/** * Update l'objet dans la DB, l'$objet est mis a jour selon les modif appliqué par la DB (insert: id...) * si l'objet n'existe pas déjà on renvoi un exception * renvoi true/false selon la réussite de la requete * @param DomainObjectInterface $object * @return mixed */ public function update(DomainObjectInterface &$object) { $aEntityList = array_filter($object->getArrayCopy()); list($condition, $bindings, $identityKey) = $this->getEntityCondition($aEntityList); if (!empty($condition) && !empty($bindings)) { $primaries = $this->getEntityPrimaries(); $entities = array_diff_key($aEntityList, array_flip($primaries)); list($update, $updateBindings) = $this->getCondition($entities, ', '); $query = 'UPDATE `' . $this->getEntityTable() . '` SET ' . $update . ' WHERE ' . $condition; if ($this->service->exec($query, array_merge($updateBindings, $bindings)) > 0) { // insert en identityMap $this->getIdentityMap()->storeObject($identityKey, $object); return true; } } return false; }
/** * charge les donnée $data dans l'objet $object * @param DomainObjectInterface $object * @param array $data */ public function populate(DomainObjectInterface &$object, array $data) { $object->populate($data); }