当前位置: 首页>>代码示例>>PHP>>正文


PHP Posts::select方法代码示例

本文整理汇总了PHP中Posts::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::select方法的具体用法?PHP Posts::select怎么用?PHP Posts::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Posts的用法示例。


在下文中一共展示了Posts::select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: executeDefault

 public function executeDefault()
 {
     $this->setView('Post/default');
     $pageSize = 20;
     $taxonomy = $this->request()->get('taxonomy', 'STRING', 'post');
     $page_title = Plugin::getTaxonomyOption($taxonomy, 'post', 'label', t('Post Management'));
     if ($this->request()->isPostRequest()) {
         $ordering = $this->request()->post('ordering', 'ARRAY', array());
         foreach ($ordering as $id => $value) {
             $_p = \Posts::retrieveById($id);
             if ($_p) {
                 $_p->setOrdering($value);
                 $_p->save();
             }
         }
     }
     $this->document()->title .= $page_title;
     $filter = $this->request()->get('filter', 'ARRAY', array());
     $query = \Posts::select()->where('`taxonomy`=:taxonomy')->andWhere('`is_draft` = :is_draft')->setParameter(':is_draft', false, \PDO::PARAM_INT)->setParameter(':taxonomy', $taxonomy, \PDO::PARAM_STR);
     if (isset($filter['keyword']) && !empty($filter['keyword'])) {
         $query->andWhere('`title` LIKE "%' . $filter['keyword'] . '%"');
     }
     if (isset($filter['status']) && '' != $filter['status'] && 'All' != $filter['status']) {
         $query->andWhere('`status` = "' . $filter['status'] . '"');
     }
     if (isset($filter['language']) && '*' != $filter['language']) {
         $query->andWhere('`language` = "' . $filter['language'] . '"');
     }
     if (isset($filter['cat_id']) && $filter['cat_id'] != 0) {
         $cat = \Terms::retrieveById($filter['cat_id']);
         $_c = array();
         if ($cat) {
             $branches = $cat->getBranch();
             foreach ($branches as $branch) {
                 $_c[] = $branch->getId();
             }
             $query->andWhere('`term_id` IN (' . implode(',', $_c) . ')');
         }
     }
     $countQuery = clone $query;
     $total = $countQuery->count()->execute();
     $orderBy = Plugin::applyFilters('default_' . $taxonomy . '_ordering', array('id', 'DESC'));
     //paging
     $page = $this->request()->get('page', 'INIT', 1);
     $query->setMaxResults($pageSize)->setFirstResult(($page - 1) * $pageSize)->orderBy($orderBy[0], $orderBy[1]);
     $list = $query->execute();
     $taxonomy_term = Plugin::getTaxonomyOption($taxonomy, 'post', 'term_taxonomy', 'category');
     $table = new PostList($taxonomy);
     $table->setItems($list);
     $this->view()->assign(array('page_title' => $page_title, 'taxonomy' => $taxonomy, 'taxonomy_term' => $taxonomy_term, 'table' => $table, 'list' => $list, 'filter' => $filter, 'total' => $total, 'page_size' => $pageSize));
     return $this->renderComponent();
 }
开发者ID:hosivan90,项目名称:toxotes,代码行数:52,代码来源:Post.php

