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


PHP Poll::generate方法代码示例

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


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

示例1: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     $intPoll = $this->poll;
     // Try to find the current poll
     if ($this->poll_current) {
         $time = time();
         $objCurrentPoll = $this->Database->prepare("SELECT id FROM tl_poll WHERE (showStart='' OR showStart<?) AND (showStop='' OR showStop>?)" . (!BE_USER_LOGGED_IN ? " AND published=1" : "") . " ORDER BY showStart DESC, activeStart DESC")->limit(1)->execute($time, $time);
         if ($objCurrentPoll->numRows) {
             $intPoll = $objCurrentPoll->id;
         }
     }
     // Return if there is no poll
     if (!$intPoll) {
         $this->Template->poll = '';
         return;
     }
     $objPoll = new \Poll($intPoll);
     $this->Template->poll = $objPoll->generate();
 }
开发者ID:hamidabbaszadeh,项目名称:contao-polls,代码行数:22,代码来源:ContentPoll.php

示例2: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     $time = time();
     $offset = 0;
     $limit = null;
     $arrPolls = array();
     $arrWhere = array();
     // Maximum number of items
     if ($this->numberOfItems > 0) {
         $limit = $this->numberOfItems;
     }
     // Build the criteria
     if ($this->poll_visible == 'yes') {
         $arrWhere[] = "(showStart='' OR showStart<{$time}) AND (showStop='' OR showStop>{$time})";
     } elseif ($this->poll_visible == 'no') {
         $arrWhere[] = "((showStart!='' AND showStart>={$time}) OR (showStop!='' AND showStop<={$time}))";
     }
     if ($this->poll_active == 'yes') {
         $arrWhere[] = "closed='' AND (activeStart='' OR activeStart<{$time}) AND (activeStop='' OR activeStop>{$time})";
     } elseif ($this->poll_active == 'no') {
         $arrWhere[] = "(closed=1 OR ((activeStart!='' AND activeStart>={$time}) OR (activeStop!='' AND activeStop<={$time})))";
     }
     if ($this->poll_featured == 'yes') {
         $arrWhere[] = "featured=1";
     } elseif ($this->poll_featured == 'no') {
         $arrWhere[] = "featured=''";
     }
     if (!BE_USER_LOGGED_IN) {
         $arrWhere[] = "published=1";
     }
     $total = $this->Database->execute("SELECT COUNT(*) AS total FROM tl_poll" . (!empty($arrWhere) ? " WHERE " . implode(" AND ", $arrWhere) : ""))->total;
     // Split the results
     if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) {
         // Adjust the overall limit
         if (isset($limit)) {
             $total = min($limit, $total);
         }
         // Get the current page
         $id = 'page_n' . $this->id;
         $page = \Input::get($id) ?: 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
             global $objPage;
             $objPage->noSearch = 1;
             $objPage->cache = 0;
             // Send a 404 header
             header('HTTP/1.1 404 Not Found');
             return;
         }
         // Set limit and offset
         $limit = $this->perPage;
         $offset = (max($page, 1) - 1) * $this->perPage;
         // Overall limit
         if ($offset + $limit > $total) {
             $limit = $total - $offset;
         }
         // Add the pagination menu
         $objPagination = new \Pagination($total, $this->perPage, 7, $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     $objPollsStmt = $this->Database->prepare("SELECT * FROM tl_poll" . (!empty($arrWhere) ? " WHERE " . implode(" AND ", $arrWhere) : "") . " ORDER BY closed ASC, showStart DESC, activeStart DESC");
     // Limit the result
     if (isset($limit)) {
         $objPollsStmt->limit($limit, $offset);
     }
     $objPolls = $objPollsStmt->execute();
     // Generate the polls
     while ($objPolls->next()) {
         $objPoll = new \Poll($objPolls->id);
         $arrPolls[] = $objPoll->generate();
     }
     $this->Template->polls = $arrPolls;
 }
开发者ID:hamidabbaszadeh,项目名称:contao-polls,代码行数:76,代码来源:ModulePollList.php


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