getModifiedRowData() public method

Gets low-level values of underlying Row columns that were modified
public getModifiedRowData ( ) : array
return array
 protected function updateInDatabase(Entity $entity)
 {
     $mapping = $entity->getClosureTableMapping();
     $parentField = $mapping['parent'];
     // zmenilo se parent_id ??
     $values = $entity->getModifiedRowData();
     if (!array_key_exists($parentField, $values)) {
         return parent::updateInDatabase($entity);
     } else {
         try {
             $this->connection->begin();
             $res = parent::updateInDatabase($entity);
             $tableName = $this->getTable() . '_closure';
             $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
             $idField = $this->mapper->getEntityField($this->getTable(), $primaryKey);
             // odstraneni stare struktury
             $this->connection->query('DELETE a FROM %n AS a' . ' JOIN %n AS d ON a.descendant_id = d.descendant_id' . ' LEFT JOIN %n AS x' . ' ON x.ancestor_id = d.ancestor_id AND x.descendant_id = a.ancestor_id' . ' WHERE d.ancestor_id = ? AND x.ancestor_id IS NULL', $tableName, $tableName, $tableName, $entity->{$idField});
             // vlozeni nove struktury
             if ($values[$parentField] !== NULL) {
                 $this->connection->query('INSERT INTO %n (ancestor_id, descendant_id, depth)' . ' SELECT supertree.ancestor_id, subtree.descendant_id,' . ' supertree.depth+subtree.depth+1' . ' FROM %n AS supertree JOIN %n AS subtree' . ' WHERE subtree.ancestor_id = ?' . ' AND supertree.descendant_id = ?', $tableName, $tableName, $tableName, $entity->{$idField}, $values[$parentField]);
             }
             $this->connection->commit();
             return $res;
         } catch (\Exception $e) {
             $this->connection->rollback();
             throw $e;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param Entity $entity
  * @return \DibiResult|int
  */
 protected function updateInDatabase(Entity $entity)
 {
     $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
     $idField = $this->mapper->getEntityField($this->getTable(), $primaryKey);
     $values = $entity->getModifiedRowData();
     $this->changeEmptyStringsToNull($values, $entity->getReflection()->getEntityProperties());
     return $this->connection->query('UPDATE %n SET %a WHERE %n = ?', $this->getTable(), $values, $primaryKey, $entity->{$idField});
 }
Exemplo n.º 3
0
 /**
  * @param \LeanMapper\Entity $entity
  * @return mixed|void
  */
 protected function updateInDatabase(\LeanMapper\Entity $entity)
 {
     /** @var TranslatableEntity $entity */
     $table = $this->getTable();
     $primaryKey = $this->mapper->getPrimaryKey($table);
     $idField = $this->mapper->getEntityField($table, $primaryKey);
     $values = array_diff_key($entity->getModifiedRowData(), $entity->getTranslatableColumns());
     if (!empty($values)) {
         $this->connection->query('UPDATE %n SET %a WHERE %n = ?', $this->getTable(), $values, $primaryKey, $entity->{$idField});
     }
     $this->insertTranslation($entity->{$idField}, $entity);
 }
Exemplo n.º 4
0
 /**
  * Performs database update (can be customized)
  *
  * @param Entity $entity
  * @return mixed
  */
 protected function updateInDatabase(Entity $entity)
 {
     $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
     $values = $entity->getModifiedRowData();
     return $this->connection->query('UPDATE %n SET %a WHERE %n = ?', $this->getTable(), $values, $primaryKey, $this->getIdValue($entity));
 }