-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started implementation of tags management page
- Loading branch information
1 parent
21d47f2
commit b7010ae
Showing
9 changed files
with
381 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
echo 'Copying...' | ||
cp -R src orig | ||
echo 'Running Babel...' | ||
babel orig -d src | ||
echo 'Running Grunt...' | ||
grunt amd --force | ||
echo 'Cleaning up...' | ||
rm -R src | ||
mv orig src | ||
echo 'Done.' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Renderable for questions page | ||
* | ||
* @package local_qtracker | ||
* @author André Storhaug <[email protected]> | ||
* @copyright 2020 NTNU | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_qtracker\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use coding_exception; | ||
use dml_exception; | ||
use moodle_exception; | ||
use renderable; | ||
use renderer_base; | ||
use stdClass; | ||
use templatable; | ||
|
||
/** | ||
* Class containing data for tags page. | ||
* | ||
* @copyright 2020 André Storhaug | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class tags_page implements renderable, templatable { | ||
|
||
/** The default number of results to be shown per page. */ | ||
const DEFAULT_PAGE_SIZE = 20; | ||
|
||
/** @var array|tags_table|\local_qtracker\tags_table */ | ||
protected $tagstable = []; | ||
|
||
/** | ||
* Construct this renderable. | ||
* | ||
* @param \local_qtracker\tags_table $tagstable | ||
* @param int $courseid the id of the course | ||
*/ | ||
public function __construct(tags_table $tagstable, $courseid) { | ||
$this->tagstable = $tagstable; | ||
$this->courseid = $courseid; | ||
} | ||
|
||
/** | ||
* Export this data so it can be used as the context for a mustache template. | ||
* | ||
* @param renderer_base $output | ||
* @return stdClass | ||
* @throws coding_exception | ||
* @throws dml_exception | ||
* @throws moodle_exception | ||
*/ | ||
public function export_for_template(renderer_base $output) { | ||
global $PAGE; | ||
$data = new stdClass(); | ||
|
||
$newtagbutton = new stdClass(); | ||
$newtagbutton->primary = true; | ||
$newtagbutton->name = "newtag"; | ||
$newtagbutton->value = true; | ||
$newtagbutton->label = get_string('newtag', 'local_qtracker'); | ||
$newtagurl = new \moodle_url('/local/qtracker/new_tag.php'); | ||
$newtagurl->param('courseid', $this->courseid); | ||
$newtagbutton->action = $newtagurl; | ||
$data->newtagbutton = $newtagbutton; | ||
|
||
ob_start(); | ||
$this->tagstable->out(self::DEFAULT_PAGE_SIZE, true); | ||
$tags = ob_get_contents(); | ||
ob_end_clean(); | ||
$data->tags = $tags; | ||
$data->courseid = $this->courseid; | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Table of questions with registered issues. | ||
* | ||
* @package local_qtracker | ||
* @author André Storhaug <[email protected]> | ||
* @copyright 2020 NTNU | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_qtracker\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/tablelib.php'); | ||
|
||
use context_system; | ||
use moodle_url; | ||
use table_sql; | ||
|
||
/** | ||
* Tags table. | ||
* | ||
* @package local_qtracker | ||
* @copyright 2020 André Storhaug | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class tags_table extends table_sql { | ||
|
||
/** | ||
* Sets up the table. | ||
* | ||
* @param string $uniqueid Unique id of table. | ||
* @param moodle_url $url The base URL. | ||
* @param \context_course $context | ||
* @param boolean $manuallySorted set true if user has chosen a non-default sorting configuration | ||
*/ | ||
public function __construct($uniqueid, $url, $context, $manuallySorted = false) { | ||
global $CFG; | ||
parent::__construct($uniqueid); | ||
|
||
$this->context = $context; | ||
|
||
// Define columns in the table. | ||
$this->define_table_columns(); | ||
// Set the baseurl. | ||
$this->define_baseurl($url); | ||
// Define configs. | ||
$this->define_table_configs($manuallySorted); | ||
// Define SQL. | ||
$this->setup_sql_queries(); | ||
} | ||
|
||
/** | ||
* Generate the display of the question name column. | ||
* @param object $data the table row being output. | ||
* @return string HTML content to go inside the td. | ||
*/ | ||
protected function col_id($data) { | ||
if ($data->id) { | ||
return $data->id; | ||
} else { | ||
return '-'; | ||
} | ||
} | ||
|
||
/** | ||
* Generate the display of the title. | ||
* @param object $data the table row being output. | ||
* @return string HTML content to go inside the td. | ||
*/ | ||
protected function col_name($data) { | ||
if ($data->name) { | ||
return $data->name; | ||
} else { | ||
return '-'; | ||
} | ||
} | ||
|
||
/** | ||
* Generate the display of color column | ||
* @param string $cols extra_colums | ||
* @param object $data the table row being output | ||
* @return |null string html content to go inside the td. | ||
*/ | ||
public function other_cols($cols, $data) { | ||
switch ($cols) { | ||
case 'color': | ||
return null; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Setup the headers for the table. | ||
*/ | ||
protected function define_table_columns() { | ||
|
||
// Define headers and columns. | ||
$cols = array( | ||
'id' => get_string('tagid', 'local_qtracker'), | ||
'name' => get_string('label', 'local_qtracker'), | ||
'color' => get_string('color', 'local_qtracker') | ||
); | ||
|
||
$this->define_columns(array_keys($cols)); | ||
$this->define_headers(array_values($cols)); | ||
} | ||
|
||
|
||
/** | ||
* Define table configs. | ||
* @param boolean $manuallySorted if false the default sorting will be used | ||
*/ | ||
protected function define_table_configs($manuallySorted) { | ||
$this->collapsible(false); | ||
$this->sortable(false); | ||
$this->pageable(true); | ||
} | ||
|
||
/** | ||
* Builds the SQL query. | ||
* | ||
* @return array containing sql to use and an array of params. | ||
*/ | ||
public function setup_sql_queries() { | ||
global $DB; | ||
|
||
$contextids = explode('/', trim($this->context->path, '/')); | ||
// Get all child contexts. | ||
$children = $this->context->get_child_contexts(); | ||
foreach ($children as $c) { | ||
$contextids[] = $c->id; | ||
} | ||
|
||
list($insql, $inarams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED); | ||
|
||
$fields = 'q.id, | ||
q.name,'; | ||
$fields .= "COUNT(case qi.state when 'new' then 1 else null end) AS new, | ||
COUNT(case qi.state when 'open' then 1 else null end) AS open, | ||
COUNT(case qi.state when 'closed' then 1 else null end) AS closed"; | ||
$from = '{local_qtracker_issue} qi'; | ||
$from .= "\nJOIN {question} q ON q.id = qi.questionid"; | ||
$from .= "\nJOIN {context} ctx ON qi.contextid = ctx.id"; | ||
$where = "\nctx.id $insql"; | ||
$where .= "\nGROUP BY q.id"; | ||
$params = $inarams; | ||
|
||
// The WHERE clause is vital here, because some parts of tablelib.php will expect to | ||
// add bits like ' AND x = 1' on the end, and that needs to leave to valid SQL. | ||
$this->set_count_sql("SELECT COUNT(1) FROM (SELECT $fields FROM $from WHERE $where) temp WHERE 1 = 1", $params); | ||
|
||
list($fields, $from, $where, $params) = $this->update_sql_after_count($fields, $from, $where, $params); | ||
$this->set_sql($fields, $from, $where, $params); | ||
} | ||
|
||
/** | ||
* A chance for subclasses to modify the SQL after the count query has been generated, | ||
* and before the full query is constructed. | ||
* @param string $fields SELECT list. | ||
* @param string $from JOINs part of the SQL. | ||
* @param string $where WHERE clauses. | ||
* @param array $params Query params. | ||
* @return array with 4 elements ($fields, $from, $where, $params) as from base_sql. | ||
*/ | ||
protected function update_sql_after_count($fields, $from, $where, $params) { | ||
return [$fields, $from, $where, $params]; | ||
} | ||
|
||
|
||
/** | ||
* Not in use | ||
*/ | ||
public function wrap_html_start() { | ||
if ($this->is_downloading()) { | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* Not in use | ||
*/ | ||
public function wrap_html_finish() { | ||
global $PAGE; | ||
if ($this->is_downloading()) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace local_qtracker; | ||
|
||
require_once('../../config.php'); | ||
require_once($CFG->dirroot . '/local/qtracker/lib.php'); | ||
|
||
global $DB, $OUTPUT, $PAGE; | ||
|
||
// Check for all required variables. | ||
$courseid = required_param('courseid', PARAM_INT); | ||
$manuallySorted = isset($_GET['tsort']); | ||
|
||
if (!$course = $DB->get_record('course', array('id' => $courseid))) { | ||
print_error('invalidcourseid'); | ||
} | ||
$context = \context_course::instance($course->id); | ||
|
||
require_login($course); | ||
require_capability('local/qtracker:viewall', $context); | ||
|
||
$url = new \moodle_url('/local/qtracker/tags.php', array('courseid' => $courseid)); | ||
|
||
$PAGE->set_url($url); | ||
$PAGE->set_pagelayout('incourse'); | ||
$PAGE->set_heading(get_string('pluginname', 'local_qtracker')); | ||
|
||
echo $OUTPUT->header(); | ||
|
||
// Get table renderer and display table. | ||
$table = new \local_qtracker\output\tags_table(uniqid(), $url, $context); | ||
$renderer = $PAGE->get_renderer('local_qtracker'); | ||
$tagspage = new \local_qtracker\output\tags_page($table, $courseid); | ||
echo $renderer->render($tagspage); | ||
|
||
echo $OUTPUT->footer(); |
Oops, something went wrong.