2

I have the option to create a new contract on my web project.

Creating a new contract is composed of the following documents(mind the french):

  • Coordonnées Client
  • Fiche Découverte
  • Contrat
  • Classification Client
  • Fiche suiveuse
  • Plan de mise en place
  • CCI
  • Enquête financière

    SAVE BUTTON

So I have a main create page where the user can click one of these documents, fill all the fields and return to this screen. My solution at the moment is storing a big object (which stores all documents data) on the PHP session and append to it each modification that the user makes.

For example if a user goes to the first document, writes something then returns to the main panel the data is saved on the session. When he clicks the SAVE BUTTON everything from the session is stored in a complicated database schema.

If you click save when a contract is incomplete (it lacks at least one of the documents, the big object is stored in MongoDB and recovered later.

  1. Is everything I do considered good practice?
  2. Should I not rest on the SESSION? (For now I haven't had any issues. The object size is about 5kb)
  3. Should I also use Mongo to store the intermediary data?

Ps: This is an internal project so security will never become an issue. The issue will be data consistency and quality.

Also note that custom objects are saved and restored from the session without the need of casting. As for mongo, I have to cast every component.

Samson
  • 2,801
  • 7
  • 37
  • 55

1 Answers1

1

Seems to me I'm pretty much a noob in using non-relational databases. The solution I found was quite simple:

Instead of inserting in MongoDB like below and then use a complicated cast when I select from the database, I serialized the object

BEFORE:

   //convert big object to array to store in MongoDB
    $this->mongo_db->insert('contrats', (array)$contrat); 

AFTER:

   $data=Array();
   $data['identifier']='123' //set an id so I can query by
   $data['contract']=serialize($contract);
   $this->mongo_db->insert('contrats',$data);

and the data recovery is very easy - unserialize($row->contract) returns the object I need.

This way storing temporary data in Mongo becomes easy, I just need to set an identifier to find the contract and serialize the big object.

Samson
  • 2,801
  • 7
  • 37
  • 55