public function hasCredential($credential, $useAnd = true) { if ($this->isSuperAdmin()) { return true; } if (sizeof($credential) == 0) { return true; } // Discuss with cmar //perm_type, dcenter, node, vm $p_permtype = $credential[0]; $p_user_id = $this->getId(); $p_cluster_id = $credential[1]; $p_server_id = $credential[2]; $c = new Criteria(); $c->add(EtvaPermissionUserPeer::USER_ID, $p_user_id, Criteria::EQUAL); $c->addJoin(EtvaPermissionUserPeer::ETVAPERM_ID, EtvaPermissionPeer::ID); $c->add(EtvaPermissionPeer::PERM_TYPE, $p_permtype, Criteria::EQUAL); $c->addJoin(EtvaPermissionPeer::ID, EtvaPermissionClusterPeer::ETVAPERM_ID); $c->add(EtvaPermissionClusterPeer::CLUSTER_ID, $p_cluster_id); $c->addJoin(EtvaPermissionPeer::ID, EtvaPermissionServerPeer::ETVAPERM_ID); $c->add(EtvaPermissionServerPeer::SERVER_ID, $p_server_id); $permission = EtvaPermissionUserPeer::doSelect($c); return $permission ? true : false; }
public function executeJsonGridInfo(sfWebRequest $request) { $isAjax = $request->isXmlHttpRequest(); if (!$isAjax) { return $this->redirect('@homepage'); } $this->sfGuardUser = sfGuardUserPeer::retrieveByPk($request->getParameter('id')); $user_info = $this->sfGuardUser->toArray(); // Get profile. $profile = $this->sfGuardUser->getProfile(); $profile_info = $profile->toArray(); //user groups $groups = $this->sfGuardUser->getGroups(); $group_ids = array(); foreach ($groups as $group) { $group_ids[] = $group->getId(); } //user permissions $id = $request->getParameter('id'); $c = new Criteria(); $c->add(EtvaPermissionUserPeer::USER_ID, $id, Criteria::EQUAL); //$c->addJoin(EtvaPermissionPeer::ID, EtvaPermissionUserPeer::ETVAPERM_ID); $perms = EtvaPermissionUserPeer::doSelect($c); //error_log(print_r($perms, true)); $permission_ids = array(); foreach ($perms as $p) { $permission_ids[] = $p->getEtvaPermission()->getId(); } error_log(print_r($permission_ids, true)); // $permissions = $this->sfGuardUser->getPermissions(); // $permission_ids = array(); // foreach($permissions as $permission) // $permission_ids[] = $permission->getId(); $user_service_list = array(); $etva_user_service = EtvaUserServiceQuery::create()->filterByUserId($id)->useEtvaServiceQuery("EtvaService", "INNER JOIN")->endUse()->find(); foreach ($etva_user_service as $uservice) { array_push($user_service_list, array('service_id' => $uservice->getServiceId(), 'extra' => $uservice->getExtra())); } $elements = array_merge($user_info, $profile_info, array('sf_guard_user_group_list' => $group_ids), array('sf_guard_user_permission_list' => $permission_ids), array('user_service_list' => $user_service_list)); $final = array('success' => true, 'data' => $elements); $result = json_encode($final); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }