예제 #1
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Get all tags
  *
  * @param  int    $limit
  * @param  int    $page
  * @param  string $sort
  * @return array
  */
 public function getAll($limit = null, $page = null, $sort = null)
 {
     $order = $this->getSortOrder($sort, $page);
     $sql = Table\TagItems::sql();
     $sql->select([0 => 'tag_id', 1 => 'id', 2 => 'title', 3 => 'slug', 'count' => 'COUNT(1)'])->join(DB_PREFIX . 'tags', [DB_PREFIX . 'tags.id' => DB_PREFIX . 'tag_items.tag_id']);
     $sql->select()->groupBy('tag_id');
     $orderAry = explode(' ', $order);
     $sql->select()->orderBy($orderAry[0], $orderAry[1]);
     if (null !== $limit) {
         $page = null !== $page && (int) $page > 1 ? $page * $limit - $limit : null;
         $sql->select()->offset($page);
         $sql->select()->limit($limit);
         return Table\TagItems::query($sql)->rows();
     } else {
         return Table\TagItems::query($sql)->rows();
     }
 }
예제 #2
0
파일: Tag.php 프로젝트: phirecms/phire-tags
 /**
  * Get all tag values for the form object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function getAll(AbstractController $controller, Application $application)
 {
     if (!$_POST && $controller->hasView() && null !== $controller->view()->form && $controller->view()->form !== false && (int) $controller->view()->form->id != 0 && null !== $controller->view()->form && $controller->view()->form instanceof \Phire\Content\Form\Content) {
         $contentId = $controller->view()->form->id;
         $tags = [];
         if (null !== $contentId) {
             $sql = Table\TagItems::sql();
             $sql->select()->join(DB_PREFIX . 'tags', [DB_PREFIX . 'tags.id' => DB_PREFIX . 'tag_items.tag_id']);
             $sql->select()->where('content_id = :content_id');
             $c2t = Table\TagItems::execute($sql, ['content_id' => $contentId]);
             if ($c2t->hasRows()) {
                 foreach ($c2t->rows() as $c) {
                     $tags[] = $c->title;
                 }
             }
             if (count($tags) > 0) {
                 $controller->view()->form->content_tags = implode(',', $tags);
             }
         }
     }
 }