public function testCheckTags()
 {
     $eventTags = "foo";
     $needsTags = "foo";
     $this->assertTrue(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $eventTags = "foo,bar,test1,test3";
     $needsTags = "test5,test10";
     $this->assertFalse(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $needsTags = "test1, bar";
     $this->assertTrue(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $needsTags = "";
     $this->assertFalse(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $eventTags = "landscapes, landscapes_sunset";
     $needsTags = "landscapes_autumn";
     $this->assertFalse(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $eventTags = "landscapes_autumn";
     $needsTags = "landscapes, landscapes_sunset";
     $this->assertFalse(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
     $eventTags = "landscapes,   ,  ,    landscapes_autumn";
     $needsTags = "land,  , ,  land";
     $this->assertFalse(EventgalleryHelpersTags::checkTags($eventTags, $needsTags));
 }
Example #2
0
 /**
  * just get the entries for this model.
  *
  * @param int $limitstart
  * @param int $limit
  * @param string $tags
  * @param string $sortAttribute
  * @param $usergroups array even if unused we need this for the cache call
  * @param $catid the category id to filter the events
  * @param $recursive defines if we should get the events for the subcategories too.
  * @return array
  */
 function getEntriesUnCached($limitstart = 0, $limit = 0, $tags = "", $sortAttribute = 'ordering', $usergroups, $catid, $recursive = false)
 {
     if ($this->_entries == null) {
         $query = $this->_db->getQuery(true)->select('folder.*, count(1) AS ' . $this->_db->quoteName('overallCount'))->from($this->_db->quoteName('#__eventgallery_folder') . ' AS folder')->join('', $this->_db->quoteName('#__eventgallery_file') . ' AS file ON folder.folder = file.folder and file.published=1')->where('(file.ismainimageonly IS NULL OR file.ismainimageonly=0)')->where('folder.published=1')->group('folder.id');
         if (null != $catid && (int) $catid != 0) {
             if ($recursive) {
                 $options = array();
                 $categories = JCategories::getInstance('Eventgallery', $options);
                 /**
                  * @var JCategoryNode $currentCategory
                  * @var JCategoryNode $childCategory
                  */
                 $currentCategory = $categories->get($catid);
                 $childCategories = $currentCategory->getChildren(true);
                 $conditions = array($catid);
                 foreach ($childCategories as $childCategory) {
                     array_push($conditions, $childCategory->id);
                 }
                 $query->where('catid in (' . implode(',', $conditions) . ') ');
             } else {
                 $query->where('catid=' . $this->_db->quote($catid));
             }
         }
         if ($sortAttribute == "date_asc") {
             $query->order('date ASC, ordering DESC');
         } elseif ($sortAttribute == "date_desc") {
             $query->order('date DESC, ordering DESC');
         } elseif ($sortAttribute == "name_asc") {
             $query->order('folder.folder ASC');
         } elseif ($sortAttribute == "name_desc") {
             $query->order('folder.folder DESC');
         } else {
             $query->order('ordering DESC');
         }
         $entries = $this->_getList($query);
         $newList = array();
         /**
          * @var EventgalleryLibraryManagerFolder $folderMgr
          */
         $folderMgr = EventgalleryLibraryManagerFolder::getInstance();
         foreach ($entries as $entry) {
             $entryObject = $folderMgr->getFolder($entry);
             // count check commented out because of picasa performance issues
             #if ($entryObject->getFileCount()>0) {
             array_push($newList, $entryObject);
             #}
         }
         $entries = $newList;
         if (strlen($tags) != 0) {
             // remove all non matching entries
             // handle space and comma separated lists like "foo bar" or "foo, bar"
             $finalWinners = array();
             /**
              * @var EventgalleryLibraryFolder $entry
              */
             foreach ($entries as $entry) {
                 if (EventgalleryHelpersTags::checkTags($entry->getFolderTags(), $tags)) {
                     $finalWinners[] = $entry;
                 }
             }
             $entries = $finalWinners;
         }
         /**
          * @var EventgalleryLibraryFolder $entry
          */
         // filter by user group
         foreach ($entries as $key => $entry) {
             if (!$entry->isVisible()) {
                 unset($entries[$key]);
             }
         }
         $this->_entries = $entries;
         $this->_total = count($entries);
     }
     return $this->_entries;
 }
Example #3
0
 /**
  * creates a link to an event
  */
 public static function createEventRoute($foldername, $tags, $catid, $itemid = null)
 {
     $foundViewType = NULL;
     if ($itemid == null) {
         $app = JFactory::getApplication();
         $menus = $app->getMenu('site');
         /**
          * @var JLanguage $lang
          */
         $lang = JFactory::getLanguage();
         $language = $lang->getTag();
         $component = JComponentHelper::getComponent('com_eventgallery');
         $attributes = array('component_id');
         $values = array($component->id);
         // take the current lang into account
         $attributes[] = 'language';
         $values[] = array($language, '*');
         $items = $menus->getItems($attributes, $values);
         $itemid = NULL;
         $options = array();
         $categories = JCategories::getInstance('Eventgallery', $options);
         foreach ($items as $item) {
             if (isset($item->query) && isset($item->query['view'])) {
                 $view = $item->query['view'];
                 if ($view == 'events' || $view == 'categories') {
                     // check the tags
                     $itemMatches = false;
                     if (strlen($item->params->get('tags', '')) == 0) {
                         $itemMatches = true;
                     } else {
                         if (EventgalleryHelpersTags::checkTags($item->params->get('tags'), $tags)) {
                             $itemMatches = true;
                         } else {
                             $itemMatches = false;
                         }
                     }
                     // check the category reference
                     // the categories view uses the catid as query parameter, the events view as param
                     if ($view == 'categories' && isset($item->query['catid'])) {
                         $menuItemCatid = $item->query['catid'];
                     } else {
                         $menuItemCatid = $item->params->get('catid', 0);
                     }
                     // if no category id is defined, this menu item would work
                     if (null == $catid || $menuItemCatid == 0) {
                         $itemMatches = $itemMatches && true;
                     } else {
                         /**
                          * @var JCategoryNode $category
                          */
                         // get the category and the path for the current folder
                         $category = $categories->get($catid);
                         $path = $category->getPath();
                         $categoryMatches = false;
                         // search the path for
                         foreach ($path as $pathItem) {
                             $temp = explode(':', $pathItem);
                             $currentCatId = $temp[0];
                             if ($menuItemCatid == $currentCatId) {
                                 $categoryMatches = true;
                                 break;
                             }
                         }
                         $itemMatches = $itemMatches && $categoryMatches;
                     }
                     // set the necessary parameters if the current item is valid
                     if ($itemMatches) {
                         $itemid = $item->id;
                         $foundViewType = $view;
                     }
                 }
                 if ($view == 'event' && isset($item->query['folder']) && $item->query['folder'] == $foldername) {
                     $itemid = $item->id;
                     $foundViewType = $view;
                 }
             }
             if ($itemid != NULL) {
                 break;
             }
         }
     }
     $url = 'index.php?option=com_eventgallery&view=event&folder=' . $foldername;
     // if not found, return language specific home link
     if ($itemid != NULL) {
         // if this is an event view we don't need to specific additional data.
         if ($foundViewType == 'event') {
             return 'index.php?Itemid=' . $itemid;
         }
         $url .= '&Itemid=' . $itemid;
     }
     return $url;
 }
Example #4
0
 /**
  * Batch tags a list of item.
  *
  * @param   integer  $value     The value of the new tag.
  * @param   array    $pks       An array of row IDs.
  * @param   array    $contexts  An array of item contexts.
  * @param   string   $mode      The mode: add|remove
  *
  * @return  void.
  *
  */
 protected function batchTags($value, $pks, $contexts, $mode)
 {
     // Parent exists so we proceed
     foreach ($pks as $pk) {
         if (!$this->user->authorise('core.edit', $contexts[$pk])) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         // Check that the row actually exists
         if (!$this->table->load($pk)) {
             if ($error = $this->table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Set the new tags
         $newTags = EventgalleryHelpersTags::splitTags($value);
         $tags = EventgalleryHelpersTags::splitTags($this->table->foldertags);
         foreach ($newTags as $newTag) {
             if ($mode == 'remove') {
                 if (($key = array_search($newTag, $tags)) !== false) {
                     unset($tags[$key]);
                 }
             }
             if ($mode == 'add') {
                 array_push($tags, $newTag);
                 $tags = array_unique($tags);
             }
         }
         $this->table->foldertags = implode(",", $tags);
         // Check the row.
         if (!$this->table->check()) {
             $this->setError($this->table->getError());
             return false;
         }
         // Store the row.
         if (!$this->table->store()) {
             $this->setError($this->table->getError());
             return false;
         }
     }
     // Clean the cache
     $this->cleanCache();
     return true;
 }
Example #5
0
 /**
  * returns an hashmap with foldertags tag=>displayname
  */
 public function getTags()
 {
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select('foldertags');
     $query->from('#__eventgallery_folder');
     $db->setQuery($query);
     $rawtags = $db->loadObjectList();
     $tags = array();
     foreach ($rawtags as $rawtag) {
         $tags = array_merge($tags, EventgalleryHelpersTags::splitTags($rawtag->foldertags));
     }
     $tags = array_unique($tags);
     $result = array();
     foreach ($tags as $tag) {
         $result[$tag] = $tag;
     }
     unset($result['']);
     asort($result);
     return $result;
 }