Пример #1
0
 public function deleteChildren(Entity $entity, $id)
 {
     $entity_id = $entity->getId();
     $children = $entity->getChildren();
     foreach ($children as $child) {
         $child_entity = $this->_entities->getEntity($child);
         $child_tbl = $child_entity->getTbl();
         $child_id = $child_entity->getId();
         $child_model = $child_entity->getModel();
         $select = new Select($child_tbl);
         $select->addField($child_id, 'id_children');
         $select->where(array($entity_id . ' = ? ' => $id));
         $result = $this->_dao->select($select);
         $arr_delete = array();
         foreach ($result as $row) {
             $arr_delete[] = array('name' => $child_tbl, 'id' => $row['id_children']);
         }
         $child_model->delete($arr_delete);
     }
 }
Пример #2
0
 public function deleteChildrens(Entity $entity, $id, $tableHistory)
 {
     $entity_id = $entity->getId();
     $entity_tbl = $entity->getTbl();
     $children = $entity->getChildren();
     // verificia se é página infinita para deletar uma filha dela caso exista
     if (array_key_exists('id_parent', $tableHistory)) {
         $model = $entity->getModel();
         $select = new Select($entity_tbl);
         $select->addField($entity_id, 'id');
         $select->where(array('id_parent = ?' => $tableHistory[$entity_id]));
         $result = $this->_dao->select($select);
         $arr_delete = array();
         foreach ($result as $row) {
             $arr_delete[] = array('name' => $entity_tbl, 'id' => $row['id']);
         }
         $this->delete($arr_delete);
     }
     //
     foreach ($children as $child) {
         $child_entity = $this->_entities->getEntity($child);
         $child_tbl = $child_entity->getTbl();
         $child_id = $child_entity->getId();
         $select = new Select($child_tbl);
         $select->addField($child_id, 'id_children');
         $select->where(array($entity_id . ' = ? ' => $id));
         $result = $this->_dao->select($select);
         $arr_delete = array();
         foreach ($result as $row) {
             $arr_delete[] = array('name' => $child_tbl, 'id' => $row['id_children']);
         }
         $this->delete($arr_delete);
     }
 }