bos = new BackOfficeService(); if ($id) { $this->id = $id; } } public function create() { $created = $this->bos->createAssignment($this->dataXML()); if ($created) { $this->id = $created->id[0][0]; return $this->id; } return false; } public function save() { return $this->bos->editAssignment($this->dataXML()); } public function delete() { return $this->bos->deleteAssignment($this->idXML()); } public function load($loader=false) { if (!$loader) { $loader = $this->bos->loadAssignment($this->idXML()); } if ($loader) { $this->type = "assignment"; $this->id = $loader->id[0][0]; $this->subtype = $loader->subtype[0][0]; $this->title = $loader->title[0][0]; $this->description = $loader->description[0][0]; $this->structure = json_decode($loader->structure[0][0]); $this->maxpoints = $loader->maxpoints[0][0]; $this->start = $loader->start[0][0]; $this->deadline = $loader->deadline[0][0]; if ($loader->late_submission[0][0] && $loader->late_submission[0][0] == 'true') $this->late_submission = 1; if ($loader->submission_visibility[0][0] && $loader->submission_visibility[0][0] == 'true') $this->submission_visibility = 1; $this->setTargetGroup($loader->{'target-group'}); $this->owner = $loader->creator[0][0]; $this->created = $loader->created[0][0]; $this->course = $loader->course[0][0]; if (isset($loader->answers[0]['answer-id'])) { $this->answers = $loader->answers[0]['answer-id'][0]; } if (isset($loader->tags[0]["tag"])) { foreach ($loader->tags[0]["tag"] as $tag) { $this->tags []= $tag["name"][0][0]; } } if (isset($loader->learningoutcomes[0]["learningoutcome"])) { foreach ($loader->learningoutcomes[0]["learningoutcome"] as $single) { $o = new LearningOutcome(); $o->load((object) $single); $this->outcomes[$o->id] = $o; } } } } public function loadAnswers() { return $this->bos->loadAnswers($this->idXML()); } public function getURL() { return WWW_ROOT."course/assignments/{$this->course}/assignment/{$this->id}/edit"; } public function getSubmissionsURL() { return WWW_ROOT."course/assignments/{$this->course}/assignment/{$this->id}/submissions"; } public function getType() { return $this->type; } public function canEdit() { if (is_admin() || (is_logged_in() && $this->owner == get_logged_in_user()->getEmail())) { 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; } function setTargetGroup($tg) { if (array_key_exists("group-id", $tg[0])) { if (is_array($tg[0]["group-id"])) { foreach ($tg[0]["group-id"] as $tagr) { $this->target_group []= $tagr[0]; } } } } private function getTargetXML() { $xml = ""; foreach ($this->target_group as $id) { $xml .= "{$id}"; } return $xml; } public function getAnswers() { return $this->answers; } public function getLearnersAnswers() { // Structured learner_id => answer $answers = array(); $data = $this->bos->loadAnswers($this->idXML()); if (isset($data->learners[0])) { foreach ($data->learners as $single) { if (isset($single['learner'][0]['answer'][0])) { $answer = new Answer(); $answer->load((object) $single['learner'][0]['answer'][0]); $answers[$single['learner'][0]['id']['0']['0']] = $answer; } } } return $answers; } public function getSubtypeString() { $subtypes = array("blogpost"=>_("Blog Post"), "reflection"=>_("Reflection"), "offline"=>_("Offline Task"), "exercise"=>_("Exercise"), "file"=>_("Upload File"), "test"=>_("Test")); return $subtypes[$this->subtype]; } function idXML() { $data = ""; $data .= ""; $data .= "{$this->id}"; $data .= ""; return $data; } function outcomesXML() { $data = ""; foreach ($this->outcomes as $outcome) { $data .= ""; $data .= "id."]]>"; $data .= ""; } return $data; } function tagsXML() { $data = ""; foreach ($this->tags as $tag) { $data .= ""; $data .= ""; $data .= ""; } return $data; } function dataXML() { $tags = $this->tagsXML(); $outcomes = $this->outcomesXML(); $data = ""; $data .= ""; $data .= "{$this->id}"; $data .= "subtype}]]>"; $data .= "<![CDATA[{$this->title}]]>"; $data .= "description}]]>"; $data .= "structure}]]>"; $data .= "maxpoints}]]>"; $data .= "start}]]>"; $data .= "deadline}]]>"; $data .= "".$this->getTargetXML().""; $data .= "{$this->submission_visibility}"; $data .= "{$this->late_submission}"; $data .= "".$this->course.""; $data .= "".$this->owner.""; $data .= "{$tags}"; $data .= "{$outcomes}"; $data .= ""; return $data; } } ?>