MDL-49231 mod_glossary: Minor coding style improvements
This commit is contained in:
committed by
Juan Leyva
parent
a58a792ba6
commit
a4d9adcb47
@@ -37,6 +37,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @package mod_glossary
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
class mod_glossary_entry_query_builder {
|
||||
|
||||
@@ -88,7 +89,8 @@ class mod_glossary_entry_query_builder {
|
||||
$this->from = sprintf('FROM {glossary_entries} %s', self::ALIAS_ENTRIES);
|
||||
if (!empty($glossary)) {
|
||||
$this->glossary = $glossary;
|
||||
$this->where[] = sprintf('(%s.glossaryid = :gid OR %s.sourceglossaryid = :gid2)', self::ALIAS_ENTRIES, self::ALIAS_ENTRIES);
|
||||
$this->where[] = sprintf('(%s.glossaryid = :gid OR %s.sourceglossaryid = :gid2)',
|
||||
self::ALIAS_ENTRIES, self::ALIAS_ENTRIES);
|
||||
$this->params['gid'] = $glossary->id;
|
||||
$this->params['gid2'] = $glossary->id;
|
||||
}
|
||||
@@ -121,7 +123,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Internal method to build the query.
|
||||
*
|
||||
* @param boolean $count Query to count?
|
||||
* @param bool $count Query to count?
|
||||
* @return string The SQL statement.
|
||||
*/
|
||||
protected function build_query($count = false) {
|
||||
@@ -150,7 +152,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Count the records.
|
||||
*
|
||||
* @return int
|
||||
* @return int The number of records.
|
||||
*/
|
||||
public function count_records() {
|
||||
global $DB;
|
||||
@@ -171,8 +173,8 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter a field using a letter.
|
||||
*
|
||||
* @param string $letter The letter.
|
||||
* @param string $finalfield The SQL statement representing the field.
|
||||
* @param string $letter The letter.
|
||||
* @param string $finalfield The SQL statement representing the field.
|
||||
*/
|
||||
protected function filter_by_letter($letter, $finalfield) {
|
||||
global $DB;
|
||||
@@ -188,7 +190,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter a field by special characters.
|
||||
*
|
||||
* @param string $finalfield The SQL statement representing the field.
|
||||
* @param string $finalfield The SQL statement representing the field.
|
||||
*/
|
||||
protected function filter_by_non_letter($finalfield) {
|
||||
global $DB;
|
||||
@@ -205,8 +207,8 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter the author by letter.
|
||||
*
|
||||
* @param string $letter The letter.
|
||||
* @param boolean $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @param string $letter The letter.
|
||||
* @param bool $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
*/
|
||||
public function filter_by_author_letter($letter, $firstnamefirst = false) {
|
||||
$field = self::get_fullname_field($firstnamefirst);
|
||||
@@ -216,7 +218,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter the author by special characters.
|
||||
*
|
||||
* @param boolean $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @param bool $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
*/
|
||||
public function filter_by_author_non_letter($firstnamefirst = false) {
|
||||
$field = self::get_fullname_field($firstnamefirst);
|
||||
@@ -226,7 +228,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter the concept by letter.
|
||||
*
|
||||
* @param string $letter The letter.
|
||||
* @param string $letter The letter.
|
||||
*/
|
||||
public function filter_by_concept_letter($letter) {
|
||||
$this->filter_by_letter($letter, self::resolve_field('concept', 'entries'));
|
||||
@@ -244,8 +246,8 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Filter non approved entries.
|
||||
*
|
||||
* @param string $constant One of the NON_APPROVED_* constants.
|
||||
* @param int $userid The user ID when relevant, otherwise current user.
|
||||
* @param string $constant One of the NON_APPROVED_* constants.
|
||||
* @param int $userid The user ID when relevant, otherwise current user.
|
||||
*/
|
||||
public function filter_by_non_approved($constant, $userid = null) {
|
||||
global $USER;
|
||||
@@ -277,7 +279,7 @@ class mod_glossary_entry_query_builder {
|
||||
*
|
||||
* This requires the alias table to be joined in the query. See {@link self::join_alias()}.
|
||||
*
|
||||
* @param string $term What the concept or aliases should be.
|
||||
* @param string $term What the concept or aliases should be.
|
||||
*/
|
||||
public function filter_by_term($term) {
|
||||
$this->where[] = sprintf("(%s = :filterterma OR %s = :filtertermb)",
|
||||
@@ -293,8 +295,8 @@ class mod_glossary_entry_query_builder {
|
||||
* Note that this does not handle invalid or too short terms. This requires the alias
|
||||
* table to be joined in the query. See {@link self::join_alias()}.
|
||||
*
|
||||
* @param array $terms Array of terms.
|
||||
* @param boolean $fullsearch Whether or not full search should be enabled.
|
||||
* @param array $terms Array of terms.
|
||||
* @param bool $fullsearch Whether or not full search should be enabled.
|
||||
*/
|
||||
public function filter_by_search_terms(array $terms, $fullsearch = true) {
|
||||
global $DB;
|
||||
@@ -362,7 +364,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Convenience method to get get the SQL statement for the full name.
|
||||
*
|
||||
* @param boolean $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @param bool $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @return string The SQL statement.
|
||||
*/
|
||||
public static function get_fullname_field($firstnamefirst = false) {
|
||||
@@ -398,7 +400,7 @@ class mod_glossary_entry_query_builder {
|
||||
*
|
||||
* This comes handy when {@link self::add_user_fields} was used.
|
||||
*
|
||||
* @param stdClass $record The record.
|
||||
* @param stdClass $record The record.
|
||||
* @return stdClass A user object.
|
||||
*/
|
||||
public static function get_user_from_record($record) {
|
||||
@@ -425,7 +427,7 @@ class mod_glossary_entry_query_builder {
|
||||
* logic that assumes that when displaying all categories the non categorised entries should
|
||||
* not be returned, etc...
|
||||
*
|
||||
* @param int $categoryid The category ID, or GLOSSARY_SHOW_* constant.
|
||||
* @param int $categoryid The category ID, or GLOSSARY_SHOW_* constant.
|
||||
*/
|
||||
public function join_category($categoryid) {
|
||||
|
||||
@@ -456,7 +458,7 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Join the user table.
|
||||
*
|
||||
* @param boolean $strict When strict uses a JOIN rather than a LEFT JOIN.
|
||||
* @param bool $strict When strict uses a JOIN rather than a LEFT JOIN.
|
||||
*/
|
||||
public function join_user($strict = false) {
|
||||
$join = $strict ? 'JOIN' : 'LEFT JOIN';
|
||||
@@ -466,8 +468,8 @@ class mod_glossary_entry_query_builder {
|
||||
|
||||
/**
|
||||
* Limit the number of records to fetch.
|
||||
* @param int $from Fetch from.
|
||||
* @param int $num Number to fetch.
|
||||
* @param int $from Fetch from.
|
||||
* @param int $num Number to fetch.
|
||||
*/
|
||||
public function limit($from, $num) {
|
||||
$this->limitfrom = $from;
|
||||
@@ -479,7 +481,7 @@ class mod_glossary_entry_query_builder {
|
||||
*
|
||||
* This ensures that the value is either ASC or DESC.
|
||||
*
|
||||
* @param string $direction The desired direction.
|
||||
* @param string $direction The desired direction.
|
||||
* @return string ASC or DESC.
|
||||
*/
|
||||
protected function normalize_direction($direction) {
|
||||
@@ -505,9 +507,8 @@ class mod_glossary_entry_query_builder {
|
||||
/**
|
||||
* Order by author name.
|
||||
*
|
||||
* @param boolean $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @param string $direction [description]
|
||||
* @param string $direction ASC, or DESC.
|
||||
* @param bool $firstnamefirst Whether or not the firstname is first in the author's name.
|
||||
* @param string $direction ASC, or DESC.
|
||||
*/
|
||||
public function order_by_author($firstnamefirst = false, $direction = '') {
|
||||
$field = self::get_fullname_field($firstnamefirst);
|
||||
|
||||
@@ -48,11 +48,14 @@ class mod_glossary_external extends external_api {
|
||||
* @param string $format The display format of the glossary.
|
||||
* @return array Containing some of all of the following: letter, cat, date, author.
|
||||
*/
|
||||
public static function get_browse_modes_from_display_format($format) {
|
||||
protected static function get_browse_modes_from_display_format($format) {
|
||||
global $DB;
|
||||
|
||||
$formats = array();
|
||||
$dp = $DB->get_record('glossary_formats', array('name' => $format), '*', IGNORE_MISSING);
|
||||
$formats = glossary_get_visible_tabs($dp);
|
||||
if ($dp) {
|
||||
$formats = glossary_get_visible_tabs($dp);
|
||||
}
|
||||
|
||||
// Always add 'letter'.
|
||||
$modes = array('letter');
|
||||
@@ -76,12 +79,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param bool $includecat Whether the definition should include category info.
|
||||
* @return external_definition
|
||||
*/
|
||||
public static function get_entry_return_structure($includecat = false) {
|
||||
protected static function get_entry_return_structure($includecat = false) {
|
||||
$params = array(
|
||||
'id' => new external_value(PARAM_INT, 'The entry ID'),
|
||||
'glossaryid' => new external_value(PARAM_INT, 'The glossary ID'),
|
||||
'userid' => new external_value(PARAM_INT, 'Author ID'),
|
||||
'userfullname' => new external_value(PARAM_TEXT, 'Author full name'),
|
||||
'userfullname' => new external_value(PARAM_NOTAGS, 'Author full name'),
|
||||
'userpictureurl' => new external_value(PARAM_URL, 'Author picture'),
|
||||
'concept' => new external_value(PARAM_RAW, 'The concept'),
|
||||
'definition' => new external_value(PARAM_RAW, 'The definition'),
|
||||
@@ -125,7 +128,7 @@ class mod_glossary_external extends external_api {
|
||||
* @param context $context The context the entry belongs to.
|
||||
* @return void
|
||||
*/
|
||||
public static function fill_entry_details($entry, $context) {
|
||||
protected static function fill_entry_details($entry, $context) {
|
||||
global $PAGE;
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
|
||||
@@ -167,7 +170,7 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $id The glossary ID.
|
||||
* @return array Contains glossary, context, course and cm.
|
||||
*/
|
||||
public static function validate_glossary($id) {
|
||||
protected static function validate_glossary($id) {
|
||||
global $DB;
|
||||
$glossary = $DB->get_record('glossary', array('id' => $id), '*', MUST_EXIST);
|
||||
list($course, $cm) = get_course_and_cm_from_instance($glossary, 'glossary');
|
||||
@@ -329,13 +332,12 @@ class mod_glossary_external extends external_api {
|
||||
* Notify that the course module was viewed.
|
||||
*
|
||||
* @param int $id The glossary instance ID.
|
||||
* @param string $mode The view mode.
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function view_glossary($id, $mode) {
|
||||
global $DB;
|
||||
|
||||
$params = self::validate_parameters(self::view_glossary_parameters(), array(
|
||||
'id' => $id,
|
||||
'mode' => $mode
|
||||
@@ -388,6 +390,7 @@ class mod_glossary_external extends external_api {
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function view_entry($id) {
|
||||
global $DB, $USER;
|
||||
@@ -453,13 +456,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_letter($id, $letter, $from = 0, $limit = 20, $options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_letter($id, $letter, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_letter_parameters(), array(
|
||||
'id' => $id,
|
||||
'letter' => $letter,
|
||||
@@ -544,14 +546,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_date($id, $order = 'UPDATE', $sort = 'DESC', $from = 0, $limit = 20,
|
||||
$options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_date($id, $order, $sort, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_date_parameters(), array(
|
||||
'id' => $id,
|
||||
'order' => core_text::strtoupper($order),
|
||||
@@ -622,7 +622,7 @@ class mod_glossary_external extends external_api {
|
||||
*/
|
||||
public static function get_categories_parameters() {
|
||||
return new external_function_parameters(array(
|
||||
'id' => new external_value(PARAM_INT, 'Glossary entry ID'),
|
||||
'id' => new external_value(PARAM_INT, 'The glossary ID'),
|
||||
'from' => new external_value(PARAM_INT, 'Start returning records from here', VALUE_DEFAULT, 0),
|
||||
'limit' => new external_value(PARAM_INT, 'Number of records to return', VALUE_DEFAULT, 20)
|
||||
));
|
||||
@@ -634,13 +634,11 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $id The glossary ID.
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, categories and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_categories($id, $from = 0, $limit = 20) {
|
||||
global $DB;
|
||||
|
||||
public static function get_categories($id, $from, $limit) {
|
||||
$params = self::validate_parameters(self::get_categories_parameters(), array(
|
||||
'id' => $id,
|
||||
'from' => $from,
|
||||
@@ -698,7 +696,7 @@ class mod_glossary_external extends external_api {
|
||||
*/
|
||||
public static function get_entries_by_category_parameters() {
|
||||
return new external_function_parameters(array(
|
||||
'id' => new external_value(PARAM_INT, 'Glossary entry ID.'),
|
||||
'id' => new external_value(PARAM_INT, 'The glossary ID.'),
|
||||
'categoryid' => new external_value(PARAM_INT, 'The category ID. Use \'' . GLOSSARY_SHOW_ALL_CATEGORIES . '\' for all' .
|
||||
' categories, or \'' . GLOSSARY_SHOW_NOT_CATEGORISED . '\' for uncategorised entries.'),
|
||||
'from' => new external_value(PARAM_INT, 'Start returning records from here', VALUE_DEFAULT, 0),
|
||||
@@ -718,12 +716,13 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_category($id, $categoryid, $from = 0, $limit = 20, $options = array()) {
|
||||
global $DB, $USER;
|
||||
public static function get_entries_by_category($id, $categoryid, $from, $limit, $options) {
|
||||
global $DB;
|
||||
|
||||
$params = self::validate_parameters(self::get_entries_by_category_parameters(), array(
|
||||
'id' => $id,
|
||||
@@ -751,7 +750,7 @@ class mod_glossary_external extends external_api {
|
||||
// Validate the category.
|
||||
if (in_array($categoryid, array(GLOSSARY_SHOW_ALL_CATEGORIES, GLOSSARY_SHOW_NOT_CATEGORISED))) {
|
||||
// All good.
|
||||
} else if ($DB->count_records('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id)) < 1) {
|
||||
} else if (!$DB->record_exists('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id))) {
|
||||
throw new invalid_parameter_exception('invalidcategory');
|
||||
}
|
||||
|
||||
@@ -818,12 +817,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, authors and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_authors($id, $from = 0, $limit = 20, $options = array()) {
|
||||
global $DB, $PAGE, $USER;
|
||||
public static function get_authors($id, $from, $limit, $options) {
|
||||
global $PAGE;
|
||||
|
||||
$params = self::validate_parameters(self::get_authors_parameters(), array(
|
||||
'id' => $id,
|
||||
@@ -916,14 +915,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_author($id, $letter, $field = 'LASTNAME', $sort = 'ASC', $from = 0, $limit = 20,
|
||||
$options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_author($id, $letter, $field, $sort, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_author_parameters(), array(
|
||||
'id' => $id,
|
||||
'letter' => $letter,
|
||||
@@ -1022,14 +1019,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_author_id($id, $authorid, $order = 'CONCEPT', $sort = 'ASC', $from = 0, $limit = 20,
|
||||
$options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_author_id($id, $authorid, $order, $sort, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_author_id_parameters(), array(
|
||||
'id' => $id,
|
||||
'authorid' => $authorid,
|
||||
@@ -1130,14 +1125,12 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entries_by_search($id, $query, $fullsearch = true, $order = 'CONCEPT', $sort = 'ASC', $from = 0,
|
||||
$limit = 20, $options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_search($id, $query, $fullsearch, $order, $sort, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_search_parameters(), array(
|
||||
'id' => $id,
|
||||
'query' => $query,
|
||||
@@ -1227,13 +1220,11 @@ class mod_glossary_external extends external_api {
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_entries_by_term($id, $term, $from = 0, $limit = 20, $options = array()) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_by_term($id, $term, $from, $limit, $options) {
|
||||
$params = self::validate_parameters(self::get_entries_by_term_parameters(), array(
|
||||
'id' => $id,
|
||||
'term' => $term,
|
||||
@@ -1311,14 +1302,11 @@ class mod_glossary_external extends external_api {
|
||||
* @param string $sort The direction of the order.
|
||||
* @param int $from Start returning records from here.
|
||||
* @param int $limit Number of records to return.
|
||||
* @param array $options Array of options.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing count, entries and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_entries_to_approve($id, $letter, $order = 'CONCEPT', $sort = 'ASC', $from = 0, $limit = 20) {
|
||||
global $DB, $USER;
|
||||
|
||||
public static function get_entries_to_approve($id, $letter, $order, $sort, $from, $limit) {
|
||||
$params = self::validate_parameters(self::get_entries_to_approve_parameters(), array(
|
||||
'id' => $id,
|
||||
'letter' => $letter,
|
||||
@@ -1389,9 +1377,10 @@ class mod_glossary_external extends external_api {
|
||||
* Get an entry.
|
||||
*
|
||||
* @param int $id The entry ID.
|
||||
* @return array of warnings and status result
|
||||
* @return array Containing entry and warnings.
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_entry_by_id($id) {
|
||||
global $DB, $USER;
|
||||
|
||||
@@ -3584,8 +3584,8 @@ function glossary_get_entries_by_author_id($glossary, $context, $authorid, $orde
|
||||
*
|
||||
* @param object $glossary The glossary.
|
||||
* @param context $context The context of the glossary.
|
||||
* @param int $from Fetch records from.
|
||||
* @param int $limit Number of records to fetch.
|
||||
* @param int $from Fetch records from.
|
||||
* @param array $options Accepts:
|
||||
* - (bool) includenotapproved. When false, includes self even if all of their entries require approval.
|
||||
* When true, also includes authors only having entries pending approval.
|
||||
@@ -3790,7 +3790,8 @@ function glossary_get_entries_to_approve($glossary, $context, $letter, $order, $
|
||||
* Fetch an entry.
|
||||
*
|
||||
* @param int $id The entry ID.
|
||||
* @return object|false
|
||||
* @return object|false The entry, or false when not found.
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
function glossary_get_entry_by_id($id) {
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
mod_glossary_external::view_entry($e3->id);
|
||||
$this->fail('Cannot view non-approved entries of others.');
|
||||
} catch (invalid_parameter_exception $e) {
|
||||
// All good.
|
||||
}
|
||||
|
||||
// Test non-readable entry.
|
||||
@@ -257,14 +258,14 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($u1);
|
||||
|
||||
// Requesting a single letter.
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'b', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'b', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(1, $return['count']);
|
||||
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
|
||||
|
||||
// Requesting special letters.
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'SPECIAL', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'SPECIAL', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
|
||||
$this->assertCount(2, $return['entries']);
|
||||
$this->assertEquals(2, $return['count']);
|
||||
@@ -272,12 +273,12 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1c->id, $return['entries'][1]['id']);
|
||||
|
||||
// Requesting with limit.
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 1);
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 1, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 1, 2);
|
||||
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 1, 2, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
|
||||
$this->assertCount(2, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -426,7 +427,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$cat1a = $gg->create_category($g1, array('name' => 'Fish'), array($e1a1, $e1a2, $e1a3));
|
||||
$cat1b = $gg->create_category($g1, array('name' => 'Cat'), array($e1b1, $e1b2));
|
||||
$cat1c = $gg->create_category($g1, array('name' => 'Zebra'), array($e1b1)); // $e1b1 is in two categories.
|
||||
$cat1c = $gg->create_category($g1, array('name' => 'Zebra'), array($e1b1)); // Entry $e1b1 is in two categories.
|
||||
$cat2a = $gg->create_category($g2, array(), array($e2a1, $e2a2));
|
||||
|
||||
$this->setAdminUser();
|
||||
@@ -559,7 +560,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($u1);
|
||||
|
||||
// Requesting a single letter.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(4, $return['entries']);
|
||||
$this->assertEquals(4, $return['count']);
|
||||
@@ -569,19 +570,19 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a3->id, $return['entries'][3]['id']);
|
||||
|
||||
// Requesting special letters.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'SPECIAL', 'LASTNAME', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'SPECIAL', 'LASTNAME', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(1, $return['count']);
|
||||
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
|
||||
|
||||
// Requesting with limit.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 0, 1);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 0, 1, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(6, $return['count']);
|
||||
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 1, 2);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 1, 2, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(2, $return['entries']);
|
||||
$this->assertEquals(6, $return['count']);
|
||||
@@ -604,28 +605,28 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a3->id, $return['entries'][6]['id']);
|
||||
|
||||
// Changing order.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'DESC', 0, 1);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'DESC', 0, 1, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(6, $return['count']);
|
||||
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
|
||||
|
||||
// Sorting by firstname.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'ASC', 0, 1);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'ASC', 0, 1, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(6, $return['count']);
|
||||
$this->assertEquals($e1b2->id, $return['entries'][0]['id']);
|
||||
|
||||
// Sorting by firstname descending.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'DESC', 0, 1);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'DESC', 0, 1, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(1, $return['entries']);
|
||||
$this->assertEquals(6, $return['count']);
|
||||
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
|
||||
|
||||
// Filtering by firstname descending.
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'z', 'FIRSTNAME', 'DESC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'z', 'FIRSTNAME', 'DESC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(4, $return['entries']);
|
||||
$this->assertEquals(4, $return['count']);
|
||||
@@ -636,7 +637,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Test with a deleted user.
|
||||
delete_user($u2);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
|
||||
$this->assertCount(4, $return['entries']);
|
||||
$this->assertEquals(4, $return['count']);
|
||||
@@ -673,7 +674,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
|
||||
// Standard request.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -682,7 +683,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a1->id, $return['entries'][2]['id']);
|
||||
|
||||
// Standard request descending.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'DESC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'DESC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -691,7 +692,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a2->id, $return['entries'][2]['id']);
|
||||
|
||||
// Requesting ordering by time created.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -700,7 +701,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a2->id, $return['entries'][2]['id']);
|
||||
|
||||
// Requesting ordering by time created descending.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'DESC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'DESC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -709,7 +710,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a3->id, $return['entries'][2]['id']);
|
||||
|
||||
// Requesting ordering by time modified.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'ASC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'ASC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -718,7 +719,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e1a2->id, $return['entries'][2]['id']);
|
||||
|
||||
// Requesting ordering by time modified descending.
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'DESC', 0, 20);
|
||||
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'DESC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
|
||||
$this->assertCount(3, $return['entries']);
|
||||
$this->assertEquals(3, $return['count']);
|
||||
@@ -773,8 +774,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$e4 = $gg->create_content($g1, array('approved' => 0, 'concept' => 'Toulouse'));
|
||||
$e5 = $gg->create_content($g1, array('approved' => 1, 'definition' => 'Heroes', 'concept' => 'Abcd'));
|
||||
$e6 = $gg->create_content($g1, array('approved' => 0, 'definition' => 'When used for heroes'));
|
||||
$e7 = $gg->create_content($g1, array('approved' => 1, 'timecreated' => 1, 'timemodified' => time() + 3600, 'concept' => 'Z'),
|
||||
array('Couscous'));
|
||||
$e7 = $gg->create_content($g1, array('approved' => 1, 'timecreated' => 1, 'timemodified' => time() + 3600,
|
||||
'concept' => 'Z'), array('Couscous'));
|
||||
$e8 = $gg->create_content($g1, array('approved' => 0), array('Heroes'));
|
||||
$e9 = $gg->create_content($g2, array('approved' => 0));
|
||||
|
||||
@@ -797,7 +798,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($e5->id, $return['entries'][0]['id']);
|
||||
$this->assertEquals($e3->id, $return['entries'][1]['id']);
|
||||
|
||||
// Concept descending
|
||||
// Concept descending.
|
||||
$query = 'hero';
|
||||
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, true, 'CONCEPT', 'DESC', 0, 20, array());
|
||||
$return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
|
||||
@@ -1065,12 +1066,14 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$return = mod_glossary_external::get_entry_by_id($e3->id);
|
||||
$this->fail('Cannot view unapproved entries of others.');
|
||||
} catch (invalid_parameter_exception $e) {
|
||||
// All good.
|
||||
}
|
||||
|
||||
try {
|
||||
$return = mod_glossary_external::get_entry_by_id($e4->id);
|
||||
$this->fail('Cannot view entries from another course.');
|
||||
} catch (require_login_exception $e) {
|
||||
// All good.
|
||||
}
|
||||
|
||||
// An admin can be other's entries to be approved.
|
||||
|
||||
Reference in New Issue
Block a user