Example #1
0
    public function deleteAction()
    {
        $this->setViewPathes();
        $this->disableRenderView();
        //отключение вывода
        //проверка на возможность удаления
        if (!$this->z_can_delete) {
            Z_FlashMessenger::addMessage('Удаление запрещено!');
            return;
        }
        //получение списка удаляемых элементов
        if (!$this->_getParam('id')) {
            $ids = $this->_getParam('ids');
        } else {
            $ids = array($this->_getParam('id'));
        }
        //если есть подтверждение на удаление или оно не требуется, то удаляем
        if ($this->z_delete_confirm && $this->_getParam('confirmed') || !$this->z_delete_confirm) {
            //получение списка полей, с файлами на удаление
            $modelForm = new Z_Model_Resourceforms();
            $formFileitems = $modelForm->fetchAll(array('resourceid=?' => $this->getResourceInfo()->id, 'is_file=?' => 1));
            $storage = new Z_File_Storage();
            $deletedItemsCount = 0;
            foreach ($ids as $id) {
                $item = $this->z_model->fetchRow(array('id=?' => $id));
                $itemArray = $item->toArray();
                if (!$this->deleteCheck($itemArray)) {
                    Z_FlashMessenger::addMessage('Удаление записи "' . $itemArray[$this->z_default_field] . '" Запрещено!');
                    continue;
                }
                //проверка на наличие подразделов в каталоге
                $haveSubcat = false;
                if ($this->z_datatype == 'catalog') {
                    $subCatCount = $this->z_model->select(true)->reset('columns')->columns('count(*)')->where('parentid=?', $item->id)->query()->fetchColumn();
                    if ($subCatCount > 0) {
                        $haveSubcat = true;
                        Z_FlashMessenger::addMessage('Раздел "' . $itemArray[$this->z_default_field] . '" имеет подразделы');
                    }
                }
                //проверка на наличие дочерних элементов
                $haveChild = false;
                if ($this->z_child_resources) {
                    foreach ($this->z_child_resources as $resource) {
                        $childModel = new $resource['model']();
                        $childItem = $childModel->fetchRow(array($resource['parent_field'] . '=?' => $item->id));
                        if ($childItem) {
                            $haveChild = true;
                            Z_FlashMessenger::addMessage('"' . $itemArray[$this->z_default_field] . '" имеет подчиненные "' . $resource['title'] . '"');
                        }
                    }
                }
                //проверка на возможность удаления элемента
                if ((!isset($itemArray['z_can_delete']) || isset($itemArray['z_can_delete']) && $itemArray['z_can_delete']) && (!$haveChild || $this->z_delete_on_have_child) && !$haveSubcat) {
                    //удаление связей многие ко многим
                    if (!empty($this->z_refers)) {
                        foreach ($this->z_refers as $referName => $refer) {
                            $referModel = new $refer['model']();
                            $referModel->delete(array($refer['field1'] . '=?' => $item->id));
                        }
                    }
                    $delData = $item->toArray();
                    $item->delete();
                    if (count($formFileitems)) {
                        foreach ($formFileitems as $formFileitem) {
                            $storage->removeFileDir($delData[$formFileitem->field]);
                        }
                    }
                    //ech('1');
                    $this->deleteSuccess($delData);
                    $this->deleteFromIndex($delData['id']);
                    $deletedItemsCount++;
                } else {
                    Z_FlashMessenger::addMessage('Удаление записи "' . $itemArray[$this->z_default_field] . '" Запрещено!');
                }
            }
            if ($deletedItemsCount > 0) {
                $this->ajaxGo($this->view->url(array('action' => $this->z_defaultAction, 'id' => NULL, 'confirmed' => NULL)));
            }
        } elseif ($this->z_delete_confirm) {
            //требуем подтверждения на удаление
            jQuery::evalScript('
	    		if (confirm("Удалить?"))
	    		{
	    			z_ajax_go("' . $this->view->url() . '",{confirmed:1,ids:[' . implode(',', $ids) . ']});
	    		}
	    	');
        }
    }
Example #2
0
 /**
  * Удаление файла, id которого хранится в декораторе
  * @param <type> $id
  * @return <type>
  */
 protected function _deleteStoredFile()
 {
     $storage = new Z_File_Storage();
     return $storage->removeFileDir($this->_storedFileId);
 }