/** * Binds the idex to an object, and updates the object * Will only bind default object properties when it's created * * @param CMbObject &$mbObject Object * @param CMbObject $mbObjectDefault Default object * * @throws Exception * * @return void */ function bindObject(&$mbObject, $mbObjectDefault = null) { $object_class = get_class($mbObject); if (!$mbObject instanceof CMbObject) { trigger_error("Impossible d'associer un identifiant Santé 400 à un objet de classe '{$object_class}'"); } $this->object_class = $object_class; $this->object_id = $mbObject->_id; $this->last_update = null; // In case already defined $this->loadMatchingObject(); $this->_ref_object = null; // Prevent optimisation errors $this->loadRefs(); // Object has not been found : never created or deleted since last binding if (!@$this->_ref_object->_id && $mbObjectDefault) { $mbObjectDefault->nullifyEmptyFields(); $mbObject->extendsWith($mbObjectDefault); } // Create/update bound object $mbObject->_id = $this->object_id; $mbObject->updatePlainFields(); $mbObject->repair(); if ($msg = $mbObject->store()) { throw new Exception($msg); } $this->object_id = $mbObject->_id; $this->last_update = CMbDT::dateTime(); // Create/update the idSante400 if ($msg = $this->store()) { throw new Exception($msg); } }