當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserDao::getGroups方法代碼示例

本文整理匯總了PHP中UserDao::getGroups方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserDao::getGroups方法的具體用法?PHP UserDao::getGroups怎麽用?PHP UserDao::getGroups使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserDao的用法示例。


在下文中一共展示了UserDao::getGroups方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: policyCheck

 /**
  * Check whether the given policy is valid for the given community and user.
  *
  * @param  CommunityDao $communityDao community DAO
  * @param  null|UserDao $userDao user DAO
  * @param  int $policy policy
  * @return bool true if the given policy is valid for the given community and user
  * @throws Zend_Exception
  */
 public function policyCheck($communityDao, $userDao = null, $policy = MIDAS_POLICY_READ)
 {
     if (!$communityDao instanceof CommunityDao || !is_numeric($policy)) {
         throw new Zend_Exception('Error in param: communityDao should be a CommunityDao and policy should be numeric.');
     }
     if ($userDao == null) {
         $userId = -1;
     } elseif (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Should be an user.');
     } else {
         $userId = $userDao->getUserId();
         if ($userDao->isAdmin()) {
             return true;
         }
     }
     $privacy = $communityDao->getPrivacy();
     switch ($policy) {
         case MIDAS_POLICY_READ:
             if ($privacy != MIDAS_COMMUNITY_PRIVATE) {
                 return true;
             } elseif ($userId == -1) {
                 return false;
             } else {
                 $user_groups = $userDao->getGroups();
                 $member_group = $communityDao->getMemberGroup();
                 foreach ($user_groups as $group) {
                     if ($group->getKey() == $member_group->getKey()) {
                         return true;
                     }
                 }
                 $invitations = $userDao->getInvitations();
                 foreach ($invitations as $invitation) {
                     if ($invitation->getCommunityId() == $communityDao->getKey()) {
                         return true;
                     }
                 }
                 return false;
             }
             break;
         case MIDAS_POLICY_WRITE:
             if ($userId == -1) {
                 return false;
             } else {
                 $user_groups = $userDao->getGroups();
                 $moderator_group = $communityDao->getModeratorGroup();
                 $admin_group = $communityDao->getAdminGroup();
                 foreach ($user_groups as $group) {
                     if ($group->getKey() == $moderator_group->getKey() || $group->getKey() == $admin_group->getKey()) {
                         return true;
                     }
                 }
                 return false;
             }
             break;
         case MIDAS_POLICY_ADMIN:
             if ($userId == -1) {
                 return false;
             } else {
                 $user_groups = $userDao->getGroups();
                 $admin_group = $communityDao->getAdminGroup();
                 foreach ($user_groups as $group) {
                     if ($group->getKey() == $admin_group->getKey()) {
                         return true;
                     }
                 }
                 return false;
             }
             break;
         default:
             return false;
     }
 }
開發者ID:josephsnyder,項目名稱:Midas,代碼行數:81,代碼來源:CommunityModelBase.php

示例2: getCommunitiesFromSearch

 /**
  * Return a list of communities corresponding to the search.
  *
  * @param string $search
  * @param UserDao $userDao
  * @param int $limit
  * @param bool $group
  * @param string $order
  * @return array
  * @throws Zend_Exception
  */
 public function getCommunitiesFromSearch($search, $userDao, $limit = 14, $group = true, $order = 'view')
 {
     if (Zend_Registry::get('configDatabase')->database->adapter == 'PDO_PGSQL') {
         $group = false;
         // PostgreSQL does not like the SQL request with group by
     }
     $communities = array();
     if ($userDao == null) {
         $userId = -1;
     } elseif (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Should be an user.');
     } else {
         $userId = $userDao->getUserId();
         $userGroups = $userDao->getGroups();
         foreach ($userGroups as $userGroup) {
             $communities[] = $userGroup->getCommunityId();
         }
     }
     $sql = $this->database->select();
     if ($group) {
         $sql->from(array('c' => 'community'), array('community_id', 'name', 'count(*)'));
     } else {
         $sql->from(array('c' => 'community'));
     }
     if ($userId != -1 && $userDao->isAdmin()) {
         $sql->where('c.name LIKE ?', '%' . $search . '%');
     } elseif (!empty($communities)) {
         $sql->where('c.name LIKE ?', '%' . $search . '%');
         $sql->where('(c.privacy < ' . MIDAS_COMMUNITY_PRIVATE . ' OR ' . $this->database->getDB()->quoteInto('c.community_id IN (?)', $communities) . ')');
     } else {
         $sql->where('c.name LIKE ?', '%' . $search . '%');
         $sql->where('(c.privacy < ' . MIDAS_COMMUNITY_PRIVATE . ')');
     }
     $sql->limit($limit);
     if ($group) {
         $sql->group('c.name');
     }
     switch ($order) {
         case 'name':
             $sql->order(array('c.name ASC'));
             break;
         case 'date':
             $sql->order(array('c.creation ASC'));
             break;
         case 'view':
         default:
             $sql->order(array('c.view DESC'));
             break;
     }
     $rowset = $this->database->fetchAll($sql);
     $return = array();
     foreach ($rowset as $row) {
         $tmpDao = $this->initDao('Community', $row);
         if (isset($row['count(*)'])) {
             $tmpDao->count = $row['count(*)'];
         }
         $return[] = $tmpDao;
         unset($tmpDao);
     }
     return $return;
 }
開發者ID:josephsnyder,項目名稱:Midas,代碼行數:72,代碼來源:CommunityModel.php


注:本文中的UserDao::getGroups方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。