11 | * @license LGPL
12 | */
13 |
14 | namespace Polls;
15 |
16 |
17 | /**
18 | * Front end module "poll list".
19 | */
20 | class ModulePollList extends \Module
21 | {
22 |
23 | /**
24 | * Template
25 | * @var string
26 | */
27 | protected $strTemplate = 'mod_polllist';
28 |
29 |
30 | /**
31 | * Display a wildcard in the back end
32 | * @return string
33 | */
34 | public function generate()
35 | {
36 | if (TL_MODE == 'BE')
37 | {
38 | $objTemplate = new \BackendTemplate('be_wildcard');
39 |
40 | $objTemplate->wildcard = '### POLL LIST ###';
41 | $objTemplate->title = $this->headline;
42 | $objTemplate->id = $this->id;
43 | $objTemplate->link = $this->name;
44 | $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
45 |
46 | return $objTemplate->parse();
47 | }
48 |
49 | return parent::generate();
50 | }
51 |
52 |
53 | /**
54 | * Generate the module
55 | */
56 | protected function compile()
57 | {
58 | $time = time();
59 | $offset = 0;
60 | $limit = null;
61 | $arrPolls = array();
62 | $arrWhere = array();
63 |
64 | // Maximum number of items
65 | if ($this->numberOfItems > 0)
66 | {
67 | $limit = $this->numberOfItems;
68 | }
69 |
70 | // Build the criteria
71 | if ($this->poll_visible == 'yes')
72 | {
73 | $arrWhere[] = "(showStart='' OR showStart<$time) AND (showStop='' OR showStop>$time)";
74 | }
75 | elseif ($this->poll_visible == 'no')
76 | {
77 | $arrWhere[] = "((showStart!='' AND showStart>=$time) OR (showStop!='' AND showStop<=$time))";
78 | }
79 | if ($this->poll_active == 'yes')
80 | {
81 | $arrWhere[] = "closed='' AND (activeStart='' OR activeStart<$time) AND (activeStop='' OR activeStop>$time)";
82 | }
83 | elseif ($this->poll_active == 'no')
84 | {
85 | $arrWhere[] = "(closed=1 OR ((activeStart!='' AND activeStart>=$time) OR (activeStop!='' AND activeStop<=$time)))";
86 | }
87 | if ($this->poll_featured == 'yes')
88 | {
89 | $arrWhere[] = "featured=1";
90 | }
91 | elseif ($this->poll_featured == 'no')
92 | {
93 | $arrWhere[] = "featured=''";
94 | }
95 | if (!BE_USER_LOGGED_IN)
96 | {
97 | $arrWhere[] = "published=1";
98 | }
99 |
100 | $total = $this->Database->execute("SELECT COUNT(*) AS total FROM tl_poll" . (!empty($arrWhere) ? " WHERE ".implode(" AND ", $arrWhere) : ""))->total;
101 |
102 | // Split the results
103 | if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage))
104 | {
105 | // Adjust the overall limit
106 | if (isset($limit))
107 | {
108 | $total = min($limit, $total);
109 | }
110 |
111 | // Get the current page
112 | $id = 'page_n' . $this->id;
113 | $page = \Input::get($id) ?: 1;
114 |
115 | // Do not index or cache the page if the page number is outside the range
116 | if ($page < 1 || $page > max(ceil($total/$this->perPage), 1))
117 | {
118 | global $objPage;
119 | $objPage->noSearch = 1;
120 | $objPage->cache = 0;
121 |
122 | // Send a 404 header
123 | header('HTTP/1.1 404 Not Found');
124 | return;
125 | }
126 |
127 | // Set limit and offset
128 | $limit = $this->perPage;
129 | $offset = (max($page, 1) - 1) * $this->perPage;
130 |
131 | // Overall limit
132 | if ($offset + $limit > $total)
133 | {
134 | $limit = $total - $offset;
135 | }
136 |
137 | // Add the pagination menu
138 | $objPagination = new \Pagination($total, $this->perPage, 7, $id);
139 | $this->Template->pagination = $objPagination->generate("\n ");
140 | }
141 |
142 | $objPollsStmt = $this->Database->prepare("SELECT * FROM tl_poll" . (!empty($arrWhere) ? " WHERE ".implode(" AND ", $arrWhere) : "") . " ORDER BY closed ASC, showStart DESC, activeStart DESC");
143 |
144 | // Limit the result
145 | if (isset($limit))
146 | {
147 | $objPollsStmt->limit($limit, $offset);
148 | }
149 |
150 | $objPolls = $objPollsStmt->execute();
151 |
152 | // Generate the polls
153 | while ($objPolls->next())
154 | {
155 | $objPoll = new \Poll($objPolls->id);
156 | $arrPolls[] = $objPoll->generate();
157 | }
158 |
159 | $this->Template->polls = $arrPolls;
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/templates/ce_poll.html5:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | poll; ?>
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/ce_poll.xhtml:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | poll; ?>
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/mod_poll.html5:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | poll; ?>
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/mod_poll.xhtml:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | poll; ?>
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/mod_polllist.html5:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | polls as $poll) echo $poll; ?>
9 | pagination; ?>
10 |
11 |
12 |
--------------------------------------------------------------------------------
/templates/mod_polllist.xhtml:
--------------------------------------------------------------------------------
1 |
2 | cssID; ?>style): ?> style="style; ?>">
3 | headline): ?>
4 |
5 | <hl; ?>>headline; ?>hl; ?>>
6 |
7 |
8 | polls as $poll) echo $poll; ?>
9 | pagination; ?>
10 |
11 |
12 |
--------------------------------------------------------------------------------
/templates/poll_default.html5:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
title; ?>
6 | message): ?>
7 |
message; ?>
8 |
9 | showResults): ?>
10 |
11 |
12 |
13 | results as $i => $result): ?>
14 | % -
15 |
16 |
17 | formLink; ?>
18 |
19 |
20 | showForm): ?>
21 |
22 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/templates/poll_default.xhtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
title; ?>
6 | message): ?>
7 |
message; ?>
8 |
9 | showResults): ?>
10 |
11 |
12 |
13 | results as $i => $result): ?>
14 | % -
15 |
16 |
17 | formLink; ?>
18 |
19 |
20 | showForm): ?>
21 |
22 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------