bos =& $Dippler->backoffice; if ($id) { $this->id = $id; } } public function create() { $created = $this->bos->createCoursegroup($this->dataXML()); if ($created) { $this->id = $created->id[0][0]; return $this->id; } return false; } public function save() { return $this->bos->editCoursegroup($this->dataXML()); } public function delete() { return $this->bos->deleteCoursegroup($this->idXML()); } public function load($loader = false) { if (!$loader) $loader = $this->bos->loadCoursegroup($this->idXML()); if ($loader) { $this->type = "coursegroup"; $this->id = $loader->id[0][0]; $this->title = $loader->title[0][0]; $this->description = $loader->description[0][0]; $this->workspace = $loader->workspace[0][0]; $this->owner = $loader->creator[0][0]; $this->created = $loader->created[0][0]; $this->course = $loader->course[0][0]; if (array_key_exists("member-id", $loader->{"member-ids"}[0])) $this->setMembers($loader->{"member-ids"}[0]["member-id"]); } } public function getURL() { return WWW_ROOT."course/groups/{$this->course}/group/{$this->id}"; } public function getType() { return $this->type; } public function canEdit() { if (!is_logged_in()){ return 0; } if (is_admin() || ($this->getOwner() == get_logged_in_user_id()) || $this->getCourseEntity()->canEdit()) { return 1; } return 0; } public function getId() { return $this->id; } public function getOwner() { return $this->owner; } public function getOwnerEntity() { if (!isset($this->owner_entity)) { $user = new User($this->owner); $user->load(); $this->owner_entity = $user; return $user; } return $this->owner_entity; } public function getCourse() { return $this->course; } public function getCourseEntity() { if (!isset($this->course_entity)) { $course = new Course($this->course); $course->load(); $this->course_entity = $course; return $course; } return $this->course_entity; } public function getMembers() { return $this->members; } public function getMemberObjects($sort_by_lastname = false) { $returned = array(); if (is_array($this->members) && sizeof($this->members)>0) { foreach ($this->members as $single) { $member = new Learner($single); $member->load(); $returned[] = $member; } if ($sort_by_lastname && sizeof($returned)>0) { $tmp = array(); foreach ($returned as $single) { $tmp[] = array('lastname' => $single->lastname, 'object' => $single); } uasort($tmp, array('self', '__member_objects_cmp')); $returned = array(); foreach ($tmp as $single) { $returned[] = $single['object']; } } } return $returned; } private function __member_objects_cmp($a, $b) { if ($a['lastname'] == $b['lastname']) { return 0; } return ($a['lastname'] < $b['lastname']) ? 1 : -1; } private function setMembers($members) { $member_ids = array(); foreach ($members as $id) { $member_ids []= $id[0]; } $this->members = $member_ids; } private function getMembersXML() { $xml = ""; foreach ($this->members as $id) { $xml .= "{$id}"; } return $xml; } function idXML() { $data = ""; $data .= ""; $data .= "".$this->id.""; $data .= ""; return $data; } function dataXML() { $data = ""; $data .= ""; $data .= "".$this->id.""; $data .= "<![CDATA[".$this->title."]]>"; $data .= "description."]]>"; $data .= "workspace."]]>"; $data .= "".$this->course.""; $data .= "".$this->owner.""; $data .= "".$this->getMembersXML().""; $data .= ""; return $data; } } ?>