Updated aggregation for junctions
This commit is contained in:
parent
2ef8b65421
commit
917304e830
|
@ -253,7 +253,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
||||||
* @param int $userid Id of user to check completion for
|
* @param int $userid Id of user to check completion for
|
||||||
* @return int Aggregated completion as completion class constant
|
* @return int Aggregated completion as completion class constant
|
||||||
*/
|
*/
|
||||||
public function aggregate_junction(array $completion, studyitem $studyitem = null, $userid = 0) {
|
public function aggregate_junction(array $completion, studyitem $studyitem, $userid = 0) {
|
||||||
// Aggregate multiple incoming states into one junction or finish.
|
// Aggregate multiple incoming states into one junction or finish.
|
||||||
// Possible states:.
|
// Possible states:.
|
||||||
// - completion::EXCELLENT - All incoming states are excellent.
|
// - completion::EXCELLENT - All incoming states are excellent.
|
||||||
|
@ -263,25 +263,43 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
||||||
// - completion::INCOMPLETE - All incoming states are incomplete.
|
// - completion::INCOMPLETE - All incoming states are incomplete.
|
||||||
// - completion::PROGRESS - All other states.
|
// - completion::PROGRESS - All other states.
|
||||||
|
|
||||||
|
$method = strtoupper($studyitem->conditions()); // One of ANY or ALL.
|
||||||
|
|
||||||
// First count all states.
|
// First count all states.
|
||||||
$statecount = completion::count_states($completion);
|
$statecount = completion::count_states($completion);
|
||||||
$total = count($completion);
|
$total = count($completion);
|
||||||
|
|
||||||
if ( $total == $statecount[completion::EXCELLENT]) {
|
if($method == "ANY"){
|
||||||
return completion::EXCELLENT;
|
if ( $statecount[completion::EXCELLENT] >= 1 ) {
|
||||||
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
return completion::EXCELLENT;
|
||||||
+ $statecount[completion::GOOD]) ) {
|
} else if ( $statecount[completion::GOOD] >= 1 ) {
|
||||||
return completion::GOOD;
|
return completion::GOOD;
|
||||||
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
} else if ( $statecount[completion::COMPLETED] >= 1 ) {
|
||||||
+ $statecount[completion::GOOD]
|
return completion::COMPLETED;
|
||||||
+ $statecount[completion::COMPLETED]) ) {
|
} else if ( $statecount[completion::PROGRESS] >= 1 ) {
|
||||||
return completion::COMPLETED;
|
return completion::PROGRESS;
|
||||||
} else if ( $statecount[completion::FAILED]) {
|
} else if ( $statecount[completion::FAILED] >= 1) {
|
||||||
return completion::FAILED;
|
return completion::FAILED;
|
||||||
} else if ( $total == $statecount[completion::INCOMPLETE]) {
|
} else {
|
||||||
return completion::INCOMPLETE;
|
return completion::INCOMPLETE;
|
||||||
} else {
|
}
|
||||||
return completion::PROGRESS;
|
} else { /* ALL (default) */
|
||||||
|
if ( $total == $statecount[completion::EXCELLENT]) {
|
||||||
|
return completion::EXCELLENT;
|
||||||
|
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
||||||
|
+ $statecount[completion::GOOD]) ) {
|
||||||
|
return completion::GOOD;
|
||||||
|
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
||||||
|
+ $statecount[completion::GOOD]
|
||||||
|
+ $statecount[completion::COMPLETED]) ) {
|
||||||
|
return completion::COMPLETED;
|
||||||
|
} else if ( $statecount[completion::FAILED]) {
|
||||||
|
return completion::FAILED;
|
||||||
|
} else if ( $total == $statecount[completion::INCOMPLETE]) {
|
||||||
|
return completion::INCOMPLETE;
|
||||||
|
} else {
|
||||||
|
return completion::PROGRESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
||||||
* @param int $userid Id of user to check completion for
|
* @param int $userid Id of user to check completion for
|
||||||
* @return int Aggregated completion as completion class constant
|
* @return int Aggregated completion as completion class constant
|
||||||
*/
|
*/
|
||||||
public function aggregate_junction(array $completion, studyitem $studyitem = null, $userid = 0) {
|
public function aggregate_junction(array $completion, studyitem $studyitem, $userid = 0) {
|
||||||
// Aggregate multiple incoming states into one junction or finish.
|
// Aggregate multiple incoming states into one junction or finish.
|
||||||
// Possible states:.
|
// Possible states:.
|
||||||
// - completion::EXCELLENT - All incoming states are excellent.
|
// - completion::EXCELLENT - All incoming states are excellent.
|
||||||
|
@ -203,25 +203,43 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
||||||
// - completion::INCOMPLETE - All incoming states are incomplete.
|
// - completion::INCOMPLETE - All incoming states are incomplete.
|
||||||
// - completion::PROGRESS - All other states.
|
// - completion::PROGRESS - All other states.
|
||||||
|
|
||||||
|
$method = strtoupper($studyitem->conditions()); // One of ANY or ALL.
|
||||||
|
|
||||||
// First count all states.
|
// First count all states.
|
||||||
$statecount = completion::count_states($completion);
|
$statecount = completion::count_states($completion);
|
||||||
$total = count($completion);
|
$total = count($completion);
|
||||||
|
|
||||||
if ( $total == $statecount[completion::EXCELLENT]) {
|
if($method == "ANY"){
|
||||||
return completion::EXCELLENT;
|
if ( $statecount[completion::EXCELLENT] >= 1 ) {
|
||||||
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
return completion::EXCELLENT;
|
||||||
+ $statecount[completion::GOOD]) ) {
|
} else if ( $statecount[completion::GOOD] >= 1 ) {
|
||||||
return completion::GOOD;
|
return completion::GOOD;
|
||||||
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
} else if ( $statecount[completion::COMPLETED] >= 1 ) {
|
||||||
+ $statecount[completion::GOOD]
|
return completion::COMPLETED;
|
||||||
+ $statecount[completion::COMPLETED]) ) {
|
} else if ( $statecount[completion::PROGRESS] >= 1 ) {
|
||||||
return completion::COMPLETED;
|
return completion::PROGRESS;
|
||||||
} else if ( $statecount[completion::FAILED]) {
|
} else if ( $statecount[completion::FAILED] >= 1) {
|
||||||
return completion::FAILED;
|
return completion::FAILED;
|
||||||
} else if ( $total == $statecount[completion::INCOMPLETE]) {
|
} else {
|
||||||
return completion::INCOMPLETE;
|
return completion::INCOMPLETE;
|
||||||
} else {
|
}
|
||||||
return completion::PROGRESS;
|
} else { /* ALL (default) */
|
||||||
|
if ( $total == $statecount[completion::EXCELLENT]) {
|
||||||
|
return completion::EXCELLENT;
|
||||||
|
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
||||||
|
+ $statecount[completion::GOOD]) ) {
|
||||||
|
return completion::GOOD;
|
||||||
|
} else if ( $total == ( $statecount[completion::EXCELLENT]
|
||||||
|
+ $statecount[completion::GOOD]
|
||||||
|
+ $statecount[completion::COMPLETED]) ) {
|
||||||
|
return completion::COMPLETED;
|
||||||
|
} else if ( $statecount[completion::FAILED]) {
|
||||||
|
return completion::FAILED;
|
||||||
|
} else if ( $total == $statecount[completion::INCOMPLETE]) {
|
||||||
|
return completion::INCOMPLETE;
|
||||||
|
} else {
|
||||||
|
return completion::PROGRESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
||||||
* @return int Aggregated completion as completion class constant
|
* @return int Aggregated completion as completion class constant
|
||||||
*/
|
*/
|
||||||
protected function aggregate_completion(array $a, $condition = "50") {
|
protected function aggregate_completion(array $a, $condition = "50") {
|
||||||
if (in_array($condition, ['ALL', '67', '50', 'ANY'])) {
|
if (in_array(strtoupper($condition), ['ALL', '67', '50', 'ANY'])) {
|
||||||
// Condition is one of the valid conditions.
|
// Condition is one of the valid conditions.
|
||||||
$ccompleted = 0;
|
$ccompleted = 0;
|
||||||
$cexcellent = 0;
|
$cexcellent = 0;
|
||||||
|
|
|
@ -84,7 +84,7 @@ class studyitem {
|
||||||
* Return the condition string for this item
|
* Return the condition string for this item
|
||||||
*/
|
*/
|
||||||
public function conditions() : string {
|
public function conditions() : string {
|
||||||
return $this->r->conditions;
|
return (!empty($this->r->conditions)) ? $this->r->conditions : "ALL";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,7 +198,7 @@ class studyitem {
|
||||||
$model = [
|
$model = [
|
||||||
'id' => $this->r->id, // Id is needed in export model because of link references.
|
'id' => $this->r->id, // Id is needed in export model because of link references.
|
||||||
'type' => $this->valid() ? $this->r->type : self::INVALID,
|
'type' => $this->valid() ? $this->r->type : self::INVALID,
|
||||||
'conditions' => $this->r->conditions,
|
'conditions' => $this->conditions(),
|
||||||
'slot' => $this->r->slot,
|
'slot' => $this->r->slot,
|
||||||
'layer' => $this->r->layer,
|
'layer' => $this->r->layer,
|
||||||
'span' => $this->r->span,
|
'span' => $this->r->span,
|
||||||
|
@ -214,9 +214,6 @@ class studyitem {
|
||||||
unset($model["layer"]);
|
unset($model["layer"]);
|
||||||
unset($model["continuation_id"]);
|
unset($model["continuation_id"]);
|
||||||
$model["connections"] = []; // In export mode, connections is just an array of outgoing connections.
|
$model["connections"] = []; // In export mode, connections is just an array of outgoing connections.
|
||||||
if (!isset($this->r->conditions)) {
|
|
||||||
unset($model["conditions"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add course link if available.
|
// Add course link if available.
|
||||||
|
@ -548,14 +545,14 @@ class studyitem {
|
||||||
}
|
}
|
||||||
} else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) {
|
} else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) {
|
||||||
// Completion of the linked items, according to the rule.
|
// Completion of the linked items, according to the rule.
|
||||||
$incompleted = [];
|
$incomingcompletions = [];
|
||||||
// Retrieve incoming connections.
|
// Retrieve incoming connections.
|
||||||
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
|
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
|
||||||
foreach ($incoming as $conn) {
|
foreach ($incoming as $conn) {
|
||||||
$item = self::find_by_id($conn->from_id);
|
$item = self::find_by_id($conn->from_id);
|
||||||
$incompleted[] = $item->completion($userid);
|
$incomingcompletions[] = $item->completion($userid);
|
||||||
}
|
}
|
||||||
return $this->aggregator->aggregate_junction($incompleted, $this, $userid);
|
return $this->aggregator->aggregate_junction($incomingcompletions, $this, $userid);
|
||||||
} else if (strtolower($this->r->type) == 'badge') {
|
} else if (strtolower($this->r->type) == 'badge') {
|
||||||
global $DB;
|
global $DB;
|
||||||
// Badge awarded.
|
// Badge awarded.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user