1<?php 2/* 3 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures 4 * all the essential functionalities required for any enterprise. 5 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com 6 * 7 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of 8 * the GNU General Public License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * See the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along with this program; 16 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA 18 */ 19 20/** 21 * Menu Dao 22 */ 23class MenuDao { 24 25 public function getMenuItemList($userRoleList) { 26 27 try { 28 29 if (count($userRoleList) == 0) { 30 return new Doctrine_Collection('MenuItem'); 31 } 32 33 $roleNames = array(); 34 35 foreach($userRoleList as $role) { 36 37 if ($role instanceof UserRole) { 38 $roleNames[] = $role->getName(); 39 } else if (is_string($role)) { 40 $roleNames[] = $role; 41 } 42 43 } 44 45 $query = Doctrine_Query::create() 46 ->from('MenuItem mi') 47 ->leftJoin('mi.Screen sc') 48 ->leftJoin('sc.Module mo') 49 ->leftJoin('sc.ScreenPermission sp') 50 ->leftJoin('sp.UserRole ur') 51 ->andWhere('mo.status = ?', Module::ENABLED) 52 ->andWhere('mi.status = ?', MenuItem::STATUS_ENABLED) 53 ->andWhere('sp.can_read = 1') 54 ->whereIn('ur.name', $roleNames) 55 ->orWhere('mi.screenId IS NULL') 56 ->orderBy('mi.orderHint ASC, mi.id ASC'); 57 58 return $query->execute(); 59 60 // @codeCoverageIgnoreStart 61 } catch (Exception $e) { 62 throw new DaoException($e->getMessage(), $e->getCode(), $e); 63 } 64 // @codeCoverageIgnoreEnd 65 66 } 67 68 public function enableModuleMenuItems($moduleName, $menuTitles = array()) { 69 70 try { 71 72 $query = Doctrine_Query::create() 73 ->from('MenuItem mi') 74 ->leftJoin('mi.Screen sc') 75 ->leftJoin('sc.Module mo') 76 ->andWhere('mo.name = ?', $moduleName) 77 ->andWhere('mi.status = ?', MenuItem::STATUS_DISABLED); 78 if (!empty($menuTitles)) { 79 $query->andWhereIn('mi.menu_title', $menuTitles); 80 } 81 $menuItemList = $query->execute(); 82 $i = 0; 83 84 foreach ($menuItemList as $menuItem) { 85 86 $menuItem->setStatus(MenuItem::STATUS_ENABLED); 87 $menuItem->save(); 88 $i++; 89 90 } 91 92 return $i; 93 94 // @codeCoverageIgnoreStart 95 } catch (Exception $e) { 96 throw new DaoException($e->getMessage(), $e->getCode(), $e); 97 } 98 // @codeCoverageIgnoreEnd 99 100 101 102 103 } 104 105}