public function executeList($request) { $page = $request->getParameter('page', 1); $num = $request->getParameter('num', 20); $q = TagTable::getPopularTagsQuery(); $this->tag_pager = new Doctrine_Pager($q, $page, $num); }
/** * Fetch images from pool according to any default tag(s) option specified * in the global schema.yml. * Override added to specify per tag in MooEditable * * @return sfDoctrinePager */ public function getPager($per_page = 12, $page = 1, $tagged_object = null, $tag = null) { $pager = new sfDoctrinePager($this->getClassnameToReturn(), $per_page); $im = new sfImagePoolImage(); if (!$im->option('tagging')) { $tagged_object = $tag = null; } $im->free(true); if (isset($tagged_object) && ($tag = $tagged_object->getTagRestriction())) { $query = TagTable::getObjectTaggedWithQuery($this->getClassnameToReturn(), $tag, $pager->getQuery(), array('nb_common_tags' => 1)); $pager->setQuery($query); } else { if (!empty($tag)) { // If only tags we have no taggable object // So get images tagged with this query and do a whereIn on the ids $tags = explode(',', $tag); $images = TagTable::getObjectTaggedWith($tags, array('model' => 'sfImagePoolImage', 'nb_common_tags' => 1)); $image_ids = array(); foreach ($images as $image) { $image_ids[] = $image->id; } if (!empty($image_ids)) { $pager->getQuery()->whereIn('sfImagePoolImage.id', $image_ids); } else { $pager->getQuery()->where('false'); } // we have no images tagged } } $pager->getQuery()->orderBy('updated_at DESC'); $pager->setPage($page); $pager->init(); return $pager; }
public function executeShow(sfWebRequest $request) { $this->talk = Doctrine::getTable('Talk')->createQuery("t")->leftJoin('t.VoteTalk')->leftJoin('t.CreatedBy p')->leftJoin('t.TalkSection')->leftJoin('p.User')->where('t.id = ?', $request->getParameter('id'))->execute()->getFirst(); $this->forward404Unless($this->talk); $this->comments = Comment::getFor($this->talk); $this->form = new CommentTalkForm(); $this->form->setCommented($this->talk); $this->related = TagTable::getObjectTaggedWith(array_keys($this->talk->getTags()), array('nb_common_tags' => 2, 'leftJoin' => 't.CreatedBy p,p.User')); }
public function withTags($tags) { if ($tags) { $taggings = TagTable::getTaggings($tags, array('model' => $this->_model)); $cmp_tags = isset($taggings[$this->_model]) ? $taggings[$this->_model] : array(0); $this->andWhereIn('i.id', $cmp_tags); } return $this; }
public function getTagChoices() { if (isset($this->tags)) { return $this->tags; } $this->tags = TagTable::getAllTagNameWithCount(null, array('model' => $this->getModelName())); foreach ($this->tags as $key => &$tag) { $tag = $key; } return $this->tags; }
private function getStuff(sfWebRequest $request) { $this->namespace = $request->getParameter('searchNamespace'); $this->search = $this->getUser()->getAttribute('search', null, $this->namespace); $this->tags = TagTable::getAllTagName(); $this->selected_tags = $this->getUser()->getSelectedTags($this->search); if (isset($this->search['customer_name'])) { $this->customer_name = $this->search['customer_name']; } else { $this->customer_name = null; } }
public function executeSidebar() { if ($this->getRequestParameter('tag')) { $this->tag = TagTable::findOrCreateByTagname($this->getRequestParameter('tag')); } if (is_null($this->categories) || !count($this->categories)) { $this->categories = Doctrine::getTable('aBlogCategory')->createQuery('c')->addWhere('c.posts = ?', true)->orderBy('c.name')->execute(); } $categoryIds = array(); foreach ($this->categories as $category) { $categoryIds[] = $category['id']; } $this->popular = Doctrine::getTable('aBlogCategory')->getTagsForCategories($categoryIds, 'aBlogPost', true, 10); $this->tags = Doctrine::getTable('aBlogCategory')->getTagsForCategories($categoryIds, 'aBlogPost'); if ($this->reset == true) { $this->params['cat'] = array(); $this->params['tag'] = array(); } }
public function executeTagWidget() { if (empty($this->object)) { $object_id = $this->getVarHolder()->get('object_id', false); $object_class = $this->getVarHolder()->get('object_class', false); if (!$object_id || !$object_class) { throw new sfException("Must pass both object_id and object_class as option to this component."); } $this->object = Doctrine::getTable($object_class)->findOneBy('id', $object_id); } else { $object_class = get_class($this->object); $object_id = $this->object->id; } if (!$this->object) { throw new sfException("Object with specified parameters does not exist."); } $this->popular_tags = TagTable::getAllTagNameWithCount(null, array('model' => $object_class, 'sort_by_popularity' => true, 'limit' => 10)); foreach ($this->object->getTags() as $tag) { unset($this->popular_tags[$tag]); } }
public function configure() { $typeOptions = array('' => 'All', 'image' => 'Image', 'video' => 'Video', 'pdf' => 'PDF'); $allTags = TagTable::getAllTagNameWithCount(null, array('model' => 'aMediaItem')); $tagOptions = array(); foreach ($allTags as $tag => $count) { $tagOptions[$tag] = "{$tag} ({$count})"; } $tagOptions = array_merge(array('' => 'All'), $tagOptions); $this->setWidgets(array('search' => new sfWidgetFormInput(array(), array('class' => 'a-search-field')), 'type' => new sfWidgetFormSelect(array('choices' => $typeOptions)), 'tag' => new sfWidgetFormSelect(array('choices' => $tagOptions)))); $this->setValidators(array('search' => new sfValidatorPass(array('required' => false)), 'type' => new sfValidatorChoice(array('required' => false, 'choices' => array_keys($typeOptions))), 'tag' => new sfValidatorChoice(array('required' => false, 'choices' => array_keys($tagOptions))))); // This is safe - it doesn't actually retrieve any extra // fields, it just declines to generate an error merely because // they exist $this->validatorSchema->setOptions('allow_extra_fields', true); $this->widgetSchema->setIdFormat('a_media_browser_%s'); $this->widgetSchema->setFormFormatterName('aAdmin'); // Yes, really: this makes it contextual without extra effort $this->widgetSchema->setNameFormat('%s'); $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
/** * @param sfGuardUser $user * @param integer $element_id * @param string $name * @param string $type */ public static function removeTag($user, $element_id, $name, $type) { if ($type == 'decision') { $tagBridge = Doctrine_Core::getTable('TagDecision')->createQuery('td')->leftJoin('td.Tag t')->where('td.decision_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne(); } else { if ($type == 'release') { $tagBridge = Doctrine_Core::getTable('TagRelease')->createQuery('td')->leftJoin('td.Tag t')->where('td.release_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne(); } else { $tagBridge = Doctrine_Core::getTable('TagAlternative')->createQuery('ta')->leftJoin('ta.Tag t')->where('ta.alternative_id = ?', $element_id)->andWhere('t.name = ?', $name)->andWhere('t.user_id = ?', $user->id)->fetchOne(); } } if ($tagBridge) { $tagBridge->delete(); $tagDecision = TagDecisionTable::getInstance()->findOneByTagId($tagBridge->tag_id); if (!$tagDecision) { $tagAlternative = TagAlternativeTable::getInstance()->findOneByTagId($tagBridge->tag_id); if (!$tagAlternative) { TagTable::getInstance()->find($tagBridge->tag_id)->delete(); } } } return; }
public function executeEdit(sfWebRequest $request) { $this->getResponse()->addJavascript('/sfDoctrineActAsTaggablePlugin/js/pkTagahead.js', 'last'); if ($this->getUser()->hasCredential('admin')) { $this->a_blog_post = $this->getRoute()->getObject(); } else { $this->a_blog_post = Doctrine::getTable('aBlogPost')->findOneEditable($request->getParameter('id'), $this->getUser()->getGuardUser()->getId()); } $this->forward404Unless($this->a_blog_post); // Separate forms for separately saved fields $this->form = new aBlogPostForm($this->a_blog_post); // Retrieve the tags currently assigned to the blog post for the inlineTaggableWidget $this->existingTags = $this->form->getObject()->getTags(); // Retrieve the 10 most popular tags for the inlineTaggableWidget $this->popularTags = TagTable::getPopulars(null, array('model' => 'aBlogPost', 'sort_by_popularity' => true), false, 10); aBlogItemTable::populatePages(array($this->a_blog_post)); }
public function executeEdit(sfWebRequest $request) { $this->setAEventForUser(); $this->forward404Unless($this->a_event); $this->form = new aEventForm($this->a_event); // Retrieve the tags currently assigned to the event for the inlineTaggableWidget $this->existingTags = $this->form->getObject()->getTags(); // Retrieve the 10 most popular tags for the inlineTaggableWidget $this->popularTags = TagTable::getAllTagNameWithCount(null, array('model' => 'aEvent', 'sort_by_popularity' => true), false, 10); aBlogItemTable::populatePages(array($this->a_event)); }
/** * @deprecated feature unvollendet entfernt (KM) * Enter description here ... * @param sfWebRequest $request */ public function executeGet_tags(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); //$lArray = array("Affe", "Pferd", "Pinguin"); //var_dump($request->getParameter('model'));die(); $lModel = $request->getParameter('model'); if ($lModel == 'user') { $lTags = TagTable::getAllUserByString(trim($request->getParameter('term'))); } elseif ($lModel == 'dp') { $lTags = TagTable::getAllDpByString(trim($request->getParameter('term'))); } else { $lTags = TagTable::getAllTagsByString(trim($request->getParameter('term'))); } $lArray = array(); foreach ($lTags as $lTag) { array_push($lArray, $lTag['name']); } return $this->renderText(json_encode($lArray)); }
public function executeTagList() { $this->tags = TagTable::getAllTagNameWithCount(null, array('model' => 'aBlogPost', 'sort_by_popularity' => true, 'limit' => 10)); }
public function execute() { if (!$this->safeToRun('uk-mp-candidates')) { $this->printDebug('Script already running'); die; } // Get (or create) the UK local Network $uk = Doctrine::getTable('LsList')->findOneByName('United Kingdom'); if (!$uk) { $uk = new LsList(); $uk->name = 'United Kingdom'; $uk->is_network = 1; $uk->description = 'People and organizations with significant influence on the policies of the United Kingdom'; $uk->display_name = 'uk'; $uk->save(); } // Get the MP list $raw = $this->getMPs(); // Add new MPs to the list foreach ($raw as $mp) { $this->printDebug(sprintf('Processing %s', $mp['name'])); // Split name $entity = PersonTable::parseFlatName($mp['name']); $entity->blurb = 'Prospective Parliamentary Candidate for ' . $mp['constituency']; $q = TagTable::getByTripleQuery('yournextmp', 'url', $mp['url']); $r = $q->count(); if ($r) { $this->printDebug('Already processed, skipping.'); continue; } // Get political party $q = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('e.name = ?', $mp['party']); if (!($partyEntity = $q->fetchOne())) { $partyEntity = new Entity(); $partyEntity->addExtension('Org'); $partyEntity->addExtension('PoliticalParty'); $partyEntity->name = $mp['party']; $partyEntity->blurb = 'UK Political Party'; $partyEntity->save(null, true, array($uk->id)); $this->printDebug("Created new political party: " . $mp['party']); } // Save entity to UK Network $entity->party_id = $partyEntity->id; $entity->save(null, true, array($uk->id)); // Add party relationship $r = new Relationship(); $r->entity1_id = $entity->id; $r->entity2_id = $partyEntity->id; $r->setCategory('Membership'); $r->description1 = 'Prospective parliamentary candidate'; $r->is_current = true; // $r->start_date = // Don't know where we can get this, and "now" seems kind of wrong $r->save(); // Add YourNextMP triple $entity->addTagByTriple('yournextmp', 'url', $mp['url']); // Add references $ref = new Reference(); $ref->addFields(array('name_first', 'name_last', 'name_middle')); // Don't need this $ref->source = $mp['url']; $ref->name = 'YourNextMP.com - ' . $entity['name']; $ref->object_model = 'Entity'; $ref->object_id = $entity->getId(); $ref->save(); unset($ref); $ref = new Reference(); $ref->addFields(array('name')); $ref->source = $mp['party_url']; $ref->name = 'YourNextMP.com - ' . $partyEntity['name']; $ref->object_model = 'Entity'; $ref->object_id = $partyEntity->getId(); $ref->save(); unset($ref); $ref = new Reference(); $ref->addFields(array('name')); $ref->source = $mp['url']; $ref->name = 'YourNextMP.com - ' . $entity['name']; $ref->object_model = 'Relationship'; $ref->object_id = $r->getId(); $ref->save(); unset($ref); $r->free(true); unset($r); // Add image? if ($mp['image']) { if ($fileName = ImageTable::createFiles($mp['image'])) { //insert image record $image = new Image(); $image->filename = $fileName; $image->title = $entity['name']; $image->caption = 'From YourNextMP under CC-BY-SA license.'; $image->is_featured = true; $image->is_free = true; $image->url = $mp['image']; $this->printDebug("Imported image: " . $image->filename); } $image->Entity = $entity; $image->save(); if ($mp['image']) { //save image source $image->addReference($mp['image']); $this->printDebug("Saved image reference"); } unset($image); } // Add party image? if ($mp['party_image']) { if ($fileName = ImageTable::createFiles($mp['party_image'])) { //insert image record $partyImage = new Image(); $partyImage->filename = $fileName; $partyImage->title = $partyEntity['name']; $partyImage->caption = 'From YourNextMP under CC-BY-SA license.'; $partyImage->is_featured = true; $partyImage->is_free = true; $partyImage->url = $mp['party_image']; $this->printDebug("Imported image: " . $partyImage->filename); } $partyImage->Entity = $partyEntity; $partyImage->save(); if ($mp['party_image']) { //save image source $partyImage->addReference($mp['party_image']); $this->printDebug("Saved image reference"); } unset($partyImage); } unset($entity); unset($partyEntity); } }
/** * DOCUMENT ME * @return mixed */ public static function getAllTagNameForUserWithCount() { // Retrieves only tags relating to media items this user is allowed to see $q = NULL; if (!sfContext::getInstance()->getUser()->hasCredential(sfConfig::get('app_a_view_locked_sufficient_credentials', 'view_locked'))) { $q = Doctrine_Query::create()->from('Tagging tg, tg.Tag t, aMediaItem m'); // If you're not logged in, you shouldn't see tags relating to secured stuff // Always IS FALSE, never = FALSE $q->andWhere('m.id = tg.taggable_id AND ((m.view_is_secure IS NULL) OR (m.view_is_secure IS FALSE))'); } return TagTable::getAllTagNameWithCount($q, array("model" => "aMediaItem")); }
/** * 通过video的id 查询这个直播视频对应的标签 * @param $videoId 视频直播的id */ public function get_video_tag_by_videoId($videoId) { $tagTab = new TagTable(); return $tagTab->get_video_tag_by_videoId($videoId); }
public function removeTagByName($name) { $parts = explode(':', $name); if (count($parts) == 3) { if (!($tag = TagTable::getByTripleQuery($parts[0], $parts[1], $parts[2])->fetchOne())) { return false; } } else { if (!($tag = Doctrine::getTable('Tag')->findOneByName($name))) { return false; } } if (!($objectTag = $this->getObjectTag($tag))) { return false; } $objectTag->delete(); return true; }