Skip to content

Commit

Permalink
Merge pull request #175 from learnweb/fix/ratingsort
Browse files Browse the repository at this point in the history
Fix/ratingsort
  • Loading branch information
NinaHerrmann committed Jan 24, 2024
2 parents 49ed301 + 94dca8a commit 43ef13a
Show file tree
Hide file tree
Showing 49 changed files with 1,646 additions and 1,010 deletions.
48 changes: 24 additions & 24 deletions backup/moodle2/backup_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,49 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define the root element describing the moodleoverflow instance.
$moodleoverflow = new backup_nested_element('moodleoverflow', array('id'), array(
$moodleoverflow = new backup_nested_element('moodleoverflow', ['id'], [
'name', 'intro', 'introformat', 'maxbytes', 'maxattachments',
'forcesubscribe', 'trackingtype', 'timecreated', 'timemodified',
'ratingpreference', 'coursewidereputation', 'allownegativereputation'));
'ratingpreference', 'coursewidereputation', 'allownegativereputation']);

// Define each element separated.
$discussions = new backup_nested_element('discussions');
$discussion = new backup_nested_element('discussion', array('id'), array(
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart'));
$discussion = new backup_nested_element('discussion', ['id'], [
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart']);

$posts = new backup_nested_element('posts');

$post = new backup_nested_element('post', array('id'), array(
$post = new backup_nested_element('post', ['id'], [
'parent', 'userid', 'created', 'modified',
'mailed', 'message', 'messageformat', 'attachment'));
'mailed', 'message', 'messageformat', 'attachment']);

$ratings = new backup_nested_element('ratings');

$rating = new backup_nested_element('rating', array('id'), array(
'userid', 'rating', 'firstrated', 'lastchanged'));
$rating = new backup_nested_element('rating', ['id'], [
'userid', 'rating', 'firstrated', 'lastchanged']);

$discussionsubs = new backup_nested_element('discuss_subs');

$discussionsub = new backup_nested_element('discuss_sub', array('id'), array(
$discussionsub = new backup_nested_element('discuss_sub', ['id'], [
'userid',
'preference',
));
]);

$subscriptions = new backup_nested_element('subscriptions');

$subscription = new backup_nested_element('subscription', array('id'), array(
'userid'));
$subscription = new backup_nested_element('subscription', ['id'], [
'userid']);

$readposts = new backup_nested_element('readposts');

$read = new backup_nested_element('read', array('id'), array(
$read = new backup_nested_element('read', ['id'], [
'userid', 'discussionid', 'postid', 'firstread',
'lastread'));
'lastread']);

$tracking = new backup_nested_element('tracking');

$track = new backup_nested_element('track', array('id'), array(
'userid'));
$track = new backup_nested_element('track', ['id'], [
'userid']);

// Build the tree.
$moodleoverflow->add_child($discussions);
Expand All @@ -111,23 +111,23 @@ protected function define_structure() {
$tracking->add_child($track);

// Define data sources.
$moodleoverflow->set_source_table('moodleoverflow', array('id' => backup::VAR_ACTIVITYID));
$moodleoverflow->set_source_table('moodleoverflow', ['id' => backup::VAR_ACTIVITYID]);

// All these source definitions only happen if we are including user info.
if ($userinfo) {
$discussion->set_source_sql('
SELECT *
FROM {moodleoverflow_discussions}
WHERE moodleoverflow = ?',
array(backup::VAR_PARENTID));
[backup::VAR_PARENTID]);

// Need posts ordered by id so parents are always before childs on restore.
$post->set_source_table('moodleoverflow_posts', array('discussion' => backup::VAR_PARENTID), 'id ASC');
$rating->set_source_table('moodleoverflow_ratings', array('postid' => backup::VAR_PARENTID));
$discussionsub->set_source_table('moodleoverflow_discuss_subs', array('discussion' => backup::VAR_PARENTID));
$subscription->set_source_table('moodleoverflow_subscriptions', array('moodleoverflow' => backup::VAR_PARENTID));
$read->set_source_table('moodleoverflow_read', array('moodleoverflowid' => backup::VAR_PARENTID));
$track->set_source_table('moodleoverflow_tracking', array('moodleoverflowid' => backup::VAR_PARENTID));
$post->set_source_table('moodleoverflow_posts', ['discussion' => backup::VAR_PARENTID], 'id ASC');
$rating->set_source_table('moodleoverflow_ratings', ['postid' => backup::VAR_PARENTID]);
$discussionsub->set_source_table('moodleoverflow_discuss_subs', ['discussion' => backup::VAR_PARENTID]);
$subscription->set_source_table('moodleoverflow_subscriptions', ['moodleoverflow' => backup::VAR_PARENTID]);
$read->set_source_table('moodleoverflow_read', ['moodleoverflowid' => backup::VAR_PARENTID]);
$track->set_source_table('moodleoverflow_tracking', ['moodleoverflowid' => backup::VAR_PARENTID]);
}

// Define id annotations.
Expand Down
16 changes: 8 additions & 8 deletions backup/moodle2/restore_moodleoverflow_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('moodleoverflow', array('intro'), 'moodleoverflow');
$contents[] = new restore_decode_content('moodleoverflow_posts', array('message'), 'moodleoverflow_post');
$contents[] = new restore_decode_content('moodleoverflow', ['intro'], 'moodleoverflow');
$contents[] = new restore_decode_content('moodleoverflow_posts', ['message'], 'moodleoverflow_post');

return $contents;
}
Expand All @@ -72,7 +72,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_decode_rule('MOODLEOVERFLOWVIEWBYID', '/mod/moodleoverflow/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('MOODLEOVERFLOWINDEX', '/mod/moodleoverflow/index.php?id=$1', 'course');
Expand All @@ -85,9 +85,9 @@ public static function define_decode_rules() {
// Link to discussion with parent and with anchor posts.
$rules[] = new restore_decode_rule('MOODLEOVERFLOWDISCUSSIONVIEWPARENT',
'/mod/moodleoverflow/discussion.php?d=$1&parent=$2',
array('moodleoverflow_discussion', 'moodleoverflow_post'));
['moodleoverflow_discussion', 'moodleoverflow_post']);
$rules[] = new restore_decode_rule('MOODLEOVERFLOWDISCUSSIONVIEWINSIDE', '/mod/moodleoverflow/discussion.php?d=$1#$2',
array('moodleoverflow_discussion', 'moodleoverflow_post'));
['moodleoverflow_discussion', 'moodleoverflow_post']);

return $rules;

Expand All @@ -100,7 +100,7 @@ public static function define_decode_rules() {
* of { restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('moodleoverflow', 'add',
'view.php?id={course_module}', '{moodleoverflow}');
Expand Down Expand Up @@ -160,7 +160,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('moodleoverflow', 'view all', 'index.php?id={course}', null);

Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class restore_moodleoverflow_activity_structure_step extends restore_activity_st
*/
protected function define_structure() {

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('moodleoverflow', '/activity/moodleoverflow');
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function process_moodleoverflow_post($data) {

// If !post->parent, it's the 1st post. Set it in discussion.
if (empty($data->parent)) {
$DB->set_field('moodleoverflow_discussions', 'firstpost', $newitemid, array('id' => $data->discussion));
$DB->set_field('moodleoverflow_discussions', 'firstpost', $newitemid, ['id' => $data->discussion]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function get_userid_mapping($moodleoverflow, $discussionid) {
if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
return [
$DB->get_field('moodleoverflow_posts', 'userid',
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow')
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow'),
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/event/readtracking_disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $this->other['moodleoverflowid']));
return new \moodle_url('/mod/moodleoverflow/view.php', ['m' => $this->other['moodleoverflowid']]);
}
}
2 changes: 1 addition & 1 deletion classes/event/readtracking_enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $this->other['moodleoverflowid']));
return new \moodle_url('/mod/moodleoverflow/view.php', ['m' => $this->other['moodleoverflowid']]);
}
}
Loading

0 comments on commit 43ef13a

Please sign in to comment.