Example #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 menu
  *
  * @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');
         $menu = Menus::findFirstByid($id);
         if (!$menu) {
             throw new Exception('Menu não encontrado!');
         }
         if (!$menu->delete()) {
             $msg = '';
             foreach ($menu->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/menus');
     }
 }
Example #3
0
 public function initialize($entity = null, $options = [])
 {
     if (is_null($entity)) {
         $entity = new Menus();
     }
     $reset = ['id' => [], 'title' => [], 'slug' => [], 'parents' => [], 'action' => []];
     $element = $reset;
     $attributes = $reset;
     $type = $options['type'];
     $hasTitle = isset($options['title']) ? $options['title'] : true;
     $formAttributes = $this->getFormAttributes($type);
     $typeForms = $entity->typeForms();
     $attributesForm = ['class' => 'col-md-8 col-md-offset-2'];
     $legend = null;
     $url = $this->di->get('url');
     $uri = $url->getBaseUri() . 'menus';
     $this->setAction($uri . '/' . $formAttributes['action']);
     $this->setAttributes(['autocomplete' => 'off', 'class' => 'form-horizontal']);
     //////////////////////////////////// attributes ////////////////////////////////////
     if ($type != 'search') {
         $attributes['id'] = ['maxlength' => 11, 'required' => 'required'];
         $attributes['title'] = ['maxlength' => 50, 'required' => 'required'];
         $attributes['slug'] = ['maxlength' => 255, 'required' => 'required'];
     }
     //////////////////////////////////// element ////////////////////////////////////
     $element['id'] = $this->_hidden('id', $attributes['id']);
     $element['title'] = $this->_text('title', $attributes['title']);
     $element['title']->setLabel('Título');
     $element['slug'] = $this->_text('slug', $attributes['slug']);
     $element['slug']->setLabel('Slug');
     $select = ['entity' => 'Nucleo\\Models\\Menus', 'selectField' => ['key' => 'id', 'value' => 'title'], 'selectEmpty' => true];
     $element['parents'] = $this->_select('parents', [], $select);
     $element['parents']->setLabel('Pai');
     $select = ['entity' => 'Nucleo\\Models\\Actions', 'selectField' => ['key' => 'id', 'value' => 'title'], 'selectEmpty' => true];
     $element['action'] = $this->_select('action', [], $select);
     $element['action']->setLabel('Ação');
     //////////////////////////////////// validator ////////////////////////////////////
     $element['id'] = $this->validatorPresenceOf($element['id']);
     $element['title'] = $this->validatorPresenceOf($element['title']);
     $element['slug'] = $this->validatorPresenceOf($element['slug']);
     if ($hasTitle) {
         $legend = $formAttributes['legend'];
     }
     $this->startFieldset($legend, $attributesForm);
     foreach ($typeForms as $field => $permission) {
         if ($field == $type) {
             foreach ($element as $keyField => $fieldForm) {
                 if ($permission[$keyField]) {
                     $element[$keyField]->clear();
                     $this->add($element[$keyField]);
                 }
             }
         }
     }
     $buttonAttribute = ['class' => $formAttributes['class'] . ' pull-right', 'type' => 'submit'];
     $element = $this->_submit($formAttributes['value'], $buttonAttribute);
     $this->add($element);
     if ($type == 'search') {
         $resetButtonAttribute = ['class' => 'bgm-gray waves-effect pull-right', 'type' => 'button', 'onclick' => 'resetting()', 'id' => 'reset'];
         $element = $this->_button('Limpar', $resetButtonAttribute);
         $this->add($element);
     }
     $this->endFieldset();
 }