Beispiel #1
0
 /**
  *
  * @param type $id
  * @param type $docs
  * @return ObjectPhalcon
  */
 private function getMenu($id = null, $docs = false)
 {
     $return = [];
     $desc = '';
     if (!$docs) {
         $desc = 'DESC';
     }
     $param['order'] = "department {$desc}, category {$desc}";
     $baseUri = $this->url->getBaseUri();
     if (is_numeric($id)) {
         if ($id == 0) {
             $param['conditions'] = 'department IS NULL ';
         } else {
             $param['conditions'] = 'department = ' . (int) $id;
         }
     }
     if ($docs) {
         $catDocs = CategoriesDocuments::find($param);
         foreach ($catDocs as $catDoc) {
             $department = $catDoc->departments->id;
             $titleDepartment = $catDoc->departments->title;
             $ccDepartment = $catDoc->departments->cc;
             $iconDepartment = $catDoc->departments->icon;
             $category = $catDoc->categories->id;
             $titleCategory = $catDoc->categories->title;
             $descriptionCategory = $catDoc->categories->description;
             $iconCategory = $catDoc->categories->icon;
             $return[$department]['title'] = $titleDepartment;
             $return[$department]['cc'] = $ccDepartment;
             $return[$department]['icon'] = $iconDepartment;
             $return[$department]['category'][$category]['title'] = $titleCategory;
             $return[$department]['category'][$category]['description'] = $descriptionCategory;
             $return[$department]['category'][$category]['icon'] = $iconCategory;
             $return[$department]['category'][$category]['document'][$catDoc->id]['description'] = $catDoc->description;
         }
     }
     $param['order'] = "department {$desc}, title, category {$desc}";
     $menus = Menus::find($param);
     $currentModule = $this->dispatcher->getModuleName();
     $currentController = $this->dispatcher->getControllerName();
     $currentAction = $this->dispatcher->getActionName();
     $currentDepartment = '';
     $currentCategory = '';
     $baseUri = $this->url->getBaseUri();
     foreach ($menus as $menu) {
         $modules = $menu->modules->slug;
         $controllers = $menu->controllers->slug;
         $actions = $menu->actions->slug;
         if ($this->access->isAllowed('private', $modules, $controllers, $actions) or $this->access->isAllowed('public', $modules, $controllers, $actions)) {
             if (is_null($menu->department)) {
                 $department = 0;
                 $titleDepartment = '';
                 $ccDepartment = '';
                 $iconDepartment = '';
             } else {
                 $department = $menu->departments->id;
                 $titleDepartment = $menu->departments->title;
                 $ccDepartment = $menu->departments->cc;
                 $iconDepartment = $menu->departments->icon;
             }
             if (is_null($menu->category)) {
                 $category = 0;
                 $titleCategory = 0;
                 $descriptionCategory = '';
                 $iconCategory = '';
             } else {
                 $category = $menu->categories->id;
                 $titleCategory = $menu->categories->title;
                 $descriptionCategory = $menu->categories->description;
                 $iconCategory = $menu->categories->icon;
             }
             if ($currentModule == $modules && $currentController == $controllers && $currentAction == $actions) {
                 $return[$department]['active'] = 'active toggled';
                 $return[$department]['category'][$category]['active'] = 'active toggled';
                 $return[$department]['category'][$category]['menus'][$menu->id]['active'] = 'active';
                 $currentDepartment = $department;
                 $currentCategory = $category;
             }
             if ($currentDepartment != $department) {
                 $return[$department]['active'] = '';
             }
             if ($currentCategory != $category) {
                 $return[$department]['category'][$category]['active'] = '';
             }
             if ($currentAction != $actions) {
                 $return[$department]['category'][$category]['menus'][$menu->id]['active'] = '';
             }
             $return[$department]['title'] = $titleDepartment;
             $return[$department]['cc'] = $ccDepartment;
             $return[$department]['icon'] = $iconDepartment;
             $return[$department]['category'][$category]['title'] = $titleCategory;
             $return[$department]['category'][$category]['description'] = $descriptionCategory;
             $return[$department]['category'][$category]['icon'] = $iconCategory;
             $return[$department]['category'][$category]['menus'][$menu->id]['title'] = $menu->title;
             $return[$department]['category'][$category]['menus'][$menu->id]['slug'] = $baseUri . $menu->slug;
             $return[$department]['category'][$category]['menus'][$menu->id]['icon'] = $menu->icon;
         }
     }
     ksort($return);
     return new ObjectPhalcon($return);
 }
 /**
  * Deletes a controller
  *
  * @param string $id
  */
 public function deleteAction()
 {
     try {
         if (!$this->request->isPost()) {
             throw new Exception('Acesso não permitido a essa action.');
         }
         if ($this->request->isAjax()) {
             $this->view->disable();
         }
         $id = $this->request->getPost('id');
         $categoryDocument = CategoriesDocuments::findFirstByid($id);
         if (!$categoryDocument) {
             throw new Exception('Documentos de Categorias não encontrado!');
         }
         if (!$categoryDocument->delete()) {
             $msg = '';
             foreach ($categoryDocument->getMessages() as $message) {
                 $msg .= $message . '<br />';
             }
             throw new Exception($msg);
         }
         echo 'ok';
     } catch (Exception $exc) {
         $this->flash->error($exc->getMessage());
         return $this->response->redirect('nucleo/categories_documents');
     }
 }