Ejemplo n.º 1
0
 /**
  * Adds multiple tags on the given taggable resource
  *
  * @param Tag[]    $tags     Array of Tag objects
  * @param Taggable $resource Taggable resource
  */
 public function addTags($tags, Taggable $resource)
 {
     foreach ($tags as $tag) {
         if ($tag instanceof Tag) {
             $resource->getTags()->add($tag);
         }
     }
 }
 /**
  * Gets the object ids.
  */
 protected function readObjectIDArray()
 {
     $sql = "SELECT\t\tcontest.contestID, contest.attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_tag_to_object tag_to_object,\n\t\t\t\t\twcf" . WCF_N . "_contest contest\n\t\t\tWHERE\t\ttag_to_object.tagID = " . intval($this->tagID) . "\n\t\t\t\t\tAND tag_to_object.taggableID = " . $this->taggable->getTaggableID() . "\n\t\t\t\t\tAND contest.contestID = tag_to_object.objectID\n\t\t\t\t\t" . (!empty($this->sqlConditions) ? "AND " . $this->sqlConditions : '') . "\n\t\t\t\t\tAND (" . Contest::getStateConditions() . ")\n\t\t\t" . (!empty($this->sqlOrderBy) ? "ORDER BY " . $this->sqlOrderBy : '');
     $result = WCF::getDB()->sendQuery($sql, $this->sqlLimit, $this->sqlOffset);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $this->objectIDArray[] = $row['contestID'];
         if ($row['attachments']) {
             $this->attachmentEntryIDArray[] = $row['contestID'];
         }
     }
 }
Ejemplo n.º 3
0
    public function findRelatedItems(Taggable $item, $class, $locale, $nbOfItems = 1)
    {
        $instance = new $class();
        if (!$instance instanceof Taggable) {
            return NULL;
        }
        $em = $this->em;
        $rsm = new ResultSetMappingBuilder($em);
        $rsm->addRootEntityFromClassMetadata($class, 'i');
        $meta = $em->getClassMetadata($class);
        $tableName = $meta->getTableName();
        $escapedClass = str_replace('\\', '\\\\', $class);
        $query = <<<EOD
            SELECT i.*, COUNT(i.id) as number
            FROM {$tableName} i
            LEFT JOIN kuma_taggings t
            ON t.resource_id = i.id
            AND t.resource_type = '{$instance->getTaggableType()}'
            WHERE t.tag_id IN (
                SELECT tg.tag_id
                FROM kuma_taggings tg
                WHERE tg.resource_id = {$item->getId()}
                AND tg.resource_type = '{$item->getTaggableType()}'
            )
            AND i.id <> {$item->getId()}
EOD;
        if ($item instanceof AbstractPage) {
            $query .= <<<EOD
                AND i.id IN (
                    SELECT nodeversion.refId
                    FROM kuma_nodes as node
                    INNER JOIN kuma_node_translations as nodetranslation
                    ON node.id = nodetranslation.node
                    AND nodetranslation.lang = '{$locale}'
                    INNER JOIN kuma_node_versions as nodeversion
                    ON nodetranslation.publicNodeVersion = nodeversion.id
                    AND nodeversion.refEntityname = '{$escapedClass}'
                    AND node.deleted = 0
                    AND nodetranslation.online = 1
                )
EOD;
        }
        $query .= <<<EOD
            GROUP BY
                i.id
            HAVING
                number > 0
            ORDER BY
                number DESC
            LIMIT {$nbOfItems};
EOD;
        $items = $em->createNativeQuery($query, $rsm)->getResult();
        return $items;
    }
 /**
  * @see DatabaseObjectList::readObjects()
  */
 protected function readThreadIDs()
 {
     $sql = "SELECT\t" . $this->sqlSelectRating . "\n\t\t\t\tthread.threadID\n\t\t\tFROM\twcf" . WCF_N . "_tag_to_object tag_to_object,\n\t\t\t\twbb" . WBB_N . "_thread thread\n\t\t\t WHERE\ttag_to_object.tagID = " . $this->tagID . "\n\t\t\t\tAND tag_to_object.taggableID = " . $this->taggable->getTaggableID() . "\n\t\t\t\tAND thread.threadID = tag_to_object.objectID\n\t\t\t\t" . (!empty($this->sqlConditions) ? "AND " . $this->sqlConditions : '') . "\n\t\t\t\t" . (!empty($this->sqlOrderBy) ? "ORDER BY " . $this->sqlOrderBy : '');
     $result = WCF::getDB()->sendQuery($sql, $this->limit, $this->offset);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!empty($this->threadIDs)) {
             $this->threadIDs .= ',';
         }
         $this->threadIDs .= $row['threadID'];
     }
 }
