コード例 #1
0
ファイル: actions.class.php プロジェクト: 42medien/spreadly
 /**
  * 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));
 }
コード例 #2
0
 public function executeEditView()
 {
     // Must be at the start of both view components
     $this->setup();
     // Careful, don't clobber a form object provided to us with validation errors
     // from an earlier pass
     if (!isset($this->form)) {
         $this->form = new $this->formClass($this->id, $this->slot->getArrayValue());
     }
     $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();
     }
 }
コード例 #3
0
 /**
  * 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');
 }
コード例 #4
0
 /**
  * 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');
     }
 }