Made some code less confusing
This commit is contained in:
parent
bcb288bac8
commit
9caf652ff5
|
@ -567,7 +567,7 @@ class studentstudyplanservice extends \external_api {
|
||||||
foreach ($records as $r) {
|
foreach ($records as $r) {
|
||||||
$studyplan = studyplan::find_by_id($r->studyplan_id);
|
$studyplan = studyplan::find_by_id($r->studyplan_id);
|
||||||
if (has_capability(self::CAP_COACH,$studyplan->context(),$USER)) {
|
if (has_capability(self::CAP_COACH,$studyplan->context(),$USER)) {
|
||||||
$list[] = $studyplan->simple_model($userid,true);
|
$list[] = $studyplan->simple_model_coach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
|
|
|
@ -277,7 +277,7 @@ class studyplan {
|
||||||
* Webservice model for basic info
|
* Webservice model for basic info
|
||||||
* @return array Webservice data model
|
* @return array Webservice data model
|
||||||
*/
|
*/
|
||||||
public function simple_model($userid=null,$coachingoverview=false) {
|
public function simple_model($userid=null) {
|
||||||
global $USER;
|
global $USER;
|
||||||
$pages = [];
|
$pages = [];
|
||||||
foreach ($this->pages() as $p) {
|
foreach ($this->pages() as $p) {
|
||||||
|
@ -300,24 +300,30 @@ class studyplan {
|
||||||
'suspended' => boolval($this->r->suspended),
|
'suspended' => boolval($this->r->suspended),
|
||||||
];
|
];
|
||||||
if(isset($userid)) {
|
if(isset($userid)) {
|
||||||
if(!$coachingoverview) {
|
$model["userid"] = $userid;
|
||||||
$model["userid"] = $userid;
|
$model["progress"] = $this->scanuserprogress($userid);
|
||||||
$model["progress"] = $this->scanuserprogress($userid);
|
$model['amteaching'] = teachingfinder::is_teaching_studyplan($this,$userid);
|
||||||
$model['amteaching'] = teachingfinder::is_teaching_studyplan($this,$userid);
|
|
||||||
} else {
|
|
||||||
$users = $this->find_linked_userids();
|
|
||||||
$sum = 0;
|
|
||||||
foreach ( $users as $uid ) {
|
|
||||||
$sum += $this->scanuserprogress($uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
$model["progress"] = $sum / count($users);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Webservice model for basic info in coach mode
|
||||||
|
* @return array Webservice data model
|
||||||
|
*/
|
||||||
|
public function simple_model_coach() {
|
||||||
|
$model = $this->simple_model();
|
||||||
|
$users = $this->find_linked_userids();
|
||||||
|
$sum = 0;
|
||||||
|
foreach ( $users as $uid ) {
|
||||||
|
$sum += $this->scanuserprogress($uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
$model["progress"] = $sum / count($users);
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Webservice structure for editor info
|
* Webservice structure for editor info
|
||||||
* @param int $value Webservice requirement constant
|
* @param int $value Webservice requirement constant
|
||||||
|
|
Loading…
Reference in New Issue
Block a user