Ejemplo n.º 5
0
 /**
  * Tags saving logic, runned after the object himself has been saved
  *
  * @param      Doctrine_Event  $event
  */
 public function postSave(Doctrine_Event $event)
 {
     $object = $event->getInvoker();
     $added_tags = Taggable::get_tags($object);
     $removed_tags = array_keys(Taggable::get_removed_tags($object));
     sfContext::getInstance()->getLogger()->notice(print_r($added_tags, true) . print_r($removed_tags, true));
     // save new tags
     foreach ($added_tags as $tagname) {
         $tag = PluginTagTable::findOrCreateByTagName($tagname);
         $tag->save();
         $tagging = new Tagging();
         $tagging->tag_id = $tag->id;
         $tagging->taggable_id = $object->id;
         $tagging->taggable_model = get_class($object);
         $tagging->save();
     }
     if ($removed_tags) {
         $q = Doctrine_Query::create()->select('t.id')->from('Tag t INDEXBY t.id')->whereIn('t.name', $removed_tags);
         $removed_tag_ids = array_keys($q->execute(array(), Doctrine::HYDRATE_ARRAY));
         Doctrine::getTable('Tagging')->createQuery()->delete()->whereIn('tag_id', $removed_tag_ids)->addWhere('taggable_id = ?', $object->id)->addWhere('taggable_model = ?', get_class($object))->execute();
     }
     $tags = array_merge(Taggable::get_tags($object), $object->getSavedTags());
     Taggable::set_saved_tags($object, $tags);
     Taggable::clear_tags($object);
     Taggable::clear_removed_tags($object);
 }
 /**
  * @see Page::assignVariables()
  */
 public function assignVariables()
 {
     parent::assignVariables();
     // display branding
     require_once WCF_DIR . 'lib/util/ContestUtil.class.php';
     ContestUtil::assignVariablesBranding();
     $this->sidebar->assignVariables();
     WCF::getTPL()->assign(array('entries' => $this->entryList->getObjects(), 'description' => $this->description, 'classes' => $this->entryList->getClasses(), 'todos' => $this->todoList ? $this->todoList->getObjects() : array(), 'tags' => $this->entryList->getTags(), 'availableTags' => $this->tags, 'tagID' => $this->tagID, 'juryID' => $this->juryID, 'participantID' => $this->participantID, 'classID' => $this->classID, 'tag' => $this->tag, 'taggableID' => $this->taggable !== null ? $this->taggable->getTaggableID() : 0, 'allowSpidersToIndexThisPage' => true));
 }
Ejemplo n.º 7
0
 public function tag()
 {
     $this->TagStr = $tag = Director::urlParam('ID');
     // page limits
     $paginator = new AbcPaginator(Taggable::$default_num_page_items);
     $dataSet = Taggable::getTaggedWith($tag, null, $paginator->start, $paginator->limit);
     $this->TagSet = $dataSet;
     // Supply template with pagination data
     $this->Paginator = $paginator->dataForTemplate($dataSet->unlimitedRowCount, 2);
     return array();
 }
 /**
  * @see Page::readData();
  */
 public function readData()
 {
     parent::readData();
     if ($this->tagObj) {
         // get tagged objects
         if ($this->taggableID == 0) {
             // get objects for overview
             $this->taggedObjects = TagEngine::getInstance()->getGroupedTaggedObjectsByTagID($this->tagObj->getID());
         } else {
             $this->taggedObjects = $this->taggable->getObjectsByTagID($this->tagObj->getID(), $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage);
         }
     }
     // get tags
     $tagCloud = new TagCloud(WCF::getSession()->getVisibleLanguageIDArray());
     $this->tags = $tagCloud->getTags($this->tagObj !== null ? 50 : 500);
 }
