public function beforeUpdate($tableHistory) { $entity_sequence = $this->_entity->getSequence(); if (count($entity_sequence) && isset($entity_sequence['dependence'])) { $dependence_field_itens = $entity_sequence['dependence']; if (!is_array($dependence_field_itens)) { $dependence_field_itens = array(0 => $dependence_field_itens); } foreach ($dependence_field_itens as $dependence_field) { $dependence_value = $this->_table->{$dependence_field}; if ($tableHistory[$dependence_field] != $dependence_value) { $seq = new SequenceModel(); $seq->changeSequence(array('tbl' => $this->getTableName(), 'id' => $this->getId(), 'sequence' => 0)); $f = new TableFilter($this->_table, array()); $f->sequence($this->_dao, $this->_entity)->filter('sequence'); } } } }
public function restore($itens) { foreach ($itens as $item) { $entity = $this->_entities->getEntity($item['name']); $entity_id = $entity->getId(); $entity_title = $entity->getTitle(); $entity_tbl = $entity->getTbl(); $entity_sequence = $entity->getSequence(); $model = $entity->getModel(); $tableHistory = $model->getById($item['id']); // if ($parent_title = $this->hasParentOnTrash($entity, $tableHistory)) { throw new Exception('Favor restaurar o ítem ' . $parent_title . ' primeiro'); } // $table = new Table($entity_tbl); $f = new TableFilter($table, array('is_del' => '0')); if (count($entity_sequence)) { if (isset($entity_sequence['dependence'])) { if (is_array($entity_sequence['dependence'])) { foreach ($entity_sequence['dependence'] as $dp) { $table->{$dp} = $tableHistory[$dp]; } } else { $table->{$entity_sequence['dependence']} = $tableHistory[$entity_sequence['dependence']]; } } $f->sequence($this->_dao, $entity)->filter('sequence'); } $f->intval()->filter('is_del'); $f->null()->filter('del_date'); $this->_dao->update($table, array($entity_id . ' = ?' => $item['id'])); $this->log('R', $tableHistory[$entity_title], $table); } }