public function putAction() { // Getting parameters $params = $this->_helper->param(); $roleId = $params['roleId']; // Convert data collection array if not $collection = $this->_helper->array()->isCollection($params['data']) ? $params['data'] : $this->_helper->array()->convertRecordtoCollection($params['data']); // Doctrine //KBBTODO move dql to models Doctrine_Manager::connection()->beginTransaction(); try { foreach ($collection as $story) { $recordExist = is_object(Doctrine_Core::getTable('Model_Entity_Permission')->findOneBystory_idAndrole_id($story['id'], $roleId)); if ($story['allow'] && !$recordExist) { $permission = new Model_Entity_Permission(); $permission->story_id = $story['id']; $permission->role_id = $roleId; $permission->save(); } elseif (!$story['allow'] && $recordExist) { Doctrine_Query::create()->delete('Model_Entity_Permission p')->where('p.role_id = ? AND p.story_id = ?', array($roleId, $story['id']))->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); } } Doctrine_Manager::connection()->commit(); $this->_helper->response(true, 201)->getResponse(); unset($permission); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
public static function getAllRoles() { $query = Doctrine_Query::create()->select('role.id, roleTranslation.title as title, roleTranslation.description as description, role.active')->from('Model_Entity_Role role')->leftJoin('role.Translation roleTranslation')->where('roleTranslation.lang = ?', Zend_Auth::getInstance()->getIdentity()->language)->useQueryCache(Kebab_Cache_Query::isEnable()); return $query; }
public static function getUserStoriesName($roles = false) { $userRoles = $roles == false ? Zend_Auth::getInstance()->getIdentity()->roles : $roles; $query = Doctrine_Query::create()->select('s.name')->from('Model_Entity_Story s')->leftJoin('s.Permission p')->andWhere('s.active = 1')->andWhereIn('p.role_id', $userRoles)->useQueryCache(Kebab_Cache_Query::isEnable()); $retVal = array(); foreach ($query->execute()->toArray() as $story) { $retVal[] = $story['name']; } return $retVal; }
public static function getFeedbackByUserId($userId, $options) { $lang = Zend_Auth::getInstance()->getIdentity()->language; $query = Doctrine_Query::create()->select(' feedback.*, application.*, applicationTranslate.title as title')->from('Model_Entity_Feedback feedback')->innerJoin('feedback.Application application')->leftJoin('application.Translation applicationTranslate')->where('feedback.user_id = ?', $userId)->andWhere('applicationTranslate.lang = ?', $lang)->useQueryCache(Kebab_Cache_Query::isEnable()); if (array_key_exists('sort', $options)) { $query->orderBy($options['sort']); } return $query; }
public function indexAction() { // Mapping $mapping = array('id' => 'feedback.id', 'status' => 'feedback.status', 'description' => 'feedback.description', 'title' => 'applicationTranslate', 'User' => 'user'); //KBBTODO move DQL to model class $query = Doctrine_Query::create()->select(' feedback.*, application.*, user.fullName, applicationTranslate.title as title')->from('Model_Entity_Feedback feedback')->innerJoin('feedback.Application application')->leftJoin('application.Translation applicationTranslate')->innerJoin('feedback.User user')->where('applicationTranslate.lang = ?', Zend_Auth::getInstance()->getIdentity()->language)->orderBy($this->_helper->sort($mapping))->useQueryCache(Kebab_Cache_Query::isEnable()); $pager = $this->_helper->pagination($query); $feedbacks = $pager->execute(); $responseData = array(); if (is_object($feedbacks)) { $responseData = $feedbacks->toArray(); } $this->_helper->response(true, 200)->addData($responseData)->addTotal($pager->getNumResults())->getResponse(); }
/** *<p>This function return applications and their stories which are allowed in ACL.</p> * * @static * @return array */ public static function getApplicationsByPermission() { $lang = Zend_Auth::getInstance()->getIdentity()->language; $roles = Zend_Auth::getInstance()->getIdentity()->roles; $query = Doctrine_Query::create()->from('Model_Entity_Application a')->leftJoin('a.Translation at')->leftJoin('a.StoryApplication sa')->leftJoin('sa.Story s')->leftJoin('s.Permission p')->leftJoin('p.Role r')->whereIn('r.id', $roles)->andWhere('a.active = 1 AND s.active = 1')->orderBy('a.name DESC')->orderBy('a.department DESC')->useQueryCache(Kebab_Cache_Query::isEnable()); $applications = $query->execute(); $returnData = array(); foreach ($applications as $application) { $app['identity'] = $application->identity; $app['className'] = $application->className; $app['name'] = $application->name; $app['type'] = $application->type; $app['department'] = $application->department; $app['version'] = $application->version; $app['title'] = array('text' => $application->Translation[$lang]->title, 'description' => $application->Translation[$lang]->description); $returnData[] = $app; } return $returnData; }
public function putAction() { // Param $params = $this->_helper->param(); $userSessionId = Zend_Auth::getInstance()->getIdentity()->id; // Validation $fullName = $params['fullName']; $email = $params['email']; $language = $params['language']; //KBBTODO move DQL to model class Doctrine_Manager::connection()->beginTransaction(); try { $userExistsWithEmail = Doctrine_Query::create()->from('Model_Entity_User user')->where('user.email = ?', $email)->andWhere('user.id != ?', $userSessionId)->useQueryCache(Kebab_Cache_Query::isEnable())->fetchOne(); if (is_object($userExistsWithEmail)) { // Another User exists with entered email $this->_helper->response(false, 201)->set('email', 'Another User with email exists.')->getResponse(); } // DQL $profile = new Model_Entity_User(); $profile->assignIdentifier($userSessionId); $profile->fullName = $fullName; $profile->email = $email; $profile->language = $language; $profile->save(); Doctrine_Manager::connection()->commit(); // Reset Session Kebab_Authentication::signOut(); Kebab_Authentication::signIn($profile->userName, $profile->password, false, false); // Response $this->_helper->response(true, 201)->addData(array('userName' => $profile->userName, 'fullName' => $profile->fullName))->getResponse(); unset($profile); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
/** * @return void */ public function addAllPermissions() { // First of all deny everything. parent::deny(); $query = Doctrine_Query::create()->select('module.name, acontroller.name, controller.name, action.name, service.id, role.id, story.id, permission.*, story.name')->from('Model_Entity_Service service')->leftJoin('service.Resource controller')->leftJoin('controller.Module module')->leftJoin('service.Action action')->leftJoin('action.Controller acontroller')->leftJoin('service.Story story')->leftJoin('story.Permission permission')->leftJoin('permission.Role role')->useQueryCache(Kebab_Cache_Query::isEnable()); $services = $query->execute(); if (count($services->toArray()) > 0) { foreach ($services as $service) { $action = !isset($service->Action->name) ? null : $service->Action->name; $resource = isset($service->Resource) ? $service->Resource->Module->name . '_' . $service->Resource->name : null; $resource = is_null($resource) && isset($service->Action->Controller) ? $service->Action->Controller->Module->name . '_' . $service->Action->Controller->name : $resource; if (isset($service->Story)) { foreach ($service->Story->Permission->toArray() as $permission) { if (count($permission) > 0) { Zend_Registry::get('logging')->log($permission['Role']['id'] . '-' . $resource . '-' . $action, Zend_Log::DEBUG); parent::allow($permission['Role']['id'], $resource, $action); } } } } } }
public function deleteAction() { // Getting parameters $params = $this->_helper->param(); $ids = $params['data']; //KBBTODO move dql to model Doctrine_Manager::connection()->beginTransaction(); try { // Delete permission Doctrine_Query::create()->delete('Model_Entity_Permission permission')->whereIn('permission.role_id', $ids)->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); // Delete permission Doctrine_Query::create()->delete('Model_Entity_UserRole userRole')->whereIn('userRole.role_id', $ids)->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); // Delete Role Doctrine_Query::create()->delete('Model_Entity_Role role')->whereIn('role.id', $ids)->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); Doctrine_Manager::connection()->commit(); // Response $this->_helper->response(true, 201)->getResponse(); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
/** * Gets the users identity from the $blameVar index of either the $_SESSION * or $GLOBALS array; OR use the default value * * @return void */ public function getUserIdentity() { $identity = Zend_Auth::getInstance()->getIdentity(); if (PHP_SAPI === 'cli') { $ident = 0; } else { $ident = is_object($identity) ? isset($identity->agent_id) ? $identity->agent_id : $identity->id : NULL; } if (is_null($ident) && $this->_options['default'] !== false) { if (is_null($this->_default)) { /* * Try to parse the default value as a dql string, if that fails * set the default value equal to the literal value of the string */ try { $default = Doctrine_Query::create()->parseDqlQuery($this->_options['default'])->useQueryCache(Kebab_Cache_Query::isEnable())->fetchOne($this->_options['params']); $this->_default = $default[$this->_options['blameVar']]; } catch (Doctrine_Query_Tokenizer_Exception $e) { $this->_default = $this->_options['default']; } } $ident = $this->_default; } return $ident; }
public function deleteAction() { // Getting parameters $params = $this->_helper->param(); // Convert data collection array if not $ids = $this->_helper->array()->convertArray($params['data']); // Updating status Doctrine_Manager::connection()->beginTransaction(); try { Doctrine_Query::create()->delete()->from('Model_Entity_User user')->whereIn('user.id', $ids)->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); Doctrine_Manager::connection()->commit(); // Delete Record and Return REST Response $this->_helper->response(true, 204)->addNotification(Kebab_Notification::INFO, 'Record was deleted.')->getResponse(); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
/** * _authenticateCreateSelect() - This method creates a Zend_Db_Select object that * is completely configured to be queried against the database. * * @return Doctrine_Query */ protected function _authenticateCreateSelect() { // build credential expression if (empty($this->_credentialTreatment) || strpos($this->_credentialTreatment, "?") === false) { $this->_credentialTreatment = '?'; } $dbSelect = Doctrine_Query::create($this->getConnection())->from($this->_tableName)->select('*, (' . $this->_credentialColumn . ' = ' . str_replace('?', $this->getConnection()->quote($this->_credential), $this->_credentialTreatment) . ') AS zend_auth_credential_match')->addWhere($this->_identityColumn . ' = ?', $this->_identity)->useQueryCache(Kebab_Cache_Query::isEnable()); return $dbSelect; }
/** * @static * @param $userId * @param $roleId * @return bool */ public static function delete($userId, $roleId) { $retVal = false; if (self::has($userId, $roleId)) { Doctrine_Query::create()->delete('Model_Entity_UserRole userRole')->where('userRole.user_id = ? AND userRole.role_id = ?', array($userId, $roleId))->useQueryCache(Kebab_Cache_Query::isEnable())->execute(); $retVal = true; } return $retVal; }
public static function getAll($searchUser = array(), $order = "user.id") { $query = Doctrine_Query::create()->select('user.id, user.fullName, user.userName, user.email, user.language, user.status, user.active')->from('Model_Entity_User user')->whereIn('user.id', $searchUser)->orderBy("{$order}")->useQueryCache(Kebab_Cache_Query::isEnable()); return $query; }