Ejemplo n.º 9
0
 public function searchTags()
 {
     $str = Input::get('q');
     $id = Input::get('id');
     if ($str != "") {
         $items = Tag::where('text', 'LIKE', '%' . $str . '%')->get();
         $total_count = $items->count();
         if ($total_count !== 0) {
             return response()->json(['items' => $items, 'total_count' => $total_count]);
         }
     } elseif ($id > 0) {
         $items = Taggable::where('taggable_id', $id)->get();
         $return_arr = array();
         $row_array = array();
         foreach ($items as $item) {
             $tag = Tag::where('id', $item->tag_id)->first();
             $row_array['id'] = $tag['id'];
             $row_array['text'] = $tag['text'];
             array_push($return_arr, $row_array);
         }
         echo json_encode($return_arr);
     }
 }
Ejemplo n.º 10
0
	public function tagsuggest($search)
	{
		$this->suggestions = Taggable::suggestTags($search);
		$this->render('suggestions');
	}
Ejemplo n.º 11
0
 /**
  * @param Taggable $model
  * @param $field
  *
  * @return mixed
  */
 public static function makeTagArray($model, $field)
 {
     return $model->tags()->lists($field, 'tag_id');
 }
<?php

// Define path constant
$path = str_replace('\\', '/', __DIR__);
$path_fragments = explode('/', $path);
$dir_name = $path_fragments[count($path_fragments) - 1];
define('TAGGABLE_PATH', $dir_name . '/src/taggable');
Taggable::$default_num_page_items = 10;
Ejemplo n.º 13
0
	public function run($widgetParams, $orient, $request)
	{
		$this->tagcloud = Taggable::cloud(15);
		return $this->render('widgets/tagcloud');
	}
Ejemplo n.º 14
0
 public static function getTagPageLink()
 {
     if (!self::$tags_page_link) {
         if (!($tagsPage = DataObject::get_one('TagPage'))) {
             return false;
         }
         self::$tags_page_link = $tagsPage->Link();
     }
     return self::$tags_page_link;
 }
