Esempio n. 1
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;
 }
 public function testSplitTags()
 {
     $tagsString = "foo, bar     test1, test2";
     $tags = EventgalleryHelpersTags::splitTags($tagsString);
     $this->assertCount(4, $tags, 'Number of tags does not match');
 }
Esempio n. 3
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;
 }