Skip to content

Commit

Permalink
MDL-56307 course: API changes to support retrieve by time
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Oct 25, 2016
1 parent 6492401 commit 1896b80
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
46 changes: 46 additions & 0 deletions comment/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,50 @@ public function delete_comments($list) {
}
return true;
}

/**
* Get comments created since a given time.
*
* @param stdClass $course course object
* @param stdClass $context context object
* @param string $component component name
* @param int $since the time to check
* @param stdClass $cm course module object
* @return array list of comments db records since the given timelimit
* @since Moodle 3.2
*/
public function get_component_comments_since($course, $context, $component, $since, $cm = null) {
global $DB;

$commentssince = array();
$where = 'contextid = ? AND component = ? AND timecreated > ?';
$comments = $DB->get_records_select('comments', $where, array($context->id, $component, $since));
// Check item by item if we have permissions.
$managersviewstatus = array();
foreach ($comments as $comment) {
// Check if the manager for the item is cached.
if (!isset($managersviewstatus[$comment->commentarea]) or
!isset($managersviewstatus[$comment->commentarea][$comment->itemid])) {

$args = new stdClass;
$args->area = $comment->commentarea;
$args->itemid = $comment->itemid;
$args->context = $context;
$args->course = $course;
$args->client_id = 0;
$args->component = $component;
if (!empty($cm)) {
$args->cm = $cm;
}

$manager = new comment($args);
$managersviewstatus[$comment->commentarea][$comment->itemid] = $manager->can_view();
}

if ($managersviewstatus[$comment->commentarea][$comment->itemid]) {
$commentssince[$comment->id] = $comment;
}
}
return $commentssince;
}
}
9 changes: 8 additions & 1 deletion lib/filestorage/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,12 @@ public function get_external_files($repositoryid, $sort = '') {
* @param int $itemid item ID or all files if not specified
* @param string $sort A fragment of SQL to use for sorting
* @param bool $includedirs whether or not include directories
* @param string $extrasql a fragment of SQL to append to the WHERE part of the query
* @param array $extraconditions an array of additional condition values for the $extrasql
* @return stored_file[] array of stored_files indexed by pathanmehash
*/
public function get_area_files($contextid, $component, $filearea, $itemid = false, $sort = "itemid, filepath, filename", $includedirs = true) {
public function get_area_files($contextid, $component, $filearea, $itemid = false, $sort = "itemid, filepath, filename",
$includedirs = true, $extrasql = '', $extraconditions = array()) {
global $DB;

$conditions = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea);
Expand All @@ -819,6 +822,10 @@ public function get_area_files($contextid, $component, $filearea, $itemid = fals
AND f.component = :component
AND f.filearea = :filearea
$itemidsql";
if (!empty($extrasql)) {
$sql .= " $extrasql";
$conditions = array_merge($conditions, $extraconditions);
}
if (!empty($sort)) {
$sql .= " ORDER BY {$sort}";
}
Expand Down
2 changes: 2 additions & 0 deletions lib/gradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $use
$grade->feedback = $grade_grades[$userid]->feedback;
$grade->feedbackformat = $grade_grades[$userid]->feedbackformat;
$grade->usermodified = $grade_grades[$userid]->usermodified;
$grade->datesubmitted = $grade_grades[$userid]->get_datesubmitted();
$grade->dategraded = $grade_grades[$userid]->get_dategraded();

// create text representation of grade
if (in_array($grade_item->id, $needsupdate)) {
Expand Down
34 changes: 34 additions & 0 deletions rating/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,40 @@ public function add_rating($cm, $context, $component, $ratingarea, $itemid, $sca
}
return $result;
}

/**
* Get ratings created since a given time.
*
* @param stdClass $context context object
* @param string $component component name
* @param int $since the time to check
* @return array list of ratings db records since the given timelimit
* @since Moodle 3.2
*/
public function get_component_ratings_since($context, $component, $since) {
global $DB, $USER;

$ratingssince = array();
$where = 'contextid = ? AND component = ? AND (timecreated > ? OR timemodified > ?)';
$ratings = $DB->get_records_select('rating', $where, array($context->id, $component, $since, $since));
// Check area by area if we have permissions.
$permissions = array();
$rm = new rating_manager();

foreach ($ratings as $rating) {
// Check if the permission array for the area is cached.
if (!isset($permissions[$rating->ratingarea])) {
$permissions[$rating->ratingarea] = $rm->get_plugin_permissions_array($context->id, $component,
$rating->ratingarea);
}

if (($permissions[$rating->ratingarea]['view'] and $rating->userid == $USER->id) or
($permissions[$rating->ratingarea]['viewany'] or $permissions[$rating->ratingarea]['viewall'])) {
$ratingssince[$rating->id] = $rating;
}
}
return $ratingssince;
}
} // End rating_manager class definition.

/**
Expand Down

0 comments on commit 1896b80

Please sign in to comment.