protected function genCriteria(Request $request, User $user) { $criteria = $request->request->all(); if ($user->getRole()->hasAuth('BSO_VIEW_ALL_PROFIT') && array_key_exists('stores', $criteria)) { $criteria['stores'] = $criteria['stores']; } if (!$user->getRole()->hasAuth('BSO_VIEW_ALL_PROFIT')) { $criteria['stores'] = $user->getStore()->getId(); } return $criteria; }
/** * 判斷該使用者是否具有對應操作權限 * * @param Woojin\UserBundle\Entity\User $user * @param string $targetName * @return boolean */ public function hasAuth($user, $targetName) { return $user instanceof User ? $user->getRole()->hasAuth($targetName) : false; }