Ejemplo n.º 15
0
$object_2_1 = _create_object_2();
$object_2_1->addTag('tag1,tag3,tag7');
$object_2_1->save();
$object_2_2 = _create_object_2();
$object_2_2->addTag('tag2,tag7');
$object_2_2->save();
$tagged_with_tag4 = Doctrine_Core::getTable('Tag')->getObjectTaggedWith('tag4');
$t->ok(count($tagged_with_tag4) == 2, 'getObjectTaggedWith() returns objects tagged with one specific tag.');
$tagged_with_tag7 = Doctrine_Core::getTable('Tag')->getObjectTaggedWith('tag7');
$t->ok(count($tagged_with_tag7) == 5, 'getObjectTaggedWith() can return several object types.');
$tagged_with_tag17 = Doctrine_Core::getTable('Tag')->getObjectTaggedWith(array('tag1', 'tag7'));
$t->ok(count($tagged_with_tag17) == 3, 'getObjectTaggedWith() returns objects tagged with several specific tags.');
$tagged_with_tag127 = Doctrine_Core::getTable('Tag')->getObjectTaggedWith('tag1, tag2, tag7', array('nb_common_tags' => 2));
$t->ok(count($tagged_with_tag127) == 6, 'the "nb_common_tags" option of getObjectTaggedWith() returns objects tagged with a certain number of tags within a set of specific tags.');
// these tests check the preloadTags() method
Taggable::preloadTags($tagged_with_tag17);
$nb_tags = 0;
foreach ($tagged_with_tag17 as $tmp_object) {
    $nb_tags += count($tmp_object->getTags());
}
$t->ok($nb_tags === 10, 'preloadTags() preloads the tags of the objects.');
// these tests check the isTaggable() method
$t->diag('detecting if a model is taggable or not');
$t->ok(TaggableToolkit::isTaggable(TEST_CLASS) === true, 'it is possible to tell if a model is taggable from its name.');
$object = _create_object();
$t->ok(TaggableToolkit::isTaggable($object) === true, 'it is possible to tell if a model is taggable from one of its instances.');
$t->ok(TaggableToolkit::isTaggable(TEST_NON_TAGGABLE_CLASS) === false, TEST_NON_TAGGABLE_CLASS . ' is not taggable, and that is fine.');
// clean the database
Doctrine_Query::create()->delete()->from('Tag')->execute();
Doctrine_Query::create()->delete()->from('Tagging')->execute();
Doctrine_Query::create()->delete()->from(TEST_CLASS)->execute();
Ejemplo n.º 16
0
 public function taggables()
 {
     return Taggable::where('tag_id', '=', $this->id)->get();
 }
Ejemplo n.º 17
0
<?php

$blogSearch = new stdClass;
$blogSearch->title = t('Blogs');
$blogSearch->module = 'blog';
$blogSearch->file = 'search-results.html.tpl';

Taggable::registerSearch('Blog', $blogSearch);

?>
Ejemplo n.º 18
0
 /**
  * @test
  * @runInSeparateProcess
  */
 public function test_static_setters_and_getters()
 {
     $taggable = new Taggable();
     // Delimiter
     $this->assertEquals(',', $taggable->getTagsDelimiter());
     $taggable->setTagsDelimiter('#');
     $this->assertEquals('#', $taggable->getTagsDelimiter());
     // Model
     $this->assertEquals('Cartalyst\\Tags\\IlluminateTag', $taggable->getTagsModel());
     $taggable->setTagsModel('Foo');
     $this->assertEquals('Foo', $taggable->getTagsModel());
     // Slug generator
     $this->assertEquals('Illuminate\\Support\\Str::slug', $taggable->getSlugGenerator());
     $taggable->setSlugGenerator('Foo');
     $this->assertEquals('Foo', $taggable->getSlugGenerator());
 }
