Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgrade to Moodle 2

  • Loading branch information...
commit cab4c9fbe4283bfe1bc32bf43b371fb204f93f4f 1 parent a189fc8
@aolley aolley authored
View
2  README
@@ -30,4 +30,4 @@
Poll Block for Moodle
-Updated by NetSpot Pty Ltd for Moodle 1.9
+Updated by NetSpot Pty Ltd for Moodle 2.x
View
72 block_poll.php
@@ -1,10 +1,21 @@
<?php
-// Paul Holden 24th July, 2007
-// this file contains the poll block class
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once("$CFG->dirroot/blocks/poll/lib.php");
-require_once($CFG->dirroot.'/my/pagelib.php');
class block_poll extends block_base {
@@ -28,33 +39,45 @@ function specialization() {
}
function poll_can_edit() {
- if ($this->instance->pagetype == PAGE_MY_MOODLE) {
- return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
- }
-
- return isteacher($this->instance->pageid);
+ return has_capability('block/poll:editpoll', $this->context);
}
function poll_user_eligible() {
+ global $COURSE, $USER;
+
+ $parents = get_parent_contexts($this->context);
+ $parentctx = get_context_instance_by_id($parents[0]);
+
+ $switched = false;
+ if ($this->poll->eligible == 'students') {
+ $switched = is_role_switched($COURSE->id);
+ if (isset($USER->access['rsw'][$parentctx->path])) {
+ $switched = $switched && !role_context_capabilities($USER->access['rsw'][$parentctx->path], $this->context, 'block/poll:editpoll');
+ } else {
+ $switched = false;
+ }
+ }
// TODO: Proper roles & capabilities
return ($this->poll->eligible == 'all') ||
- (($this->poll->eligible == 'students') && isstudent($this->instance->pageid)) ||
- (($this->poll->eligible == 'teachers') && poll_can_edit());
+ (($this->poll->eligible == 'students') && !$this->poll_can_edit()) ||
+ ($switched) ||
+ (($this->poll->eligible == 'teachers') && $this->poll_can_edit());
}
function poll_results_link() {
- global $USER;
- $page = page_create_object($this->instance->pagetype, $this->instance->pageid);
- $url = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey, 'blockaction' => 'config', 'action' => 'responses', 'pid' => $this->poll->id));
- return "<hr />(<a href=\"$url\">" . get_string('responses', 'block_poll') . '</a>)';
+ $url = new moodle_url('/blocks/poll/tabs.php', array('action' => 'responses', 'pid' => $this->poll->id, 'instanceid' => $this->instance->id));
+ $html = html_writer::empty_tag('hr');
+ $html .= html_writer::link($url, get_string('responses', 'block_poll'));
+ return $html;
}
function poll_print_options() {
- global $CFG;
+ global $CFG, $COURSE;
+ //TODO: Renderer/html_writer-ify
$this->content->text .= '<form method="get" action="' . $CFG->wwwroot . '/blocks/poll/poll_action.php">
<input type="hidden" name="action" value="respond" />
<input type="hidden" name="pid" value="' . $this->poll->id . '" />
- <input type="hidden" name="id" value="' . $this->instance->pageid . '" />';
+ <input type="hidden" name="id" value="' . $COURSE->id . '" />';
foreach ($this->options as $option) {
$this->content->text .= "<tr><td><input type=\"radio\" id=\"r_$option->id\" name=\"rid\" value=\"$option->id\" />
<label for=\"r_$option->id\">$option->optiontext</label></td></tr>";
@@ -63,8 +86,9 @@ function poll_print_options() {
}
function poll_get_results(&$results, $sort = true) {
+ global $DB;
foreach ($this->options as $option) {
- $responses = get_records('block_poll_response', 'optionid', $option->id);
+ $responses = $DB->get_records('block_poll_response', array('optionid' => $option->id));
$results[$option->optiontext] = (!$responses ? '0' : count($responses));
}
if ($sort) { poll_sort_results($results); }
@@ -75,6 +99,7 @@ function poll_print_results() {
foreach ($results as $option => $count) {
$img = ((isset($img) && $img == 0) ? 1 : 0);
$highest = ((!isset($highest) || !$highest) ? $count : $highest);
+ $highest = ($highest == 0) ? 150 : $highest; //default to 150px, prevent division by zero
$imgwidth = round($this->config->maxwidth / $highest * $count);
$imgwidth = ($imgwidth == 0 ? 1 : $imgwidth);
$this->content->text .= "<tr><td>$option ($count)<br />" . poll_get_graphbar($img, $imgwidth) . '</td></tr>';
@@ -82,28 +107,29 @@ function poll_print_results() {
}
function get_content() {
- global $USER;
+ global $DB, $USER;
if ($this->content !== null) {
return $this->content;
}
if(!isset($this->config->pollid) || !is_numeric($this->config->pollid))
{
- $this->content = new stdClass;
+ $this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
return $this->content;
}
- $this->poll = get_record('block_poll', 'id', $this->config->pollid);
+ $this->poll = $DB->get_record('block_poll', array('id' => $this->config->pollid));
- $this->options = get_records('block_poll_option', 'pollid', $this->poll->id);
+ $this->options = $DB->get_records('block_poll_option', array('pollid' => $this->poll->id));
- $this->content = new stdClass;
+ //TODO: html_table
+ $this->content = new stdClass();
$this->content->text = '<table cellspacing="2" cellpadding="2">';
$this->content->text .= '<tr><th>' . $this->poll->questiontext . '</th></tr>';
- $response = get_record('block_poll_response', 'pollid', $this->poll->id, 'userid', $USER->id);
+ $response = $DB->get_record('block_poll_response', array('pollid' => $this->poll->id, 'userid' => $USER->id));
$func = 'poll_print_' . (!$response && $this->poll_user_eligible() ? 'options' : 'results');
$this->$func();
View
15 db/access.php
@@ -0,0 +1,15 @@
+<?php
+
+$capabilities = array(
+
+ 'block/poll:editpoll' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_BLOCK,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ )
+ ),
+
+);
View
30 db/install.xml
@@ -7,13 +7,13 @@
<TABLE NAME="block_poll" COMMENT="Contains polls for the poll block" NEXT="block_poll_option">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
- <FIELD NAME="name" TYPE="char" LENGTH="64" NOTNULL="true" DEFAULT="" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="courseid"/>
- <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="questiontext"/>
- <FIELD NAME="questiontext" TYPE="text" LENGTH="big" NOTNULL="true" DEFAULT="" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="eligible"/>
- <FIELD NAME="eligible" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="all" SEQUENCE="false" ENUM="true" ENUMVALUES="'all', 'students', 'teachers'" PREVIOUS="questiontext" NEXT="created"/>
- <FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="eligible" NEXT="anonymous"/>
- <FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="created"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="courseid"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="name" NEXT="questiontext"/>
+ <FIELD NAME="questiontext" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" PREVIOUS="courseid" NEXT="eligible"/>
+ <FIELD NAME="eligible" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="all" SEQUENCE="false" PREVIOUS="questiontext" NEXT="created"/>
+ <FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="eligible" NEXT="anonymous"/>
+ <FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="created"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
@@ -22,9 +22,9 @@
<TABLE NAME="block_poll_option" COMMENT="Contains options for each poll in the poll block" NEXT="block_poll_response" PREVIOUS="block_poll">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="pollid"/>
- <FIELD NAME="pollid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="optiontext"/>
- <FIELD NAME="optiontext" TYPE="text" LENGTH="big" NOTNULL="true" DEFAULT="" SEQUENCE="false" ENUM="false" PREVIOUS="pollid"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="pollid"/>
+ <FIELD NAME="pollid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="optiontext"/>
+ <FIELD NAME="optiontext" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" PREVIOUS="pollid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
@@ -33,11 +33,11 @@
<TABLE NAME="block_poll_response" COMMENT="Contains response info for each poll in the poll block" PREVIOUS="block_poll_option">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="pollid"/>
- <FIELD NAME="pollid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="optionid"/>
- <FIELD NAME="optionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="pollid" NEXT="userid"/>
- <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="optionid" NEXT="submitted"/>
- <FIELD NAME="submitted" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="userid"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="pollid"/>
+ <FIELD NAME="pollid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="optionid"/>
+ <FIELD NAME="optionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="pollid" NEXT="userid"/>
+ <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="optionid" NEXT="submitted"/>
+ <FIELD NAME="submitted" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
View
40 db/upgrade.php
@@ -1,4 +1,19 @@
-<?php //$Id$
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file keeps track of upgrades to
// the poll block
@@ -17,20 +32,19 @@
// The commands in here will all be database-neutral,
// using the functions defined in lib/ddllib.php
-function xmldb_block_poll_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $db;
-
- $result = true;
+function xmldb_block_poll_upgrade($oldversion) {
+ global $DB;
+ $dbman = $DB->get_manager();
/// Add a new column for anonymous polls
- if ($result && $oldversion < 2011041400) {
- $table = new XMLDBTable('block_poll');
- $field = new XMLDBField('anonymous');
- $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'anonymous');
-
- $result = $result && add_field($table, $field);
+ if ($oldversion < 2011041400) {
+ $table = new xmldb_table('block_poll');
+ $field = new xmldb_field('anonymous');
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'anonymous');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
}
- return $result;
+ return true;
}
View
46 edit_form.php
@@ -0,0 +1,46 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+class block_poll_edit_form extends block_edit_form {
+ protected function specific_definition($mform) {
+ global $COURSE, $DB;
+ // Fields for editing poll block title and contents.
+ $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
+
+ $mform->addElement('text', 'config_customtitle', get_string('configtitle', 'block_html'));
+ $mform->setType('config_customtitle', PARAM_MULTILANG);
+
+ if ($polls = $DB->get_records('block_poll', array('courseid' => $COURSE->id), '', 'id, name')) {
+ $list = array(0 => get_string('choose', 'block_poll'));
+ foreach ($polls as $poll) {
+ $list[$poll->id] = $poll->name;
+ }
+ $mform->addElement('select', 'config_pollid', get_string('editpollname', 'block_poll'), $list);
+ } else {
+ $mform->addElement('static', 'nopolls', get_string('editpollname', 'block_poll'), get_string('nopollsavailable', 'block_poll'));
+ }
+
+ $mform->addElement('text', 'config_maxwidth', get_string('editmaxbarwidth', 'block_poll'));
+
+ $tabs = array('editpoll', 'managepolls', 'responses');
+ foreach ($tabs as $tab) {
+ $params = array('action' => $tab, 'cid' => $COURSE->id, 'instanceid' => $this->block->instance->id);
+ $link = html_writer::link(new moodle_url('/blocks/poll/tabs.php', $params), get_string("tab$tab", 'block_poll'));
+ $mform->addElement('static', "linki_$tab", '', $link);
+ }
+ }
+}
View
26 lang/en/block_poll.php
@@ -0,0 +1,26 @@
+<?php
+$string['choose'] = 'Choose...';
+$string['config_param'] = 'Parameter';
+$string['config_value'] = 'Value';
+$string['editanonymousresponses'] = 'Anonymous';
+$string['edit:poll'] = 'Can edit poll blocks';
+$string['editblocktitle'] = 'Block title';
+$string['editmaxbarwidth'] = 'Maximum graph width';
+$string['editpollname'] = 'Poll name';
+$string['editpollquestion'] = 'Question text';
+$string['editpolleligible'] = 'Eligible users';
+$string['editpolloptions'] = 'Option count';
+$string['formaltitle'] = 'Poll';
+$string['nopollsavailable'] = 'No polls are currently available, select the create/edit poll link below to create one.';
+$string['option'] = 'Option';
+$string['pluginname'] = 'Poll';
+$string['poll:editpoll'] = 'Edit and Manage Polls';
+$string['pollconfirmdelete'] = 'Are you sure you want to completely delete this poll ($a), including all response data?';
+$string['pollwarning'] = 'You must be a teacher to perform this action';
+$string['responses'] = 'Responses';
+$string['submit'] = 'Submit';
+$string['tabconfigblock'] = 'Configure Block';
+$string['tabeditpoll'] = 'Create/Edit Poll';
+$string['tabmanagepolls'] = 'Manage Polls';
+$string['tabresponses'] = 'View Responses';
+$string['useranonymous'] = 'Anonymous';
View
22 lib.php
@@ -1,7 +1,19 @@
<?php
-// Paul Holden 24th July, 2007
-// various poll library functions
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
function poll_sort_callback($a, $b) {
return ($a == $b ? 0 : ($a > $b ? -1 : 1));
@@ -12,6 +24,8 @@ function poll_sort_results(&$options, $callback = 'poll_sort_callback') {
}
function poll_get_graphbar($img = '0', $width = '100') {
- global $CFG;
- return "<img src=\"$CFG->wwwroot/blocks/poll/img/graph$img.gif\" height=\"15\" width=\"$width\" border=\"1\" /><br />";
+ global $CFG, $OUTPUT;
+ $html = $OUTPUT->pix_icon("graph$img", '', 'block_poll', array('style' => "width: {$width}px; height: 15px;"));
+ $html .= html_writer::empty_tag('br');
+ return $html;
}
View
33 module.js
@@ -0,0 +1,33 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+M.block_poll = {};
+
+M.block_poll.show_poll = function(Y, action, pid) {
+ Y.use('yui2-treeview', function(Y) {
+ var tree = new YAHOO.widget.TreeView(htmlid);
+
+ tree.subscribe("clickEvent", function(node, event) {
+ // we want normal clicking which redirects to url
+ return false;
+ });
+
+ if (expand_all) {
+ tree.expandAll();
+ }
+
+ tree.render();
+ });
+};
View
BIN  pix/graph0.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  pix/graph1.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
122 poll_action.php
@@ -1,36 +1,47 @@
<?php
-// Paul Holden 24th July, 2007
-// contains the code that controls polls and responses
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
-require_once($CFG->dirroot.'/my/pagelib.php');
+
global $PAGE;
$action = required_param('action', PARAM_ALPHA);
$pid = optional_param('pid', 0, PARAM_INTEGER);
$cid = required_param('id', PARAM_INTEGER);
$srcpage = optional_param('page', '', PARAM_TEXT);
-if ($cid == 0) $cid = 1;
+if ($cid == 0) {
+ if (!$cid = optional_param('course', 0, PARAM_INT)) {
+ $cid = 1;
+ }
+}
$instanceid = optional_param('instanceid', 0, PARAM_INTEGER);
$sesskey = $USER->sesskey;
-if ($PAGE->body_id == 'admin-stickyblocks' || $srcpage == 'admin-stickyblocks') {
- $mymoodleref = true;
- $stickyblocksref = true;
-} else {
- $mymoodleref = strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/my/') !== FALSE || strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/admin/stickyblocks.php') !== FALSE;
- $stickyblocksref = strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/admin/stickyblocks.php') !== FALSE;
-}
+$mymoodleref = strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/my/') !== FALSE || strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/admin/stickyblocks.php') !== FALSE;
+$stickyblocksref = strpos($_SERVER["HTTP_REFERER"], $CFG->wwwroot.'/my/indexsys.php') !== FALSE;
-function test_allowed_to_update() {
- // TODO: Proper roles & capabilities
- global $cid, $mymoodleref;
+function test_allowed_to_update($cid = 0) {
+ global $COURSE;
+ $cid = $cid == 0 ? $COURSE->id : $cid;
+ $context = get_context_instance(CONTEXT_COURSE, $cid);
- if ($mymoodleref && has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM))) {
- return;
- }
-
- if ($mymoodleref || !isteacher($cid)) {
- error(get_string('pollwarning', 'block_poll'));
+ if (has_capability('block/poll:editpoll', $context)) {
+ return true;
+ } else {
+ print_error(get_string('pollwarning', 'block_poll'));
}
}
@@ -42,10 +53,15 @@ function test_allowed_to_update() {
$url = $CFG->wwwroot.'/course/view.php?id='.$cid;
}
+$tabs = array('create', 'delete', 'edit');
+if (in_array($action, $tabs)) {
+ $url = $CFG->wwwroot.'/blocks/poll/tabs.php?';
+}
+
switch ($action) {
case 'create':
- test_allowed_to_update();
- $poll = new Object();
+ test_allowed_to_update($cid);
+ $poll = new stdClass();
$poll->id = $pid;
$poll->name = required_param('name', PARAM_TEXT);
$poll->courseid = $cid;
@@ -53,80 +69,88 @@ function test_allowed_to_update() {
$poll->eligible = required_param('eligible', PARAM_ALPHA);
$poll->created = time();
$poll->anonymous = optional_param('anonymous', 0, PARAM_INTEGER);
- $newid = insert_record('block_poll', $poll, true);
+ $newid = $DB->insert_record('block_poll', $poll, true);
$optioncount = optional_param('optioncount', 0, PARAM_INTEGER);
for ($i = 0; $i < $optioncount; $i++) {
- $pollopt = new Object();
+ $pollopt = new stdClass();
$pollopt->id = 0;
$pollopt->pollid = $newid;
$pollopt->optiontext = '';
- insert_record('block_poll_option', $pollopt);
+ $DB->insert_record('block_poll_option', $pollopt);
}
- $url .= "&amp;instanceid=$instanceid&amp;sesskey=$sesskey&amp;blockaction=config&amp;action=editpoll&amp;pid=$newid";
+ $url .= "&instanceid=$instanceid&sesskey=$sesskey&blockaction=config&action=editpoll&pid=$newid";
break;
case 'edit':
- test_allowed_to_update();
- $poll = get_record('block_poll', 'id', $pid);
+ test_allowed_to_update($cid);
+ $poll = $DB->get_record('block_poll', array('id' => $pid));
$poll->name = required_param('name', PARAM_TEXT);
$poll->questiontext = required_param('questiontext', PARAM_TEXT);
$poll->eligible = required_param('eligible', PARAM_ALPHA);
if ($poll->anonymous == 0) { //only allow one way setting of anonymous
$poll->anonymous = optional_param('anonymous', 0, PARAM_INTEGER);
}
- update_record('block_poll', $poll);
+ $DB->update_record('block_poll', $poll);
$options = optional_param('options', array(), PARAM_RAW);
foreach (array_keys($options) as $option) {
- $pollopt = get_record('block_poll_option', 'id', $option);
+ $pollopt = $DB->get_record('block_poll_option', array('id' => $option));
$pollopt->optiontext = $options[$option];
- update_record('block_poll_option', $pollopt);
+ $DB->update_record('block_poll_option', $pollopt);
}
$optioncount = optional_param('optioncount', 0, PARAM_INTEGER);
if (count($options) > $optioncount) {
$temp = 1;
foreach ($options as $optid => $optname) {
- if ($temp++ > $optioncount) break;
+ if ($temp++ > $optioncount) {
+ break;
+ }
$safe[] = $optid;
}
- delete_records_select('block_poll_option', "pollid = $pid AND id NOT IN (" . implode($safe, ',') . ")");
+
+ list($insql, $params) = $DB->get_in_or_equal($safe, SQL_PARAMS_NAMED);
+ $insql = count($params) > 1 ? "NOT $insql" : "!$insql";
+ $params['pid'] = $pid;
+ $DB->delete_records_select('block_poll_option', "pollid = :pid AND id $insql", $params);
}
for ($i = count($options); $i < $optioncount; $i++) {
- $pollopt = new Object();
+ $pollopt = new stdClass();
$pollopt->id = 0;
$pollopt->pollid = $pid;
$pollopt->optiontext = '';
- insert_record('block_poll_option', $pollopt);
+ $DB->insert_record('block_poll_option', $pollopt);
}
- $url .= "&amp;instanceid=$instanceid&amp;sesskey=$sesskey&amp;blockaction=config&amp;action=editpoll&amp;pid=$pid";
+ $url .= "&instanceid=$instanceid&sesskey=$sesskey&blockaction=config&action=editpoll&pid=$pid";
break;
case 'delete':
- test_allowed_to_update();
+ test_allowed_to_update($cid);
$step = optional_param('step', 'first', PARAM_TEXT);
- $urlno = $url . "&amp;instanceid=$instanceid&amp;sesskey=$sesskey&amp;blockaction=config&amp;action=managepolls";
+ $urlno = $url . "&instanceid=$instanceid&sesskey=$sesskey&blockaction=config&action=managepolls";
if ($step == 'confirm') {
- delete_records('block_poll', 'id', $pid);
- delete_records('block_poll_option', 'pollid', $pid);
- delete_records('block_poll_response', 'pollid', $pid);
+ $DB->delete_records('block_poll', array('id' => $pid));
+ $DB->delete_records('block_poll_option', array('pollid' => $pid));
+ $DB->delete_records('block_poll_response', array('pollid' => $pid));
$url = $urlno;
} else {
- $poll = get_record('block_poll', 'id', $pid);
- $suffix = $srcpage != '' ? "&amp;page=$srcpage" : '';
- $urlyes = "$CFG->wwwroot/blocks/poll/poll_action.php?id=$cid&amp;instanceid=$instanceid&amp;action=delete&amp;step=confirm&amp;pid=$pid$suffix";
+ $poll = $DB->get_record('block_poll', array('id' => $pid));
+ $yesparams = array('id' => $cid, 'instanceid' => $instanceid, 'action' => 'delete', 'step' => 'confirm', 'pid' => $pid);
+ if ($srcpage != '') {
+ $yesparams['page'] = $srcpage;
+ }
+ $urlyes = new moodle_url('/blocks/poll/poll_action.php', $yesparams);
notice_yesno(get_string('pollconfirmdelete', 'block_poll', $poll->name), $urlyes, $urlno);
- die();
+ exit;
}
break;
case 'respond':
- if (!get_record('block_poll_response', 'pollid', $pid, 'userid', $USER->id)) {
- $response = new Object();
+ if (!$DB->get_record('block_poll_response', array('pollid' => $pid, 'userid' => $USER->id))) {
+ $response = new stdClass();
$response->id = 0;
$response->pollid = $pid;
$response->optionid = required_param('rid', PARAM_INTEGER);
$response->userid = $USER->id;
$response->submitted = time();
- insert_record('block_poll_response', $response);
+ $DB->insert_record('block_poll_response', $response);
}
break;
}
redirect($url);
-?>
View
8 styles.css
@@ -0,0 +1,8 @@
+#page-blocks-poll-tabs .singleselect {
+ text-align: left;
+ margin: 0;
+}
+
+#page-blocks-poll-tabs .field_title {
+ float: left;
+}
View
146 tab_editpoll.php
@@ -1,78 +1,98 @@
-<script language="javascript" type="text/javascript">
-function show_poll_results(id) {
- window.location.href="<?php echo(str_replace('&amp;', '&', $url) . 'editpoll&pid='); ?>" + id;
-}
-</script>
-
<?php
- // Paul Holden 24th July, 2007
- // poll block; poll creating/editing tab
- $id = optional_param('id', 0, PARAM_INTEGER);
- $pid = optional_param('pid', 0, PARAM_INTEGER);
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
- $polls = get_records('block_poll', 'courseid', $COURSE->id);
- if($polls !== false)
- {
- foreach ($polls as $poll) {
- $menu[$poll->id] = $poll->name;
- }
- }
+defined('MOODLE_INTERNAL') || exit;
- print_simple_box_start();
- echo(get_string('editpollname', 'block_poll') . ': ');
- choose_from_menu((isset($menu) && !empty($menu) ? $menu : null), 'pid', $pid, 'choose', 'show_poll_results(this.options[this.selectedIndex].value);');
- print_simple_box_end();
+/*echo '<script language="javascript" type="text/javascript">
+function show_poll_results(id) {
+ window.location.href="'.(str_replace('&amp;', '&', $url) . 'editpoll&pid=').' + id;
+}
+</script>';*/
- $poll = get_record('block_poll', 'id', $pid);
- $poll_options = get_records('block_poll_option', 'pollid', $pid);
- $poll_option_count = (!$poll_options ? 0 : count($poll_options));
+$PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('movecourses', 'movetoid', false));
-?>
-</form>
+$id = optional_param('id', 0, PARAM_INTEGER);
+$pid = optional_param('pid', 0, PARAM_INTEGER);
+
+$polls = $DB->get_records('block_poll', array('courseid' => $cid));
+$menu = array();
+if($polls !== false)
+{
+ foreach ($polls as $poll) {
+ $menu[$poll->id] = $poll->name;
+ }
+}
+//TODO: Renderify
+echo $OUTPUT->box_start();
+echo html_writer::start_tag('form', array('action' => '#', 'method' => 'get', 'id' => 'pollselect_form'));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'cid', 'value' => $cid));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'instanceid', 'value' => $instanceid));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'editpoll'));
+echo get_string('editpollname', 'block_poll').': ';
+echo html_writer::select($menu, 'pid', $pid, array('' => 'choosedots'), array('id' => 'pid'));
+echo html_writer::end_tag('form');
+$PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('pollselect_form', 'pid', false));
+echo $OUTPUT->box_end();
-<form method="get" action="<?php echo($CFG->wwwroot); ?>/blocks/poll/poll_action.php">
-<input type="hidden" name="pid" value="<?php echo($pid); ?>" />
-<input type="hidden" name="action" value="<?php echo($pid == 0 ? 'create' : 'edit'); ?>" />
-<input type="hidden" name="instanceid" value="<?php echo($this->instance->id) ;?>" />
-<input type="hidden" name="id" value="<?php echo($id) ;?>" />
-<input type="hidden" name="sesskey" value="<?php echo($USER->sesskey) ;?>" />
-<input type="hidden" name="blockaction" value="config" />
-<input type="hidden" name="course" value="<?php echo($COURSE->id); ?>" />
+$poll = $DB->get_record('block_poll', array('id' => $pid));
+$poll_options = $DB->get_records('block_poll_option', array('pollid' => $pid));
+$poll_option_count = (!$poll_options ? 0 : count($poll_options));
-<?php
+echo html_writer::start_tag('form', array('method' => "post", 'action' => $CFG->wwwroot.'/blocks/poll/poll_action.php'));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pid', 'value' => $pid));
+$action = $pid == 0 ? 'create' : 'edit';
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => $action));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'instanceid', 'value' => $instanceid));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $id));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'blockaction', 'value' => 'config'));
+echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'course', 'value' => $COURSE->id));
- $eligible = array('all' => get_string('all'), 'students' => get_string('students'), 'teachers' => get_string('teachers'));
- for ($i = 1; $i <= 10; $options[$i++] = ($i - 1)) {}
+$eligible = array('all' => get_string('all'), 'students' => get_string('students'), 'teachers' => get_string('teachers'));
+for ($i = 1; $i <= 10; $options[$i++] = ($i - 1)) {}
- $table = new Object();
- $table->head = array(get_string('config_param', 'block_poll'), get_string('config_value', 'block_poll'));
- $table->tablealign = 'left';
- $table->width = '*';
+$table = new html_table();
+$table->head = array(get_string('config_param', 'block_poll'), get_string('config_value', 'block_poll'));
+$table->tablealign = 'left';
+$table->width = '*';
- $stranonresp = get_string('editanonymousresponses', 'block_poll');
- $anoncheck = isset($poll->anonymous) && $poll->anonymous == 1 ? 'checked="checked" disabled="disabled"' : '';
+$stranonresp = get_string('editanonymousresponses', 'block_poll');
+$anoncheck = isset($poll->anonymous) && $poll->anonymous == 1 ? 'checked="checked" disabled="disabled"' : '';
- $table->data[] = array(get_string('editpollname', 'block_poll'), '<input type="text" name="name" value="' . ((!isset($poll) || !$poll) ? '' : $poll->name) . '" />');
- $table->data[] = array(get_string('editpollquestion', 'block_poll'), '<input type="text" name="questiontext" value="' . (!$poll ? '' : $poll->questiontext) . '" />');
- $table->data[] = array($stranonresp, '<input type="checkbox" name="anonymous" alt="'.$stranonresp.'" value="1" '.$anoncheck.' />');
- $table->data[] = array(get_string('editpolleligible', 'block_poll'), choose_from_menu($eligible, 'eligible', (isset($poll->eligible) ? $poll->eligible : null), 'choose', '', 0, true));
- $table->data[] = array(get_string('editpolloptions', 'block_poll'), choose_from_menu($options, 'optioncount', $poll_option_count, 'choose', '', 0, true));
+$table->data[] = array(get_string('editpollname', 'block_poll'), '<input type="text" name="name" value="' . ((!isset($poll) || !$poll) ? '' : $poll->name) . '" />');
+$table->data[] = array(get_string('editpollquestion', 'block_poll'), '<input type="text" name="questiontext" value="' . (!$poll ? '' : $poll->questiontext) . '" />');
+$table->data[] = array($stranonresp, '<input type="checkbox" name="anonymous" alt="'.$stranonresp.'" value="1" '.$anoncheck.' />');
+$selected = isset($poll->eligible) ? $poll->eligible : null;
+$table->data[] = array(get_string('editpolleligible', 'block_poll'), html_writer::select($eligible, 'eligible', $selected));
+$table->data[] = array(get_string('editpolloptions', 'block_poll'), html_writer::select($options, 'optioncount', $poll_option_count));
- $option_count = 0;
- if(is_array($poll_options))
- {
- foreach ($poll_options as $option) {
- $option_count++;
- $table->data[] = array(get_string('option', 'block_poll') . " $option_count", "<input type=\"text\" name=\"options[$option->id]\" value=\"$option->optiontext\" />");
- }
- }
- for ($i = $option_count + 1; $i <= $poll_option_count; $i++) {
- $table->data[] = array(get_string('option', 'block_poll') . " $i", '<input type="text" name="newoptions[]" />');
- }
+$option_count = 0;
+if(is_array($poll_options))
+{
+foreach ($poll_options as $option) {
+ $option_count++;
+ $table->data[] = array(get_string('option', 'block_poll') . " $option_count", "<input type=\"text\" name=\"options[$option->id]\" value=\"$option->optiontext\" />");
+}
+}
+for ($i = $option_count + 1; $i <= $poll_option_count; $i++) {
+ $table->data[] = array(get_string('option', 'block_poll') . " $i", '<input type="text" name="newoptions[]" />');
+}
- $table->data[] = array('&nbsp;', '<input type="submit" value="' . get_string('savechanges') . '" />');
+$table->data[] = array('&nbsp;', '<input type="submit" value="' . get_string('savechanges') . '" />');
- print_table($table);
-?>
-</form>
+echo html_writer::table($table);
+echo html_writer::end_tag('form');
View
51 tab_managepolls.php
@@ -1,19 +1,33 @@
<?php
-// Paul Holden 24th July, 2007
-// poll block; poll management tab
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
function print_action($action, $url) {
- global $CFG;
- return "<a href=\"$url\"><img src=\"$CFG->pixpath/t/$action.gif\" alt=\"\" /></a> ";
+ global $OUTPUT;
+ return html_writer::link($url, $OUTPUT->pix_icon("t/$action", "$action"));
}
$edit = get_string('edit');
$delete = get_string('delete');
$view = get_string('view');
-$polls = get_records('block_poll', 'courseid', $COURSE->id);
+$polls = $DB->get_records('block_poll', array('courseid' => $COURSE->id));
-$table = new Object();
+//TODO: Use html_table
+$table = new html_table();
$table->head = array(get_string('editpollname', 'block_poll'),
get_string('editpolloptions', 'block_poll'),
get_string('responses', 'block_poll'),
@@ -22,19 +36,22 @@ function print_action($action, $url) {
$table->tablealign = 'left';
$table->width = '*';
-global $PAGE;
-$suffix = $PAGE->body_id == 'admin-stickyblocks' ? '&amp;page=admin-stickyblocks' : '';
-if($polls !== false)
-{
+if ($polls !== false) {
foreach ($polls as $poll) {
- $options = get_records('block_poll_option', 'pollid', $poll->id);
- $responses = get_records('block_poll_response', 'pollid', $poll->id);
- $action = print_action('preview', "{$url}responses&amp;pid=$poll->id") .
- print_action('edit', "{$url}editpoll&amp;pid=$poll->id") .
- print_action('delete', "$CFG->wwwroot/blocks/poll/poll_action.php?id=$COURSE->id&amp;instanceid=" . $this->instance->id . "&amp;action=delete&amp;pid=$poll->id$suffix");
+ $options = $DB->get_records('block_poll_option', array('pollid' => $poll->id));
+ $responses = $DB->get_records('block_poll_response', array('pollid' => $poll->id));
+
+ $url_preview = clone $url;
+ $url_preview->params(array('action' => 'responses', 'pid' => $poll->id));
+ $url_edit = clone $url;
+ $url_edit->params(array('action' => 'editpoll', 'pid' => $poll->id));
+ $url_delete = new moodle_url('/blocks/poll/poll_action.php', array('action' => 'delete', 'id' => $cid, 'pid' => $poll->id, 'instanceid' => $instanceid));
+
+ $action = print_action('preview', $url_preview) .
+ print_action('edit', $url_edit) .
+ print_action('delete', $url_delete);
$table->data[] = array($poll->name, (!$options ? '0' : count($options)), (!$responses ? '0' : count($responses)), $action);
}
}
-print_table($table);
-?>
+echo html_writer::table($table);
View
67 tab_responses.php
@@ -1,12 +1,19 @@
-<script language="javascript" type="text/javascript">
-function show_poll_results(id) {
- window.location.href="<?php echo(str_replace('&amp;', '&', $url) . 'responses&pid='); ?>" + id;
-}
-</script>
-
<?php
-// Paul Holden 24th July, 2007
-// poll block; view poll responses tab
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
$pid = optional_param('pid', 0, PARAM_INTEGER);
@@ -16,45 +23,45 @@ function poll_custom_callback($a, $b) {
return ($counta == $countb ? 0 : ($counta > $countb ? -1 : 1));
}
-function get_response_checks($options, $selected) {
+function block_poll_get_response_checks($options, $selected) {
foreach ($options as $option) {
- $arr[] = '<input type="checkbox" onclick="this.checked=' . ($option->id == $selected ? 'true" checked' : 'false"') . ' />';
+ $arr[] = html_writer::checkbox('', '', $option->id == $selected, '', array('onclick' => 'this.checked='.($option->id == $selected ? 'true' : 'false')));
}
return $arr;
}
-$polls = get_records('block_poll', 'courseid', $COURSE->id);
+$polls = $DB->get_records('block_poll', array('courseid' => $cid));
if($polls !== false) {
foreach ($polls as $poll) {
$menu[$poll->id] = $poll->name;
}
}
-print_simple_box_start();
-echo(get_string('editpollname', 'block_poll') . ': ');
-choose_from_menu( (isset($menu) && !empty($menu) ? $menu : null), 'pid', $pid, 'choose', 'show_poll_results(this.options[this.selectedIndex].value);');
-print_simple_box_end();
+echo $OUTPUT->box_start();
+echo html_writer::tag('div', get_string('editpollname', 'block_poll') . ': ', array('class' => 'field_title'));
+echo $OUTPUT->single_select($url, 'pid', $menu, $pid);
+echo $OUTPUT->box_end();
-if (($poll = get_record('block_poll', 'id', $pid)) && ($options = get_records('block_poll_option', 'pollid', $poll->id))) {
+if (($poll = $DB->get_record('block_poll', array('id' => $pid))) && ($options = $DB->get_records('block_poll_option', array('pollid' => $poll->id)))) {
foreach ($options as $option) {
- $option->responses = get_records('block_poll_response', 'optionid', $option->id);
+ $option->responses = $DB->get_records('block_poll_response', array('optionid' => $option->id));
$option->responsecount = (!$option->responses ? 0 : count($option->responses));
}
poll_sort_results($options, 'poll_custom_callback');
- print_simple_box_start();
+ echo $OUTPUT->box_start();
echo("<div style=\"text-align:left;\"><strong>$poll->questiontext</strong><ol>");
foreach ($options as $option) {
echo("<li>$option->optiontext ($option->responsecount)</li>");
}
echo('</ol></div>');
- print_simple_box_end();
+ echo $OUTPUT->box_end();
- if ($responses = get_records('block_poll_response', 'pollid', $poll->id, 'submitted ASC')) {
+ if (!(isset($poll->anonymous) && $poll->anonymous == 1) && $responses = $DB->get_records('block_poll_response', array('pollid' => $poll->id), 'submitted ASC')) {
$responsecount = count($responses);
$optioncount = count($options);
- $table = new Object();
+ $table = new html_table();
$table->head = array('&nbsp;', get_string('user'), get_string('date'));
for ($i = 1; $i <= $optioncount; $i++) {
$table->head[] = $i;
@@ -63,20 +70,12 @@ function get_response_checks($options, $selected) {
$table->width = '*';
foreach ($responses as $response) {
- if (!$poll->anonymous) {
- $user = get_record('user', 'id', $response->userid, '', '', '', '', 'id, firstname, lastname, picture');
- $table->data[] = array_merge(array(print_user_picture($user->id, $COURSE->id, $user->picture, 0, true),
- fullname($user), userdate($response->submitted)),
- get_response_checks($options, $response->optionid));
-
- } else { //anonymous data
- $table->data[] = array_merge(array(print_png("$CFG->pixpath/u/f2.png",35,35,true),
- get_string('useranonymous', 'block_poll'), userdate($response->submitted)),
- get_response_checks($options, $response->optionid));
- }
+ $user = $DB->get_record('user', array('id' => $response->userid), user_picture::fields());
+ $table->data[] = array_merge(array($OUTPUT->user_picture($user, array($cid)),
+ fullname($user), userdate($response->submitted)),
+ block_poll_get_response_checks($options, $response->optionid));
}
- print_table($table);
+ echo html_writer::table($table);
}
}
-?>
View
67 tabs.php
@@ -0,0 +1,67 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+
+$action = required_param('action', PARAM_ALPHA);
+$instanceid = required_param('instanceid', PARAM_INT);
+
+if (!$bi = $DB->get_record('block_instances', array('id' => $instanceid))) {
+ print_error('Missing block instance!'); //TODO: Stringify
+}
+$config = unserialize(base64_decode($bi->configdata));
+
+// Check login and get context.
+$context = get_context_instance(CONTEXT_BLOCK, $instanceid);
+$cid = get_courseid_from_context($context);
+if ($cid === false) {
+ $cid = SITEID;
+}
+require_login($cid);
+require_capability('block/poll:editpoll', $context);
+
+if ($action == 'configblock') {
+ $url = new moodle_url('/course/view.php', array('id' => $cid, 'sesskey' => $USER->sesskey, 'bui_editid' => $instanceid));
+ if ($bi->pagetypepattern == 'my-index') {
+ $url = new moodle_url('/my/index.php', array('sesskey' => $USER->sesskey, 'bui_editid' => $instanceid));
+ }
+ redirect($url);
+}
+
+$tabs = array();
+$tabnames = array('configblock', 'editpoll', 'managepolls', 'responses');
+foreach ($tabnames as $tabname) {
+ $params = array('action' => $tabname, 'cid' => $cid, 'instanceid' => $instanceid);
+ $url = new moodle_url('/blocks/poll/tabs.php', $params);
+ $tabs[] = new tabObject($tabname, $url, get_string('tab' . $tabname, 'block_poll'));
+}
+
+if (!in_array($action, $tabnames)) {
+ $action = 'configblock';
+}
+
+$PAGE->set_url('/blocks/poll/tabs.php');
+$PAGE->set_context($context);
+$PAGE->requires->css('/blocks/poll/styles.css');
+echo $OUTPUT->header();
+
+print_tabs(array($tabs), $action);
+
+echo html_writer::empty_tag('br');
+include("tab_$action.php");
+
+echo $OUTPUT->footer();
View
20 version.php
@@ -1,3 +1,19 @@
<?php
-$plugin->version = 2011041400;
-$plugin->requires = 2007101541;
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+$plugin->version = 2011113000;
+$plugin->requires = 2010112400;
Please sign in to comment.
Something went wrong with that request. Please try again.