public function getQuery() { // Explicit select() mandatory with orderByList $q = Doctrine::getTable($this->modelClass)->createQuery()->leftJoin($this->modelClass . '.Author a')->leftJoin($this->modelClass . '.Categories c')->select($this->modelClass . '.*, a.*, c.*'); Doctrine::getTable($this->modelClass)->addPublished($q); if (isset($this->values['title_or_tag']) && $this->values['title_or_tag'] === 'title') { $this->handSelected = true; if (isset($this->values['blog_posts']) && count($this->values['blog_posts'])) { $q->andWhereIn('id', $this->values['blog_posts']); $q = aDoctrine::orderByList($q, $this->values['blog_posts']); } else { $q->andWhere('0 <> 0'); } // Works way better when you actually return it! return $q; } else { if (isset($this->values['categories_list']) && count($this->values['categories_list']) > 0) { $q->andWhereIn('c.id', $this->values['categories_list']); } if (isset($this->values['tags_list']) && strlen($this->values['tags_list']) > 0) { PluginTagTable::getObjectTaggedWithQuery($q->getRootAlias(), $this->values['tags_list'], $q, array('nb_common_tags' => 1)); } if (!isset($this->values['count'])) { $this->values['count'] = 3; } $q->limit($this->values['count']); $q->orderBy('published_at desc'); return $q; } }
/** * 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); }
public function executeTag(sfWebRequest $request) { $p = PluginTagTable::getObjectTaggedWithQuery('peanutPosts', $request->getParameter('tag')); $p->andWhere('peanutPosts.status = ?', 'publish'); $p->orderBy('peanutPosts.created_at DESC'); $this->entries = $p->execute(); $this->forward404Unless($this->entries); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $deleted = PluginTagTable::purgeOrphans(); $count = count($deleted); echo "deleted {$count} orphan tags.\n"; }
public function executeCloud(sfWebRequest $request) { $limit = 50; if ($this->getVar('options')) { $options = $this->getVar('options'); $limit = $options['limit']; } $tags = PluginTagTable::getPopulars(null, array('limit' => $limit)); $this->tags = $tags; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $analytics_activity = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity'); $this->activities = $analytics_activity->findBy(array("user_id" => intval($this->getUser()->getUserId())))->limit(30)->sort(array("cb" => "DESC")); $this->likes_complete = $analytics_activity->findBy(array("user_id" => intval($this->getUser()->getUserId())))->count(); $this->clickbacks_complete = $analytics_activity->getOverallClickbacks($this->getUser()->getUserId()); $q = Doctrine_Query::create(); $q->addWhere("tg.taggable_id = ?", array($this->getUser()->getUserId())); $this->tags = PluginTagTable::getAllTagNameWithCount($q, array("model" => "User", "limit" => 100)); }
public function getQuery() { // Explicit select() mandatory with orderByList $q = Doctrine::getTable($this->modelClass)->createQuery()->leftJoin($this->modelClass . '.Author a')->leftJoin($this->modelClass . '.Categories c')->select($this->modelClass . '.*, a.*, c.*'); Doctrine::getTable($this->modelClass)->addPublished($q); if (isset($this->values['title_or_tag']) && $this->values['title_or_tag'] === 'title') { $this->handSelected = true; if (isset($this->values['blog_posts']) && count($this->values['blog_posts'])) { $q->andWhereIn('id', $this->values['blog_posts']); $q = aDoctrine::orderByList($q, $this->values['blog_posts']); } else { $q->andWhere('0 <> 0'); } // Works way better when you actually return it! return $q; } else { if (isset($this->values['categories_list']) && count($this->values['categories_list']) > 0) { // This doesn't cut it because we wind up not knowing about the // other categories of each post, which breaks our "link to best page // for this post" algorithm // $q->andWhereIn('c.id', $this->values['categories_list']); // This would be nice but Doctrine croaks parsing it // $q->andWhere($this->modelClass . '.id IN (SELECT iblog.id FROM ' . $this->modelClass . ' iblog INNER JOIN iblog.Categories ic WITH ic.id IN ?)', array($this->values['categories_list'])); // Let's cheat and use aMysql to pull the blog item IDs that have the relevant categories in a lightweight way, // then do a whereIn clause. It's not ideal, but it works well in practice $sql = new aMysql(); $blogItemsForCategories = $sql->queryScalar('SELECT i.id FROM a_blog_item i INNER JOIN a_blog_item_to_category ic ON i.id = ic.blog_item_id AND ic.category_id IN :category_ids', array('category_ids' => $this->values['categories_list'])); // So we use this after all, but we'll fetch all the categories for the posts in a second pass, sigh $q->andWhereIn($this->modelClass . '.id', $blogItemsForCategories); } if (isset($this->values['tags_list']) && strlen($this->values['tags_list']) > 0) { PluginTagTable::getObjectTaggedWithQuery($q->getRootAlias(), $this->values['tags_list'], $q, array('nb_common_tags' => 1)); } if (!isset($this->values['count'])) { $this->values['count'] = 3; } $q->limit($this->values['count']); $q->orderBy('published_at desc'); return $q; } }
public function executeNormalView() { $this->setup(); $this->values = $this->slot->getArrayValue(); $q = Doctrine::getTable($this->modelClass)->createQuery()->leftJoin($this->modelClass . '.Author a')->leftJoin($this->modelClass . '.Categories c'); Doctrine::getTable($this->modelClass)->addPublished($q); if (isset($this->values['categories_list']) && count($this->values['categories_list']) > 0) { $q->andWhereIn('c.id', $this->values['categories_list']); } if (isset($this->values['tags_list']) && strlen($this->values['tags_list']) > 0) { PluginTagTable::getObjectTaggedWithQuery($q->getRootAlias(), $this->values['tags_list'], $q, array('nb_common_tags' => 1)); } $limit = isset($this->values['count']) ? $this->values['count'] : 5; $this->options['slideshowOptions']['width'] = isset($this->options['slideshowOptions']['width']) ? $this->options['slideshowOptions']['width'] : 100; $this->options['slideshowOptions']['height'] = isset($this->options['slideshowOptions']['height']) ? $this->options['slideshowOptions']['height'] : 100; $this->options['slideshowOptions']['resizeType'] = isset($this->options['slideshowOptions']['resizeType']) ? $this->options['slideshowOptions']['resizeType'] : 'c'; $this->options['excerptLength'] = $this->getOption('excerptLength', 100); $this->options['maxImages'] = $this->getOption('maxImages', 1); aEventTable::getInstance()->addUpcoming($q, $limit); $this->aEvents = $q->execute(); aBlogItemTable::populatePages($this->aEvents); }
public function executeTags(sfRequest $request) { $this->validateAPIKey(); $tags = PluginTagTable::getAllTagName(); $this->jsonResponse('ok', $tags); }
public function getObjectTaggedWith($options = array()) { return PluginTagTable::getObjectTaggedWith($this->name); }
/** * DOCUMENT ME */ public function configure() { parent::configure(); $manage = $this->getObject()->isNew() ? true : $this->getObject()->userHasPrivilege('manage'); $user = sfContext::getInstance()->getUser(); // $page->setArchived(!sfConfig::get('app_a_default_published', sfConfig::get('app_a_default_on', true))); // We must explicitly limit the fields because otherwise tables with foreign key relationships // to the pages table will extend the form whether it's appropriate or not. If you want to do // those things on behalf of an engine used in some pages, define a form class called // enginemodulenameEngineForm. It will automatically be instantiated with the engine page // as an argument to the constructor, and rendered beneath the main page settings form. // On submit, it will be bound to the parameter name that begins its name format and, if valid, // saved consecutively after the main page settings form. The form will be rendered via // the _renderPageSettingsForm partial in your engine module, which must exist, although it // can be as simple as echo $form. (Your form is passed to the partial as $form.) // // We would use embedded forms if we could. Unfortunately Symfony has unresolved bugs relating // to one-to-many relations in embedded forms. $fields = array('slug', 'archived'); if ($user->hasCredential('cms_admin')) { $fields[] = 'edit_admin_lock'; } $this->useFields($fields); $object = $this->getObject(); // The states we really have now are: // Public // Login required, with various settings plus a boolean for "guest" access // Admin only (for which we have added view_admin_lock) // The problem is that right now, public and "guest" are distinguished by a single boolean. // It's a pain to turn that into an enumeration. // So we need an additional "view_guest" boolean consulted when "view_is_secure" is true, and // that new boolean should default to true. // In 2.0 we'll probably clean these flags up a bit. $choices = array('public' => 'Public', 'login' => 'Login Required', 'admin' => 'Admins Only'); if (!$user->hasCredential('cms_admin')) { // You can't stop yourself and your peers from viewing a page unset($choices['admin']); } $default = 'public'; if ($object->view_admin_lock) { $default = 'admin'; } elseif ($object->view_is_secure) { $default = 'login'; } if ($manage) { $this->setWidget('view_options', new sfWidgetFormChoice(array('choices' => $choices, 'expanded' => true, 'default' => $default))); $this->setValidator('view_options', new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => true))); if ($this->getObject()->hasChildren(false)) { $this->setWidget('view_options_apply_to_subpages', new sfWidgetFormInputCheckbox(array('label' => 'Apply to Subpages'))); $this->setValidator('view_options_apply_to_subpages', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', '')))); } $this->setWidget('view_individuals', new sfWidgetFormInputHidden(array('default' => $this->getViewIndividualsJSON()))); $this->setValidator('view_individuals', new sfValidatorCallback(array('callback' => array($this, 'validateViewIndividuals'), 'required' => true))); $this->setWidget('view_groups', new sfWidgetFormInputHidden(array('default' => $this->getViewGroupsJSON()))); $this->setValidator('view_groups', new sfValidatorCallback(array('callback' => array($this, 'validateViewGroups'), 'required' => true))); } // Changed the name so Doctrine doesn't get uppity $engine = $object->engine; $template = $object->template; if (!strlen($object->template)) { $object->template = 'default'; } if (!is_null($object->engine)) { $joinedTemplateName = $object->engine . ':' . $object->template; } else { $joinedTemplateName = 'a' . ':' . $object->template; } $choices = aTools::getTemplateChoices(); $this->setWidget('joinedtemplate', new sfWidgetFormSelect(array('choices' => $choices, 'default' => $joinedTemplateName))); $this->setValidator('joinedtemplate', new sfValidatorChoice(array('required' => true, 'choices' => array_keys($choices)))); // Published vs. Unpublished makes more sense to end users, but when we first // designed this feature we had an 'archived vs. unarchived' // approach in mind $this->setWidget('archived', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(false => "Published", true => "Unpublished"), 'default' => false))); if ($this->getObject()->hasChildren(false)) { $this->setWidget('cascade_archived', new sfWidgetFormInputCheckbox()); $this->setValidator('cascade_archived', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', '')))); } // Tags $options['default'] = implode(', ', $this->getObject()->getTags()); // added a space after the comma for readability if (sfConfig::get('app_a_all_tags', true)) { $options['all-tags'] = PluginTagTable::getAllTagNameWithCount(); } else { sfContext::getInstance()->getConfiguration()->loadHelpers('Url'); $options['typeahead-url'] = url_for('taggableComplete/complete'); } $options['popular-tags'] = PluginTagTable::getPopulars(null, array('sort_by_popularity' => true), false, 10); $options['commit-selector'] = '#' . ($this->getObject()->isNew() ? 'a-create-page' : 'a-page-settings') . '-submit'; $options['tags-label'] = ''; // class tag-input enabled for typeahead support $this->setWidget('tags', new pkWidgetFormJQueryTaggable($options, array('class' => 'tags-input'))); $this->setValidator('tags', new sfValidatorString(array('required' => false))); // Meta Description // Call the widget real_meta_description to avoid conflicts with the automatic behavior // of Doctrine forms (which will call setMetaDescription before the page is saved, something // that newAreaVersion does not support) $metaDescription = $this->getObject()->getMetaDescription(); $this->setWidget('real_meta_description', new sfWidgetFormTextArea(array('default' => html_entity_decode($metaDescription, ENT_COMPAT, 'UTF-8')))); $this->setValidator('real_meta_description', new sfValidatorString(array('required' => false))); $privilegePage = $this->getObject(); if ($privilegePage->isNew()) { $privilegePage = $this->parent; } if ($user->hasCredential('cms_admin')) { $this->setWidget('edit_individuals', new sfWidgetFormInputHidden(array('default' => $this->getEditIndividualsJSON()))); $this->setValidator('edit_individuals', new sfValidatorCallback(array('callback' => array($this, 'validateEditIndividuals'), 'required' => true))); $this->setWidget('edit_groups', new sfWidgetFormInputHidden(array('default' => $this->getEditGroupsJSON()))); $this->setValidator('edit_groups', new sfValidatorCallback(array('callback' => array($this, 'validateEditGroups'), 'required' => true))); } // If you can delete the page, you can change the slug if ($manage) { $this->setValidator('slug', new aValidatorSlug(array('required' => true, 'allow_slashes' => true, 'require_leading_slash' => true), array('required' => 'The permalink cannot be empty.', 'invalid' => 'The permalink must contain only slashes, letters, digits, dashes and underscores. There must be a leading slash. Also, you cannot change a permalink to conflict with an existing permalink.'))); $this->setWidget('slug', new sfWidgetFormInputText()); } // Named 'realtitle' to avoid excessively magic Doctrine form behavior. // Specifically, updateObject() will automatically call setTitle() if there // is such a method and a widget named 'title', and we don't want that to // happen until after the page is saved so we can store it in a slot $this->setValidator('realtitle', new sfValidatorString(array('required' => true), array('required' => 'The title cannot be empty.'))); $title = $this->getObject()->getTitle(); $this->setWidget('realtitle', new sfWidgetFormInputText(array('default' => html_entity_decode($this->getObject()->getTitle(), ENT_COMPAT, 'UTF-8')))); // The slug of the home page cannot change (chicken and egg problems) if ($this->getObject()->getSlug() === '/') { unset($this['slug']); } else { $this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique(array('model' => 'aPage', 'column' => 'slug'), array('invalid' => 'There is already a page with that slug.'))); } $this->widgetSchema->setIdFormat('a_settings_%s'); $this->widgetSchema->setNameFormat('settings[%s]'); $this->widgetSchema->setFormFormatterName('list'); // We changed the form formatter name, so we have to reset the translation catalogue too $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
public function executeListByTag(sfWebRequest $request) { $this->snippets = PluginTagTable::getObjectTaggedWith($request->getParameter('tag')); $this->setTemplate('index'); }
/** * DOCUMENT ME * @param sfWebRequest $request */ public function executeClean(sfWebRequest $request) { $deleted = PluginTagTable::purgeOrphans(); $count = count($deleted); $this->getUser()->setFlash('notice', "{$count} unused tags removed."); $this->redirect('a_tag_admin'); }
public function filterByTag(Doctrine_Query $q, sfWebRequest $request) { PluginTagTable::getObjectTaggedWithQuery($q->getRootAlias(), $request->getParameter('tag'), $q, array('nb_common_tag' => 1)); }
/** * DOCUMENT ME * @param sfWebRequest $request * @return mixed */ public function executeEditMultiple(sfWebRequest $request) { $this->forward404Unless(aMediaTools::userHasUploadPrivilege()); $this->embedAllowed = aMediaTools::getEmbedAllowed(); $this->uploadAllowed = aMediaTools::getUploadAllowed(); // I'd put these in the form class, but I can't seem to access them // there unless the whole form is valid. I need them as metadata // to control the form's behavior, so that won't cut it. // Perhaps I could put them in a second form, since there's // no actual restriction on multiple form objects inside a // single HTML form element. $this->firstPass = $request->getParameter('first_pass'); $items = $request->getParameter('a_media_items'); // The active parameter was redundant, just look at the items that are present. // This allows successive passes to prune out some items if desired $active = array(); foreach ($items as $itemName => $item) { if (preg_match('/^item-(\\d+)$/', $itemName, $matches)) { $active[] = $matches[1]; } } $this->totalItems = count($active); $this->form = new aMediaEditMultipleForm($active); $this->form->bind($request->getParameter('a_media_items'), $request->getFiles('a_media_items')); $this->popularTags = PluginTagTable::getPopulars(null, array('sort_by_popularity' => true), false, 10); if (sfConfig::get('app_a_all_tags', true)) { $this->allTags = PluginTagTable::getAllTagNameWithCount(); } else { $this->allTags = array(); } $this->postMaxSizeExceeded = false; // An empty POST is an anomaly indicating that we hit the php.ini max_post_size or similar if ($request->isMethod('post') && !count($request->getPostParameters())) { // This is a bummer because you've lost your annotation work but we really can't // resurrect it from an empty POST, short of keeping everything in attributes $this->forward('aMedia', 'upload'); } if (!$this->firstPass && $this->form->isValid()) { $values = $this->form->getValues(); // This is NOT automatic since this isn't a Doctrine form. http://thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list foreach ($this->form->getEmbeddedForms() as $key => $itemForm) { // Called from doSave in the embedded form, these will never be called here if we don't call them ourselves. // Modifies $values[$key] by reference $itemForm->updateCategoriesList($values[$key]); $itemForm->updateObject($values[$key]); $object = $itemForm->getObject(); if ($object->getId()) { // We're creating new objects only here, but the embedded form // supports an id for an existing object, which is useful in // other contexts. Prevent hackers from stuffing in changes // to media items they don't own. $this->forward404(); } // updateObject doesn't handle one-to-many relations, only save() does, and we // can't do save() in this embedded form, so we need to implement the categories // relation ourselves $object->unlink('Categories'); $object->link('Categories', $values[$key]['categories_list']); // Everything except the actual copy which can't succeed // until the slug is cast in stone $file = $values[$key]['file']; $object->preSaveFile($file); $object->save(); $object->saveFile($file); } return $this->redirect('aMedia/resume'); } }
/** * Retrieve a Doctrine_Query instance for querying tagged model objects. * * Example: * * $q = PluginTagTable::getObjectTaggedWithQuery('Article', array('tag1', 'tag2')); * $q->orderBy('posted_at DESC'); * $q->limit(10); * $this->articles = $q->execute(); * * @param string $model Taggable model name * @param mixed $tags array of tags (can be a string where tags are * comma separated) * @param Doctrine_Query $q Existing Doctrine_Query to hydrate * @return Doctrine_Query */ public static function getObjectTaggedWithQuery($model, $tags = array(), Doctrine_Query $q = null, $options = array()) { $tags = TaggableToolkit::explodeTagString($tags); if (is_string($tags)) { $tags = array($tags); } if (!class_exists($model) || !PluginTagTable::isDoctrineModelClass($model)) { throw new sfDoctrineException(sprintf('The class "%s" does not exist, or it is not a model class.', $model)); } if (!$q instanceof Doctrine_Query) { $q = Doctrine_Query::create()->from($model); } $taggings = self::getTaggings($tags, array_merge(array('model' => $model), $options)); $tagging = isset($taggings[$model]) ? $taggings[$model] : array(); if (empty($tagging)) { $q->where('false'); } else { $q->whereIn($model . '.id', $tagging); } return $q; }
public static function getTaggings($tags = array(), $options = array()) { return parent::getTaggings($tags, $options); }
public function filterByTag($tag, Doctrine_Query $q) { PluginTagTable::getObjectTaggedWithQuery($q->getRootAlias(), $tag, $q, array('nb_common_tag' => 1)); }