示例2: executeDefault

 public function executeDefault()
 {
     if (!($cat = \Terms::retrieveById($this->request()->get('id')))) {
         $this->raise404();
     }
     $viewProp = $cat->getProperty('cat_view');
     if ($viewProp) {
         $this->setView('Category/' . $viewProp->getPropertyValue());
     } else {
         $this->setView('Category/default');
     }
     $child = $cat->getDescendants();
     $q = \Posts::select()->where('`status` = :status AND `is_draft` = 0')->setParameter(':status', 'PUBLISH', \PDO::PARAM_STR);
     //Filter
     $catId = array($cat->getId());
     foreach ($child as $c) {
         $catId[] = $c->getId();
     }
     $q->andWhere('`term_id` IN (' . implode(',', $catId) . ')');
     //Filter by time
     $day = $this->request()->get('day');
     $month = $this->request()->get('month');
     $year = $this->request()->get('year');
     if ($day || $month || $year) {
         if ($day) {
             $q->andWhere('DAY(`created_time`) = :day')->setParameter(':day', $day, \PDO::PARAM_STR);
         }
         if ($month) {
             $q->andWhere('MONTH(`created_time`) = :month')->setParameter(':month', $month, \PDO::PARAM_STR);
         }
         if ($year) {
             $q->andWhere('YEAR(`created_time`) = :year')->setParameter(':year', $year, \PDO::PARAM_STR);
         }
     }
     //Keyword
     if ($keyword = $this->request()->get('keyword')) {
         $q->andWhere('`title` LIKE "%' . $keyword . '%"');
     }
     //Ordering
     $orderingProp = $cat->getProperty('post_ordering');
     if ($orderingProp) {
         switch ($orderingProp->getPropertyValue()) {
             case 'created_time':
                 $q->addOrderBy('created_time');
                 break;
             case 'ordering':
                 $q->addOrderBy('ordering');
                 break;
             case 'modified_time':
             case 'default':
             default:
                 $q->addOrderBy('created_time', 'DESC');
                 break;
         }
     } else {
         $q->addOrderBy('created_time', 'DESC');
     }
     $qCount = clone $q;
     $total = $qCount->count()->execute();
     //Paging
     $pageSizeProp = $cat->getProperty('page_size');
     if ($pageSizeProp) {
         $page_size = $cat->getProperty('page_size')->getPropertyValue();
         if (-1 != $pageSizeProp->getPropertyValue()) {
             $q->setMaxResults($pageSizeProp->getPropertyValue());
             $page = $this->request()->get('page', 'INT', 1);
             $q->setFirstResult(($page - 1) * $pageSizeProp->getPropertyValue());
         }
     } else {
         $page_size = 25;
         $q->setMaxResults(25);
         $page = $this->request()->get('page', 'INT', 1);
         $q->setFirstResult(($page - 1) * $page_size);
     }
     $posts = $q->execute();
     $this->view()->assign(array('page_size' => $page_size, 'total' => $total, 'cat' => $cat, 'child' => $child, 'posts' => $posts));
     return $this->renderComponent();
 }
开发者ID:hosivan90,项目名称:toxotes,代码行数:78,代码来源:Category.php

示例3: fixAction

 /**
  * @todo Remove when done
  */
 public function fixAction()
 {
     $posts = new Posts();
     $tposts = $posts->fetchAll($posts->select()->where('id > 0'));
     $defaultFilterChain = new Zend_Filter();
     $defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean());
     $defaultFilterChain->addFilter(new Zend_Filter_StringTrim());
     $defaultFilterChain->addFilter(new Zend_Filter_StripTags());
     $defaultFilterChain->addFilter(new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES, 'charset' => 'UTF-8')));
     $defaultFilterChain->addFilter(new Ifphp_Filter_HtmlEntityNames());
     foreach ($tposts as $post) {
         $post->title = $defaultFilterChain->filter($post->title);
         $post->description = $defaultFilterChain->filter($post->description);
         $post->feedId = $defaultFilterChain->filter($post->feedId);
         $post->link = $defaultFilterChain->filter($post->link);
         $post->publishDate = $post->publishDate;
         //            Zend_Debug::dump($post->description);
         $post->save();
     }
     $feeds = new Feeds();
     $tfeeds = $feeds->fetchAll($feeds->select()->where('id > 0'));
     $inflector = new Zend_Filter_Inflector(':title');
     $inflector->setRules(array(':title' => array('Word_SeparatorToDash', 'StringToLower', 'HtmlEntities')));
     foreach ($tfeeds as $feed) {
         $feed->title = $defaultFilterChain->filter($feed->title);
         $feed->description = $defaultFilterChain->filter($feed->description);
         $feed->slug = $inflector->filter(array('title' => $feed->title));
         $feed->save();
     }
     die;
 }
开发者ID:akeemphilbert,项目名称:ifphp,代码行数:34,代码来源:FeedController.php


注:本文中的Posts::select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。