예제 #1
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Category
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->title) {
         // Check for dupe name
         $tag = Table\Tags::findBy(['title' => $this->title]);
         if (isset($tag->id) && $this->id != $tag->id) {
             $this->getElement('title')->addValidator(new Validator\NotEqual($this->title, 'That tag already exists.'));
         }
     }
     return $this;
 }
예제 #2
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Get tag content
  *
  * @param  Table\Tags          $tag
  * @param  \Pop\Module\Manager $modules
  * @return void
  */
 protected function getTag(Table\Tags $tag, \Pop\Module\Manager $modules)
 {
     if ($modules->isRegistered('phire-fields')) {
         $t = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Tags\\Model\\Tag', [$tag->id]);
         $data = $t->toArray();
     } else {
         $data = $tag->getColumns();
     }
     $items = [];
     $c2t = Table\TagItems::findBy(['tag_id' => $tag->id], ['order' => 'content_id DESC']);
     if ($c2t->hasRows()) {
         foreach ($c2t->rows() as $c) {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', [$c->content_id], 'getById', $modules['phire-tags']['filters']);
             } else {
                 $class = 'Phire\\Content\\Model\\Content';
                 $model = new $class();
                 call_user_func_array([$model, 'getById'], [$c->content_id]);
                 $item = $model;
             }
             if ($item->status == 1 && count($item->roles) == 0) {
                 $items[$item->id] = new \ArrayObject($item->toArray(), \ArrayObject::ARRAY_AS_PROPS);
             }
         }
     }
     $data['items'] = $items;
     $this->data = array_merge($this->data, $data);
 }
예제 #3
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Save tag relationships
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function save(AbstractController $controller, Application $application)
 {
     $contentId = null;
     if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) {
         $tags = $controller->view()->form->content_tags;
         $contentId = $controller->view()->id;
         if (null !== $contentId) {
             $c2t = new Table\TagItems();
             $c2t->delete(['content_id' => $contentId]);
         }
         if (!empty($tags)) {
             $tags = explode(',', $tags);
             foreach ($tags as $tag) {
                 $tag = trim($tag);
                 $t = Table\Tags::findBy(['title' => $tag]);
                 if (!isset($t->id)) {
                     $t = new Table\Tags(['title' => $tag, 'slug' => Slug::filter($tag)]);
                     $t->save();
                 }
                 $c2t = new Table\TagItems(['content_id' => $contentId, 'tag_id' => $t->id]);
                 $c2t->save();
             }
         }
     }
 }