Ejemplo n.º 1
0
 /**
  * @param int|array $ids
  * @return bool
  */
 public static function updateModuleMenu($ids = null)
 {
     if ($ids != null) {
         if (is_array($ids)) {
             ZArrayHelper::toInteger($ids);
         } else {
             $id = intval($ids);
             $ids = [];
             $ids[] = $id;
         }
     }
     $menus = CoreModules::find(['conditions' => 'menu != "" AND location = "backend" AND published = 1 AND base_name NOT IN("admin","system","template")', 'order' => 'ordering ASC'])->toArray();
     if (!count($menus)) {
         $menus = [];
     }
     $menuAdmin = CoreModules::findFirst("base_name = 'admin'");
     $menuTemplate = CoreModules::findFirst("base_name = 'template'");
     $menuSystem = CoreModules::findFirst("base_name = 'system'");
     if ($menuTemplate) {
         array_unshift($menus, $menuAdmin->toArray());
     }
     if ($menuTemplate) {
         $menus[] = $menuTemplate->toArray();
     }
     if ($menuSystem) {
         $menus[] = $menuSystem->toArray();
     }
     $menusAll = [];
     foreach ($menus as $index => $menu) {
         $menusAll[] = unserialize($menu['menu']);
     }
     $newMenuAll = [];
     foreach ($menusAll as $menu) {
         if (isset($menu['link'])) {
             $menu['link'] = self::checkUrl($menu['link']);
             $tmp = $menu;
             $tmp['items'] = [];
             if (isset($menu['items']) && count($menu['items'])) {
                 foreach ($menu['items'] as $index1 => $item) {
                     if (isset($item['link'])) {
                         $item['link'] = self::checkUrl($item['link']);
                         $tmp['items'][$index1] = $item;
                         if (isset($item['items']) && count($item['items'])) {
                             foreach ($item['items'] as $index2 => $childItem) {
                                 $childItem['link'] = self::checkUrl($childItem['link']);
                                 $tmp['items'][$index1]['items'][$index2] = $childItem;
                             }
                         }
                     }
                 }
             }
             $newMenuAll[] = $tmp;
         }
     }
     $menusAll = $newMenuAll;
     if (count($ids)) {
         /**
          * @var UserRoles[] $roles
          */
         $roles = UserRoles::find('id IN (' . implode(',', $ids) . ')');
     } else {
         $roles = UserRoles::find();
     }
     $menuForRole = [];
     foreach ($roles as $role) {
         if ($role->role_id != 1) {
             $rules = UserRoles::getRules($role->role_id);
             if (count($rules)) {
                 $menuTMPArray = [];
                 foreach ($menusAll as $menu) {
                     if ($menu['rule'] == "" || self::checkRuleMenuInRole($menu['rule'], $rules)) {
                         $menuTMP = ['menu_name' => $menu['menu_name'], 'module' => $menu['module'], 'link' => $menu['link'], 'rule' => $menu['rule'], 'link_class' => $menu['link_class'], 'icon_class' => $menu['icon_class'], 'link_target' => $menu['link_target']];
                         $menuTMP['items'] = [];
                         if (isset($menu['items']) && count($menu['items'])) {
                             foreach ($menu['items'] as $index1 => $item) {
                                 if ($item['rule'] == "" || self::checkRuleMenuInRole($item['rule'], $rules)) {
                                     $childItem = [];
                                     if (isset($item['items'])) {
                                         $childItem = $item['items'];
                                     }
                                     $item['items'] = [];
                                     $menuTMP['items'][$index1] = $item;
                                     if (count($childItem)) {
                                         foreach ($childItem as $cItem) {
                                             if ($cItem['rule'] == "" || self::checkRuleMenuInRole($cItem['rule'], $rules)) {
                                                 $menuTMP['items'][$index1]['items'][] = $cItem;
                                             }
                                         }
                                     }
                                     if (!count($menuTMP['items'][$index1]['items']) && ($menuTMP['items'][$index1]['link'] == "" || $menuTMP['items'][$index1]['link'] == "#") && $menuTMP['items'][$index1]["role"] == "") {
                                         unset($menuTMP['items'][$index1]);
                                     }
                                 }
                             }
                         }
                         if (!count($menuTMP['items']) && ($menuTMP['link'] == "" || $menuTMP['link'] == "#") && $menuTMP["rule"] == "") {
                         } else {
                             $menuTMPArray[] = $menuTMP;
                         }
                     }
                 }
                 $menuForRole[$role->role_id] = $menuTMPArray;
             } else {
                 $menuForRole[$role->role_id] = null;
             }
         } else {
             $menuForRole[$role->role_id] = $menusAll;
         }
     }
     foreach ($roles as $role) {
         $role->menu = serialize($menuForRole[$role->role_id]);
         if (!$role->save()) {
             //Do something
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Delete multiple menu type and menu item of this menu type
  *
  * @param int $id
  * @return \Phalcon\Http\ResponseInterface
  */
 public function deleteAction($id = NULL)
 {
     if ($this->request->isPost()) {
         if ($id == null) {
             $ids = $this->request->getPost('ids');
         } else {
             $ids = [$id];
         }
         ZArrayHelper::toInteger($ids);
         foreach ($ids as $id) {
             /**
              * @var MenuTypes $menu_type
              */
             $menu_type = MenuTypes::findFirst($id);
             /**
              * @var MenuDetails[] $menu_details
              */
             $menu_details = MenuDetails::find(['menu_type_id = ?0', 'bind' => [$id]]);
             foreach ($menu_details as $detail) {
                 $detail->delete();
             }
             if ($menu_type->delete()) {
                 $this->flashSession->success($menu_type->name . ' deleted successful');
             } else {
                 $this->flashSession->error($menu_type->name . ' deleted fail');
             }
         }
     }
     return $this->response->redirect('/admin/menu/');
 }
Ejemplo n.º 3
0
 /**
  * Delete user
  *
  * @param null $id
  */
 public function deleteAction($id = null)
 {
     //return false;
     if ($this->_model && $this->_modelBaseName) {
         if ($id) {
             $id = intval($id);
             $ids[] = $id;
         } else {
             $ids = $this->request->getPost('ids');
             ZArrayHelper::toInteger($ids);
         }
         if (is_array($ids)) {
             $query = "DELETE FROM {$this->_modelBaseName} WHERE id IN (" . implode(',', $ids) . ") AND is_supper_admin <> 1";
             $this->db->execute($query);
             if ($this->db->affectedRows() > 0) {
                 $this->flashSession->success(__('m_' . $this->_module . '_' . $this->_controller . '_message_items_successfully_delete', ["1" => $this->db->affectedRows()]));
             }
         }
     } else {
         $this->flashSession->error('gb_message_you_are_must_set_model_in_child_controller');
     }
     $this->response->redirect('/admin/' . $this->_module . '/' . $this->_controller . '/');
 }
Ejemplo n.º 4
0
 /**
  * Delete slide show item(s)
  *
  * @param int|null $slideShowID
  * @param string $redirect
  * @return \Phalcon\Http\ResponseInterface|void
  */
 public function deleteAction($slideShowID, $redirect = null)
 {
     $slideShowID = intval($slideShowID);
     /**
      * @var SlideShows $slideShow
      */
     $slideShow = SlideShows::findFirst(['conditions' => 'slide_show_id = ?0', 'bind' => [$slideShowID]]);
     if (!$slideShow) {
         return $this->response->redirect('/admin/slide/');
     }
     $ids = $this->request->getPost('ids');
     ZArrayHelper::toInteger($ids);
     foreach ($ids as $id) {
         $this->deleteSlideShowItem($id);
     }
     $this->flashSession->success('Delete slide show item(s) successfully!');
     if ($redirect) {
         return $redirect;
     }
     return $this->response->redirect('/admin/slide/manage-slide/slide/' . $slideShowID);
 }
Ejemplo n.º 5
0
 /**
  * Unpublished item action
  *
  * @param int $id
  * @param string $redirect
  * @param bool $log
  */
 public function unPublishAction($id = null, $redirect = null, $log = true)
 {
     if ($this->_model && $this->_modelBaseName) {
         $extraQuery = null;
         if ($log) {
             $extraQuery = ', updated_by = ' . $this->_user['id'] . ", updated_at = '" . date("Y-m-d H:i:s") . "'";
         }
         if ($id) {
             $id = intval($id);
             $ids[] = $id;
         } else {
             $ids = $this->request->getPost('ids');
             ZArrayHelper::toInteger($ids);
         }
         if (is_array($ids)) {
             $query = "UPDATE {$this->_modelBaseName} SET published = 0 " . $extraQuery . " WHERE {$this->_modelPrimaryKey} IN (" . implode(',', $ids) . ")";
             $this->db->execute($query);
             $this->flashSession->success(__($this->_getPrefixMessage() . 'message_items_successfully_unpublished', ["1" => $this->db->affectedRows()]));
         }
     } else {
         $this->flashSession->error('gb_message_you_are_must_set_model_in_child_controller');
     }
     if ($redirect) {
         $this->response->redirect($redirect);
     } else {
         $this->response->redirect('/admin/' . $this->_module . '/' . $this->_controller . '/');
     }
 }
Ejemplo n.º 6
0
 /**
  * Delete item action
  *
  * @param int $id
  * @param string $redirect
  */
 public function deleteAction($id = null, $redirect = null)
 {
     if (class_exists($this->_model) && $this->_modelBaseName) {
         $ids = [];
         if ($id) {
             $id = intval($id);
             $ids[] = $id;
         } else {
             $ids = $this->request->getPost('ids');
             ZArrayHelper::toInteger($ids);
         }
         if (is_array($ids)) {
             $idsSrt = implode(',', $ids);
             $query = "DELETE FROM {$this->_modelBaseName} WHERE is_core = 0 AND module_id IN (" . $idsSrt . ")";
             $this->db->execute($query);
             $this->flashSession->success(__('m_' . $this->_module . '_' . $this->_controller . '_message_items_successfully_delete', ['1' => $this->db->affectedRows()]));
             //Check module is core module
             $isCoreModule = CoreModules::find('is_core = 1 AND module_id IN (' . $idsSrt . ')')->toArray();
             if (count($isCoreModule)) {
                 $isCoreModuleName = array_map("__", array_column($isCoreModule, 'name'));
                 $this->flashSession->error(__('m_' . $this->_module . '_' . $this->_controller . '_can_not_delete_module_core', ["1" => implode(', ', $isCoreModuleName)]));
             }
         }
     } else {
         $this->flashSession->error('gb_message_you_are_must_set_model_in_child_controller');
     }
     if ($redirect) {
         $this->response->redirect($redirect);
     } else {
         $this->response->redirect('/admin/' . $this->_module . '/' . $this->_controller . '/');
     }
 }
Ejemplo n.º 7
0
 /**
  * Delete role
  *
  * @return \Phalcon\Http\ResponseInterface
  */
 public function deleteAction()
 {
     if ($this->request->isPost()) {
         $ids = $this->request->getPost('ids', 'int', 'null');
         if (is_array($ids)) {
             ZArrayHelper::toInteger($ids);
             foreach ($ids as $id) {
                 /**
                  * @var UserRoles $userRole
                  */
                 $userRole = UserRoles::findFirst('role_id = ' . $id . ' AND is_super_admin != 1');
                 if ($userRole) {
                     //Check Admin role is being used
                     $user = Users::findFirst(['conditions' => 'role_id = :id:', 'bind' => ['id' => $id]]);
                     if (!$user) {
                         //Begin transaction
                         $this->db->begin();
                         $userRoleMapping = UserRoleMapping::find('role_id = ' . $id);
                         if (method_exists($userRoleMapping, 'delete') && $userRoleMapping->delete() == false) {
                             $this->db->rollback();
                             $this->flashSession->error('m_system_role_message_cannot_delete_role_mapping');
                             return $this->response->redirect('/admin/system/role/');
                         }
                         if ($userRole->delete() == false) {
                             $this->db->rollback();
                             $this->flashSession->error('m_system_role_message_cannot_delete_role');
                             return $this->response->redirect('/admin/system/role/');
                         }
                         //After all successfully, commit transaction
                         $this->db->commit();
                         $this->flashSession->success(__('m_system_role_message_delete_role_successfully', ["1" => $userRole->name]));
                     } else {
                         $this->flashSession->error('m_system_role_message_role_is_being_used_on_some_user');
                     }
                 } else {
                     $this->flashSession->error('m_system_role_message_super_administrator_cannot_delete');
                 }
             }
         }
     }
     return $this->response->redirect('/admin/system/role/');
 }
Ejemplo n.º 8
0
 /**
  * Set default language
  *
  * @param $id
  */
 public function setDefaultLanguageAction($id = null)
 {
     if ($id) {
         $id = intval($id);
     } else {
         $ids = $this->request->getPost('ids');
         ZArrayHelper::toInteger($ids);
         $id = array_shift($ids);
     }
     /**
      * @var CoreLanguages $item
      */
     $item = CoreLanguages::findFirst($id);
     if ($id > 0 && $item) {
         $this->modelsManager->createQuery('UPDATE ' . $this->_model . ' SET is_default = 0')->execute();
         $item->is_default = 1;
         $item->published = 1;
         if ($item->save()) {
             $this->flashSession->success(__('m_system_language_set_default_language_successfully', ['1' => $item->title]));
         } else {
             $this->flashSession->error(__('m_system_language_set_default_language_error'));
         }
     } else {
         $this->flashSession->error(__('m_system_language_set_default_language_error'));
     }
     $this->response->redirect('/admin/system/language/');
 }