Skip to content

Commit

Permalink
final locking API cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 9, 2007
1 parent 6c9f672 commit ddc2098
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
26 changes: 2 additions & 24 deletions lib/grade/grade_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,37 +302,15 @@ function set_locked($lockedstate, $cascade=false, $refresh=true) {
}
}

/**
* Lock the grade if needed - make sure this is called only when final grade is valid
*/
function check_locktime() {
if (!empty($this->locked)) {
return; // already locked - do not use is_locked() because we do not want the locking status of grade_item here
}

if ($this->locktime and $this->locktime < time()) {
$this->locked = time();
$this->update('locktime');
}
}


/**
* Lock the grade if needed - make sure this is called only when final grades are valid
* @param int $courseid
* @param array $items array of all grade item ids (speedup only)
* @param array $items array of all grade item ids
* @return void
*/
function check_locktime_all($courseid, $items=null) {
function check_locktime_all($courseid, $items) {
global $CFG;

if (!$items) {
if (!$items = get_records('grade_items', 'courseid', $courseid, '', 'id')) {
return; // no items?
}
$items = array_keys($items);
}

$items_sql = implode(',', $items);

$now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
Expand Down
22 changes: 0 additions & 22 deletions lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,28 +493,6 @@ function check_locktime() {
}
}

/**
* Lock all grade items if needed - make sure this is called only when final grades are valid
* @static
* @param int $courseid
* @return void
*/
function check_locktime_all($courseid) {
global $CFG;

$now = time(); // no need to round it here, executed from cron only
$sql = "SELECT * FROM {$CFG->prefix}grade_items
WHERE courseid=$courseid AND locked = 0 AND locktime > 0 AND locktime < $now";

if ($items = get_records_sql($sql)) {
foreach ($items as $item) {
$grade_item = new grade_grade($item, false);
$grade_item->locked = time();
$grade_item->update('locktime');
}
}
}

/**
* Set the locktime for this grade item.
*
Expand Down

0 comments on commit ddc2098

Please sign in to comment.