1 | <?php |
||
14 | class forum_poll extends block |
||
15 | { |
||
16 | /** @var \phpbb\db\driver\driver_interface */ |
||
17 | protected $db; |
||
18 | |||
19 | /** @var \blitze\sitemaker\services\forum\data */ |
||
20 | protected $forum_data; |
||
21 | |||
22 | /** @var \blitze\sitemaker\services\forum\options */ |
||
23 | protected $forum_options; |
||
24 | |||
25 | /** @var \blitze\sitemaker\services\groups */ |
||
26 | protected $groups; |
||
27 | |||
28 | /** @var \blitze\sitemaker\services\poll */ |
||
29 | protected $poll; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $settings; |
||
33 | |||
34 | const FORUMS_ORDER_FIRST_POST = 0; |
||
35 | const FORUMS_ORDER_LAST_POST = 1; |
||
36 | const FORUMS_ORDER_LAST_READ = 2; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
42 | * @param \blitze\sitemaker\services\forum\data $forum_data Forum Data object |
||
43 | * @param \blitze\sitemaker\services\forum\options $forum_options Forum Options Object |
||
44 | * @param \blitze\sitemaker\services\groups $groups Groups Object |
||
45 | * @param \blitze\sitemaker\services\poll $poll Poll Object |
||
46 | */ |
||
47 | 4 | public function __construct(\phpbb\db\driver\driver_interface $db, \blitze\sitemaker\services\forum\data $forum_data, \blitze\sitemaker\services\forum\options $forum_options, \blitze\sitemaker\services\groups $groups, \blitze\sitemaker\services\poll $poll) |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 1 | public function get_config(array $settings) |
|
60 | { |
||
61 | 1 | $forum_options = $this->forum_options->get_all(); |
|
62 | 1 | $group_options = $this->groups->get_data(); |
|
63 | 1 | $topic_type_options = array(POST_NORMAL => 'POST_NORMAL', POST_STICKY => 'POST_STICKY', POST_ANNOUNCE => 'POST_ANNOUNCEMENT', POST_GLOBAL => 'POST_GLOBAL'); |
|
64 | 1 | $sort_options = array('' => 'RANDOM', self::FORUMS_ORDER_FIRST_POST => 'FIRST_POST_TIME', self::FORUMS_ORDER_LAST_POST => 'LAST_POST_TIME', self::FORUMS_ORDER_LAST_READ => 'LAST_READ_TIME'); |
|
65 | |||
66 | return array( |
||
67 | 1 | 'legend1' => 'SETTINGS', |
|
68 | 1 | 'user_ids' => array('lang' => 'POLL_FROM_USERS', 'validate' => 'string', 'type' => 'textarea:3:40', 'maxlength' => 2, 'explain' => true, 'default' => ''), |
|
69 | 1 | 'group_ids' => array('lang' => 'POLL_FROM_GROUPS', 'validate' => 'string', 'type' => 'multi_select', 'options' => $group_options, 'default' => array(), 'explain' => true), |
|
70 | 1 | 'topic_ids' => array('lang' => 'POLL_FROM_TOPICS', 'validate' => 'string', 'type' => 'textarea:3:40', 'maxlength' => 2, 'explain' => true, 'default' => ''), |
|
71 | 1 | 'forum_ids' => array('lang' => 'POLL_FROM_FORUMS', 'validate' => 'string', 'type' => 'multi_select', 'options' => $forum_options, 'default' => array(), 'explain' => true), |
|
72 | 1 | 'topic_type' => array('lang' => 'TOPIC_TYPE', 'validate' => 'string', 'type' => 'checkbox', 'options' => $topic_type_options, 'default' => array(POST_NORMAL), 'explain' => false), |
|
73 | 1 | 'order_by' => array('lang' => 'ORDER_BY', 'validate' => 'string', 'type' => 'select', 'options' => $sort_options, 'default' => 0, 'explain' => false), |
|
74 | 1 | ); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 3 | public function display(array $bdata, $edit_mode = false) |
|
81 | { |
||
82 | 3 | $this->settings = $bdata['settings']; |
|
83 | 3 | $title = 'POLL'; |
|
84 | |||
85 | 3 | if (!($topic_data = $this->get_topic_data())) |
|
86 | 3 | { |
|
87 | return array( |
||
88 | 1 | 'title' => $title, |
|
89 | 1 | 'content' => '', |
|
90 | 1 | ); |
|
91 | } |
||
92 | |||
93 | 2 | $this->poll->build($topic_data, $this->ptemplate); |
|
94 | |||
95 | return array( |
||
96 | 2 | 'title' => $title, |
|
97 | 2 | 'content' => $this->ptemplate->render_view('blitze/sitemaker', 'blocks/forum_poll.html', 'forum_poll_block') |
|
98 | 2 | ); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * @return array|null |
||
103 | */ |
||
104 | 3 | private function get_topic_data() |
|
126 | |||
127 | /** |
||
128 | * @param array $sql_array |
||
129 | */ |
||
130 | 3 | private function limit_by_group(array &$sql_array) |
|
139 | |||
140 | /** |
||
141 | * @param string $string |
||
142 | * @return array |
||
143 | */ |
||
144 | 3 | private function get_array($string) |
|
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | 3 | private function get_sorting() |
|
162 | } |
||
163 |