Skip to content

Commit

Permalink
Merge branch 'MDL-32203c-21' of git://github.com/srynot4sale/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_21_STABLE
  • Loading branch information
Sam Hemelryk committed May 23, 2012
2 parents e09266d + 4ef74c4 commit ebbf509
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 293 deletions.
36 changes: 19 additions & 17 deletions course/completion.php
Expand Up @@ -103,44 +103,43 @@


// Handle aggregation methods // Handle aggregation methods
// Overall aggregation // Overall aggregation
$aggregation = new completion_aggregation(); $aggdata = array(
$aggregation->course = $data->id; 'course' => $data->id,
$aggregation->criteriatype = null; 'criteriatype' => null
);
$aggregation = new completion_aggregation($aggdata);
$aggregation->setMethod($data->overall_aggregation); $aggregation->setMethod($data->overall_aggregation);
$aggregation->insert(); $aggregation->save();


// Activity aggregation // Activity aggregation
if (empty($data->activity_aggregation)) { if (empty($data->activity_aggregation)) {
$data->activity_aggregation = 0; $data->activity_aggregation = 0;
} }


$aggregation = new completion_aggregation(); $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_ACTIVITY;
$aggregation->course = $data->id; $aggregation = new completion_aggregation($aggdata);
$aggregation->criteriatype = COMPLETION_CRITERIA_TYPE_ACTIVITY;
$aggregation->setMethod($data->activity_aggregation); $aggregation->setMethod($data->activity_aggregation);
$aggregation->insert(); $aggregation->save();


// Course aggregation // Course aggregation
if (empty($data->course_aggregation)) { if (empty($data->course_aggregation)) {
$data->course_aggregation = 0; $data->course_aggregation = 0;
} }


$aggregation = new completion_aggregation(); $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_COURSE;
$aggregation->course = $data->id; $aggregation = new completion_aggregation($aggdata);
$aggregation->criteriatype = COMPLETION_CRITERIA_TYPE_COURSE;
$aggregation->setMethod($data->course_aggregation); $aggregation->setMethod($data->course_aggregation);
$aggregation->insert(); $aggregation->save();


// Role aggregation // Role aggregation
if (empty($data->role_aggregation)) { if (empty($data->role_aggregation)) {
$data->role_aggregation = 0; $data->role_aggregation = 0;
} }


$aggregation = new completion_aggregation(); $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_ROLE;
$aggregation->course = $data->id; $aggregation = new completion_aggregation($aggdata);
$aggregation->criteriatype = COMPLETION_CRITERIA_TYPE_ROLE;
$aggregation->setMethod($data->role_aggregation); $aggregation->setMethod($data->role_aggregation);
$aggregation->insert(); $aggregation->save();


// Update course total passing grade // Update course total passing grade
if (!empty($data->criteria_grade)) { if (!empty($data->criteria_grade)) {
Expand All @@ -152,7 +151,10 @@
} }
} }


redirect($CFG->wwwroot."/course/view.php?id=$course->id", get_string('changessaved')); add_to_log($course->id, 'course', 'completion updated', 'completion.php?id='.$course->id);

$url = new moodle_url('/course/view.php', array('id' => $course->id));
redirect($url);
} }




Expand Down
75 changes: 40 additions & 35 deletions lib/completion/completion_aggregation.php
@@ -1,5 +1,4 @@
<?php <?php

// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
Expand All @@ -19,65 +18,58 @@
/** /**
* Course completion critieria aggregation * Course completion critieria aggregation
* *
* @package moodlecore * @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd * @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz> * @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */

defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/completion/data_object.php'); require_once($CFG->libdir.'/completion/data_object.php');


/** /**
* Course completion critieria aggregation * Course completion critieria aggregation
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class completion_aggregation extends data_object { class completion_aggregation extends data_object {


/** /* @var string Database table name that stores completion aggregation information */
* DB Table
* @var string $table
*/
public $table = 'course_completion_aggr_methd'; public $table = 'course_completion_aggr_methd';


/** /**
* Array of required table fields, must start with 'id'. * Array of required table fields, must start with 'id'.
* @var array $required_fields * Defaults to id, course, criteriatype, method, value
* @var array
*/ */
public $required_fields = array('id', 'course', 'criteriatype', 'method', 'value'); public $required_fields = array('id', 'course', 'criteriatype', 'method', 'value');


/** /* @var array Array of unique fields, used in where clauses */
* Course id public $unique_fields = array('course', 'criteriatype');
* @access public
* @var int /* @var int Course id */
*/
public $course; public $course;


/** /* @var int Criteria type this aggregation method applies to, or NULL for overall course aggregation */
* Criteria type this aggregation method applies to, or NULL for overall course aggregation
* @access public
* @var int
*/
public $criteriatype; public $criteriatype;


/** /* @var int Aggregation method (COMPLETION_AGGREGATION_* constant) */
* Aggregation method (COMPLETION_AGGREGATION_* constant)
* @access public
* @var int
*/
public $method; public $method;


/** /* @var mixed Method value */
* Method value
* @access public
* @var mixed
*/
public $value; public $value;




/** /**
* Finds and returns a data_object instance based on params. * Finds and returns a data_object instance based on params.
* @static abstract
* *
* @param array $params associative arrays varname=>value * @param array $params associative arrays varname=>value
* @return object data_object instance or false if none found. * @return data_object instance of data_object or false if none found.
*/ */
public static function fetch($params) { public static function fetch($params) {
return self::fetch_helper('course_completion_aggr_methd', __CLASS__, $params); return self::fetch_helper('course_completion_aggr_methd', __CLASS__, $params);
Expand All @@ -86,7 +78,6 @@ public static function fetch($params) {


/** /**
* Finds and returns all data_object instances based on params. * Finds and returns all data_object instances based on params.
* @static abstract
* *
* @param array $params associative arrays varname=>value * @param array $params associative arrays varname=>value
* @return array array of data_object insatnces or false if none found. * @return array array of data_object insatnces or false if none found.
Expand All @@ -95,9 +86,8 @@ public static function fetch_all($params) {}


/** /**
* Set the aggregation method * Set the aggregation method
* @access public *
* @param $method int * @param int $method One of COMPLETION_AGGREGATION_ALL or COMPLETION_AGGREGATION_ANY
* @return void
*/ */
public function setMethod($method) { public function setMethod($method) {
$methods = array( $methods = array(
Expand All @@ -111,4 +101,19 @@ public function setMethod($method) {
$this->method = COMPLETION_AGGREGATION_ALL; $this->method = COMPLETION_AGGREGATION_ALL;
} }
} }


/**
* Save aggregation method to database
*
* @access public
* @return boolean
*/
public function save() {
if ($this->id) {
return $this->update();
} else {
return $this->insert();
}
}
} }

0 comments on commit ebbf509

Please sign in to comment.