Esempio n. 1
0
 public function renderTags()
 {
     $element = "<select id ='tags' name='tags[]' class ='form-control' multiple='multiple'>";
     $tags = Tags::find();
     foreach ($tags as $key => $tag) {
         $selected = '';
         if (is_array($this->tagsId)) {
             if (in_array($tag->id, $this->tagsId)) {
                 $selected = 'selected';
             }
         }
         $element .= "<option value='{$tag->id}' {$selected}> {$tag->name}";
         $element .= "</option>";
     }
     $element .= "</select>";
     return $element;
 }
Esempio n. 2
0
 /**
  * Retrieve a list of Posts for a specific tags id.
  *
  * @param int    $id       The Tags ID
  * @param string $slugTags
  *
  * @return array list of posts
  */
 public function postByTagAction($id, $slugName)
 {
     $join = ['type' => 'join', 'model' => 'Phanbook\\Models\\PostsTags', 'on' => 'pt.postsId = p.id', 'alias' => 'pt'];
     /**@Todo later for security*/
     $where = 'p.deleted = 0 AND pt.tagsId = ' . $id;
     list($itemBuilder, $totalBuilder) = $this->prepareQueries($join, $where, $this->perPage);
     //$itemBuilder->andWhere($conditions);
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute();
     $totalPages = ceil($totalPosts->count / $this->perPage);
     if ($page > 1) {
         $itemBuilder->offset((int) $page);
     }
     //@todo refacttor
     $this->view->setVars(['tab' => 'tags', 'type' => Posts::POST_ALL, 'posts' => $itemBuilder->getQuery()->execute(), 'totalPages' => $totalPages, 'currentPage' => $page, 'slugName' => $slugName, 'tags' => Tags::find()]);
     $this->tag->setTitle(t('These posts fillter by tags'));
     return $this->view->pick('post');
 }
Esempio n. 3
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     $postsId = Posts::find(['columns' => 'id'])->toArray();
     $tagsId = Tags::find(['columns' => 'id'])->toArray();
     for ($i = 0; $i <= self::POSTS_TAGS_TOTAL; $i++) {
         $postRandId = array_rand($postsId);
         $tagsRandId = array_rand($tagsId);
         $postTag = new PostsTags();
         $postTag->postsId = $postsId[$postRandId]['id'];
         $postTag->tagsId = $tagsId[$tagsRandId]['id'];
         if (!$postTag->save()) {
             var_dump($tags->getMessages());
             $database->rollback();
             die;
         }
         $log->info('Posts<->Tags ' . $postTag->getPostsId() . '<->' . $postTag->getTagsId());
     }
 }
Esempio n. 4
0
 /**
  * Default it will get all posts
  *
  */
 public function indexAction()
 {
     /* @var \Phalcon\Mvc\Model\Query\BuilderInterface $itemBuilder */
     /* @var \Phalcon\Mvc\Model\Query\BuilderInterface $totalBuilder */
     $tab = $this->request->getQuery('tab');
     $page = isset($_GET['page']) ? (int) $_GET['page'] : $this->numberPage;
     $perPage = isset($_GET['perPage']) ? (int) $_GET['perPage'] : $this->perPage;
     if ($tab == "answers") {
         $join = ['type' => 'join', 'model' => 'Phanbook\\Models\\PostsReply', 'on' => 'r.postsId = p.id', 'alias' => 'r'];
         list($itemBuilder, $totalBuilder) = ModelBase::prepareQueriesPosts($join, false, $perPage);
         $itemBuilder->groupBy(array('p.id'));
     } else {
         list($itemBuilder, $totalBuilder) = ModelBase::prepareQueriesPosts('', false, $perPage);
     }
     $userId = $this->auth->getAuth();
     /*
      * Create the conditions according to the parameter order
      */
     $params = null;
     switch ($tab) {
         case 'hot':
             $this->tag->setTitle('Hot Questions');
             $itemBuilder->orderBy('p.modifiedAt DESC');
             break;
         case 'unanswered':
             $this->tag->setTitle('Unanswered Questions');
             $unansweredConditions = 'p.numberReply = 0 AND p.acceptedAnswer <> "Y"';
             $itemBuilder->where($unansweredConditions);
             $totalBuilder->where($unansweredConditions);
             break;
         case 'week':
             $this->tag->setTitle('Hot Questions This Week');
             $lastWeek = new \DateTime();
             $lastWeek->modify('-1 week');
             $params = array($lastWeek->getTimestamp());
             $weekConditions = 'p.createdAt >= ?0';
             $itemBuilder->where($weekConditions);
             $totalBuilder->where($weekConditions);
             break;
         case 'month':
             $this->tag->setTitle('Hot Questions This Month');
             $lastMonths = new \DateTime();
             $lastMonths->modify('-6 month');
             $params = array($lastMonths->getTimestamp());
             $monthConditions = 'p.createdAt >= ?0';
             $itemBuilder->where($monthConditions);
             $totalBuilder->where($monthConditions);
             break;
         case 'questions':
             $this->tag->setTitle('Questions');
             $questionConditions = 'p.type = "questions"';
             $itemBuilder->where($questionConditions);
             $totalBuilder->where($questionConditions);
             break;
         case 'blog':
             $this->tag->setTitle('Blogs');
             $blogConditions = 'p.type = "blog"';
             $itemBuilder->where($blogConditions);
             $totalBuilder->where($blogConditions);
             break;
         case 'hackernews':
             $this->tag->setTitle('Hacker News');
             $tipConditions = 'p.type = "hackernews"';
             $itemBuilder->where($tipConditions);
             $totalBuilder->where($tipConditions);
             break;
         default:
             $this->tag->setTitle($this->config->application->tagline);
     }
     $type = Posts::POST_PAGE;
     $conditions = "p.deleted = 0 AND p.type != '{$type}'";
     $itemBuilder->andWhere($conditions);
     $totalBuilder->andWhere($conditions);
     //order like tabs sort
     if (!$tab) {
         $tab = 'hot';
     }
     $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute($params);
     $totalPages = ceil($totalPosts->count / $perPage);
     $offset = ($page - 1) * $perPage + 1;
     if ($page > 1) {
         $itemBuilder->offset($offset);
     }
     $this->view->setVars(['tab' => $tab, 'type' => Posts::POST_ALL, 'posts' => $itemBuilder->getQuery()->execute($params), 'totalPages' => $totalPages, 'currentPage' => $page, 'tags' => Tags::find()]);
     return $this->view->pick('post');
 }
Esempio n. 5
0
 public function initialize()
 {
     $this->view->setVars(['tab' => $this->currentOrder, 'tags' => Tags::find(), 'hotPosts' => Posts::getHotPosts(5), 'totalPost' => Posts::totalPost(), 'highestKarma' => Users::highestKarma(), 'totalReply' => PostsReply::totalReply()]);
     if (isset($this->config->perPage)) {
         $this->perPage = $this->config->perPage;
     }
 }
Esempio n. 6
0
 /**
  * Returns those tags that don't have bounties
  *
  * @return array
  */
 public function getFullNoBountyTags()
 {
     if (!$this->fullNoBountyTags) {
         $this->fullNoBountyTags = Tags::find('noBounty = "Y"')->toArray();
     }
     return $this->fullNoBountyTags;
 }