示例#1
0
 /**
  * Get all the modules for the current user that are tagged with $tag.
  *
  * If the $limit is set, the returned array is limited to the $limit tags.
  *
  * @param string  $tag   The tag for search.
  * @param integer $limit The number of modules for return, 0 for all.
  *
  * @return array Array with results.
  */
 public function getModulesByTag($tag, $limit = 0)
 {
     $foundResults = array();
     $results = array();
     $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
     $userId = Phprojekt_Auth::getUserId();
     if (!empty($tag)) {
         // Find the tag
         $tagId = $this->_tags->getTagId($tag);
         if ($tagId > 0) {
             // Get The user-tags relations
             $tagUserIds = $this->_tagsUsers->getUserTagIds(0, $tagId);
             // Get The modules data
             foreach ($tagUserIds as $tagUserId => $tagId) {
                 $foundResults = array_merge($foundResults, $this->_tagsModules->getModulesByRelationId($tagUserId));
             }
             // Return the $limit tags
             if ($limit > 0) {
                 $foundResults = array_slice($foundResults, 0, $limit);
             }
             // Convert result to array and add the display data
             // only fetch records with read access
             $display = Phprojekt_Loader::getLibraryClass('Phprojekt_Search_Display');
             $dataForDisplay = array();
             foreach ($foundResults as $result) {
                 if ($rights->getItemRight($result['moduleId'], $result['itemId'], $userId) > 0) {
                     $dataForDisplay[$result['moduleId']][] = $result['itemId'];
                 }
             }
             $results = $display->getDisplay($dataForDisplay);
         }
     }
     return $results;
 }