Ejemplo n.º 19
0
 /**
  * Handles downloaded data.
  * The function name is a bit of a misnomer, as it does not actually fetch the contents when using api_multi. This has been done ahead of time (unless we're using the old api() calls).
  * This function writes the downloaded content (json-ified, if it's not a Picture) into its respective output file, causes the new object to create its connections and add them to the queue.
  * @param $facebook A Facebook instance to use for fetching data.
  */
 public function fetch($facebook)
 {
     // If the folder for our output files doesn't exist yet, create it
     if (!is_dir("../tmp/" . $facebook->getUnique())) {
         mkdir("../tmp/" . $facebook->getUnique());
     }
     // Create a safe file name. Simply replaces all slashes, actually.
     //TODO: Write this platform-independent-safe
     $fname = Connection::createSafeName($facebook, $this->url);
     //$fname = $facebook->getUnique() . "/" .strtr($this->url, "/", "~") . ".request";
     // Is this a Picture? If so, we don't process the content but simply write it into a file that has base64($url) as its filename.
     if ($this->type == 'Picture') {
         fprintf($facebook->getLogFd(), "Writing picture with filesize " . strlen($this->json) . "\n");
         if (!file_exists("../tmp/" . $facebook->getUnique() . "/" . base64_encode($this->url))) {
             file_put_contents("../tmp/" . $facebook->getUnique() . "/" . base64_encode($this->url), $this->json);
         }
         return new Picture("", 0);
     }
     try {
         // Check if the file already exists; if so, throw an exception
         if (file_exists($fname)) {
             throw new Exception("File " . $fname . " already exists.");
         }
         // If json is empty, we haven't fetched any content yet, which means that we're using the old API.
         // So let's just use the old api() call. This one also does an implicit json_decode(), so we don't have to perform that anymore.
         if (strlen($this->json) < 1) {
             $this->json = $facebook->api($this->url);
         } else {
             $facebook->log("[RESPONSE] Response's json is larger than 0");
             $this->json = json_decode($this->json, true);
         }
         // Check if the Graph API returned an error.
         if (isset($this->json['error'])) {
             //echo "fetch() FB Error:<br />";
             //print_r($this->json);
             throw new Exception("fb error: " . json_encode($this->json['error']));
         }
     } catch (Exception $e) {
         //echo "fetch() Exception occurred (" . $e->getMessage()  . "), continuing anyway, handling as empty Picture";
         //ob_flush();
         //flush()
         $facebook->log("[ERROR] fetch() Exception occurred (" . $e->getMessage() . "), continuing anyway, handling as empty Picture");
         // This "empty picture" is nearly an empty object. It has no connections and should therefore be completely neutral to the rest of the process.
         return new Picture("", 0);
     }
     // Open the output file for writing
     $facebook->log("[FILE] Creating file " . $fname);
     $fp = fopen($fname, "w");
     // Write the json data - in text form - to the file
     //fwrite($fp, print_r($this->json, TRUE));
     fwrite($fp, json_encode($this->json));
     // Close the output file again.
     fclose($fp);
     if (isset($this->json['paging']) && isset($this->json['paging']['next'])) {
         $queue = new PriorityQueue();
         $url = substr($this->json['paging']['next'], strpos($this->json['paging']['next'], "com/") + 4);
         $facebook->log("[DEBUG] Adding paging URL " . $url);
         $queue->unshift(new Connection($url, $this->depth, $this->type, true), 100);
         Facebook::getQueue()->merge($queue);
     } else {
         $facebook->log("[DEBUG] No paging or next");
     }
     // If the data is not "right there" at the topmost level but nested in the data part, replace our internal variable with the actual payload.
     if (isset($this->json['data'])) {
         $this->json = $this->json['data'];
     }
     // Check if there are multiple objects stored in the received json
     if ($this->multiplicity) {
         $retval = array();
         // Handle each object in json
         foreach ($this->json as $item) {
             // First, the two "meta-types" Profile and Taggable; they're not actual types, but they can determine which of their subtypes is the appropriate one with their static getInstance() method.
             if ($this->type == 'Profile') {
                 array_push($retval, Profile::getInstance($item, $this->depth));
             } else {
                 if ($this->type == 'Taggable') {
                     array_push($retval, Taggable::getInstance($item, $this->depth));
                 } else {
                     // Slight PHP magic: $this->type is a string that contains a class name, i.e. we construct an object whose class name is specified by that field.
                     array_push($retval, new $this->type($item, $this->depth));
                 }
             }
             if ($this->type == 'User') {
                 $facebook->log('Created a user.');
             }
             //$facebook->log(print_r($item));
         }
         $fullnull = true;
         //Performing getConnections() now, adding everything into the big static queue
         // Also, we check if all getConnections() return NULL
         foreach ($retval as $item) {
             if (NULL != $item->getConnections()) {
                 $fullnull = false;
             }
         }
         // All getConnections() have returned NULL, which means that the depth is too high (or deep?). So it's time for us to return NULL, too, in order to let the recursion end at this point (actually, it doesn't end, it just switches to a different part of the recursion tree).
         if ($fullnull) {
             return NULL;
         }
         // Return the array with all parsed objects
         return $retval;
     } else {
         // Same as before: Call getInstance for the meta-types, otherwise create an object with the type $this->type.
         if ($this->type == 'Profile') {
             $retval = Profile::getInstance($this->json, $this->depth);
         } else {
             if ($this->type == 'Taggable') {
                 $retval = Taggable::getInstance($this->json, $this->depth);
             } else {
                 $retval = new $this->type($this->json, $this->depth);
             }
         }
         //Performing getConnections() now, adding this element's connection into the big static queue
         if (NULL == $retval->getConnections()) {
             return NULL;
         }
         // Return the parsed object
         return $retval;
     }
 }
