MDL-56307 course: API changes to support retrieve by time
This commit is contained in:
@@ -217,4 +217,50 @@ class comment_manager {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,9 +798,12 @@ class file_storage {
|
||||
* @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);
|
||||
@@ -819,6 +822,10 @@ class file_storage {
|
||||
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}";
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -1174,6 +1174,40 @@ class rating_manager {
|
||||
}
|
||||
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.
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user