Ejemplo n.º 20
0
 /**
  * DOCUMENT ME
  * @param sfWebRequest $request
  * @return mixed
  */
 public function executeIndex(sfWebRequest $request)
 {
     $params = array();
     $tag = $request->getParameter('tag');
     $type = aMediaTools::getType();
     $type = $type ? $type : $request->getParameter('type');
     // It is permissible to filter more narrowly if the overall type is a metatype (_downloadable)
     if (substr($type, 0, 1) === '_') {
         if ($request->getParameter('type')) {
             $type = $request->getParameter('type');
         }
     }
     $this->embedAllowed = aMediaTools::getEmbedAllowed();
     $this->uploadAllowed = aMediaTools::getUploadAllowed();
     $category = $request->getParameter('category');
     $search = $request->getParameter('search');
     if ($request->isMethod('post')) {
         // Give the routing engine a shot at making the URL pretty.
         // We use addParams because it automatically deletes any
         // params with empty values. (To be fair, http_build_query can't
         // do that because some crappy web application might actually
         // use checkboxes with empty values, and that's not
         // technically wrong. We have the luxury of saying "reasonable
         // people who work here don't do that.")
         return $this->redirect(aUrl::addParams("aMedia/index", array("tag" => $tag, "search" => $search, "type" => $type)));
     }
     if (!empty($tag)) {
         $params['tag'] = $tag;
     }
     if (!empty($search)) {
         $params['search'] = $search;
     }
     if (!empty($type)) {
         $params['type'] = $type;
     }
     if (!empty($category)) {
         $params['category'] = $category;
     }
     // Cheap insurance that these are integers
     $aspectWidth = floor(aMediaTools::getAttribute('aspect-width'));
     $aspectHeight = floor(aMediaTools::getAttribute('aspect-height'));
     if ($type === 'image') {
         // Now that we provide cropping tools, width and height should only exclude images
         // that are too small to ever be cropped to that size
         $minimumWidth = floor(aMediaTools::getAttribute('minimum-width'));
         $width = floor(aMediaTools::getAttribute('width'));
         $minimumWidth = max($minimumWidth, $width);
         $minimumHeight = floor(aMediaTools::getAttribute('minimum-height'));
         $height = floor(aMediaTools::getAttribute('height'));
         $minimumHeight = max($minimumHeight, $height);
         // Careful, aspect ratio can impose a bound on the other dimension
         if ($minimumWidth && $aspectWidth) {
             $minimumHeight = max($minimumHeight, $minimumWidth * $aspectHeight / $aspectWidth);
         }
         if ($minimumHeight && $aspectHeight) {
             $minimumWidth = max($minimumWidth, $minimumHeight * $aspectWidth / $aspectHeight);
         }
         // We've updated these with implicit constraints from the aspect ratio, the width and height params, etc.
         aMediaTools::setAttribute('minimum-width', $minimumWidth);
         aMediaTools::setAttribute('minimum-height', $minimumHeight);
         $params['minimum-width'] = $minimumWidth;
         $params['minimum-height'] = $minimumHeight;
     } else {
         // TODO: performance of these is not awesome (it's a linear search).
         // It would be more awesome with the right kind of indexing. For the
         // aspect ratio test to be more efficient we'd have to store the lowest
         // common denominator aspect ratio and index that.
         if ($aspectWidth && $aspectHeight) {
             $params['aspect-width'] = $aspectWidth;
             $params['aspect-height'] = $aspectHeight;
         }
         $minimumWidth = floor(aMediaTools::getAttribute('minimum-width'));
         if ($minimumWidth) {
             $params['minimum-width'] = $minimumWidth;
         }
         $minimumHeight = floor(aMediaTools::getAttribute('minimum-height'));
         if ($minimumHeight) {
             $params['minimum-height'] = $minimumHeight;
         }
         $width = floor(aMediaTools::getAttribute('width'));
         if ($width) {
             $params['width'] = $width;
         }
         $height = floor(aMediaTools::getAttribute('height'));
         if ($height) {
             $params['height'] = $height;
         }
     }
     // The media module is now an engine module. There is always a page, and that
     // page might have a restricted set of categories associated with it
     $mediaCategories = aTools::getCurrentPage()->Categories;
     if (count($mediaCategories)) {
         $params['allowed_categories'] = $mediaCategories;
     }
     $query = aMediaItemTable::getBrowseQuery($params);
     $this->pager = new sfDoctrinePager('aMediaItem', aMediaTools::getOption('per_page'));
     $page = $request->getParameter('page', 1);
     $this->pager->setQuery($query);
     if ($request->hasParameter('max_per_page')) {
         $this->getUser()->setAttribute('max_per_page', $request->getParameter('max_per_page'), 'apostrophe_media_prefs');
     }
     $this->max_per_page = $this->getUser()->getAttribute('max_per_page', 20, 'apostrophe_media_prefs');
     $this->pager->setMaxPerPage($this->max_per_page);
     $this->pager->setPage($page);
     $this->pager->init();
     $this->results = $this->pager->getResults();
     Taggable::preloadTags($this->results);
     // Go to the last page if we are beyond it
     if ($page > 1 && $page > $this->pager->getLastPage()) {
         $page--;
         $params['page'] = $page;
         return $this->redirect('aMedia/index?' . http_build_query($params));
     }
     aMediaTools::setSearchParameters(array("tag" => $tag, "type" => $type, "search" => $search, "page" => $page, 'category' => $category));
     $this->pagerUrl = "aMedia/index?" . http_build_query($params);
     if (aMediaTools::isSelecting()) {
         $this->selecting = true;
         if (aMediaTools::getAttribute("label")) {
             $this->label = aMediaTools::getAttribute("label");
         }
         $this->limitSizes = $minimumWidth || $minimumHeight;
     }
     if ($request->hasParameter('layout')) {
         $this->getUser()->setAttribute('layout', $request->getParameter('layout'), 'apostrophe_media_prefs');
     }
     $this->layout = aMediaTools::getLayout($this->getUser()->getAttribute('layout', 'two-up', 'apostrophe_media_prefs'));
     $this->enabled_layouts = aMediaTools::getEnabledLayouts();
     return $this->pageTemplate;
 }
Ejemplo n.º 21
0
 /**
  * Preload tags for a set of objects. It might be usefull in case you want to
  * display a long list of taggable objects with their associated tags: it
  * avoids to load tags per object, and gets all tags in a few requests.
  *
  * @param      array       $objects
  */
 public static function preloadTags(&$objects)
 {
     $searched = array();
     foreach ($objects as $object) {
         $class = get_class($object);
         if (!isset($searched[$class])) {
             $searched[$class] = array();
         }
         $searched[$class][$object->getPrimaryKey()] = $object;
         Taggable::set_saved_tags($object, array());
     }
     $q = Doctrine_Core::getTable('Tagging')->createQuery('t')->leftJoin('t.Tag as tag')->orderBy('t.taggable_id')->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY);
     foreach ($searched as $model => $instances) {
         $qClone = clone $q;
         $taggings = $qClone->addWhere('t.taggable_model = ?', $model)->andWhereIn('t.taggable_id', array_keys($instances))->execute();
         foreach ($taggings as $tagging) {
             Taggable::add_saved_tag($instances[$tagging['taggable_id']], $tagging['Tag']['name']);
         }
     }
 }