bos = new BackOfficeService();
if ($id) {
$this->id = $id;
}
}
public function create() {
$created = $this->bos->createCourse($this->dataXML());
if ($created) {
$this->id = $created->id[0][0];
return $this->id;
}
return false;
}
public function save() {
return $this->bos->editCourse($this->dataXML());
}
public function delete() {
return $this->bos->deleteCourse($this->idXML());
}
public function approve() {
return $this->bos->approveCourse($this->idXML());
}
public function load($loader = NULL) {
if (!is_object($loader) && $this->id) {
$loader = $this->bos->loadCourse($this->idXML());
}
if ($loader) {
$this->type = "course";
$this->id = $loader->id[0][0];
$this->title = $loader->title[0][0];
if (isset($loader->description[0][0])) $this->description = $loader->description[0][0];
$this->owner = $loader->owner[0][0];
$this->creator = $loader->creator[0][0];
if (isset($loader->start[0][0])) $this->start = $loader->start[0][0];
if (isset($loader->end[0][0])) $this->end = $loader->end[0][0];
if (isset($loader->closes[0][0])) $this->applyuntil = $loader->closes[0][0];
if (isset($loader->provider[0][0])) $this->provider = $loader->provider[0][0];
if (isset($loader->identifier[0][0])) $this->identifier = $loader->identifier[0][0];
if (isset($loader->credits[0][0])) $this->credits = $loader->credits[0][0];
if (isset($loader->permission[0][0])) $this->permission = $loader->permission[0][0];
if (isset($loader->enrollment[0][0])) $this->enrollment_procedure = $loader->enrollment[0][0];
if (isset($loader->education_level[0][0])) $this->education_level = $loader->education_level[0][0];
if (isset($loader->language_of_instruction[0][0])) $this->language_of_instruction = $loader->language_of_instruction[0][0];
if (isset($loader->attendance_mode[0][0])) $this->attendance_mode = $loader->attendance_mode[0][0];
if (isset($loader->objective[0][0])) $this->objective = $loader->objective[0][0];
if (isset($loader->assessment[0][0])) $this->assessment = $loader->assessment[0][0];
if (isset($loader->prerequisite[0][0])) $this->prerequisite = $loader->prerequisite[0][0];
if (isset($loader->tag[0][0])) $this->course_tag = $loader->tag[0][0];
if (isset($loader->image[0]) && isset($loader->image[0]["id"])) {
$image = new Image();
$image->id = $loader->image[0]["id"][0][0];
$image->name = $loader->image[0]["name"][0][0];
$image->type = $loader->image[0]["filetype"][0][0];
$image->size = $loader->image[0]["filesize"][0][0];
$this->course_image = $image;
}
if (isset($loader->status[0][0])) $this->status = $loader->status[0][0];
$this->approved = in_array(strtolower($loader->approved[0][0]), array("false", "null")) ? false : true;
}
}
public function getURL($tab=NULL) {
if (!in_array($tab, array('view', 'info', 'announcements', 'participants', 'groups', 'assignments', 'resources', 'settings'))) {
$tab = 'view';
}
return WWW_ROOT."course/{$tab}/{$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()->getEmail()) || $this->isFacilitator()) {
return 1;
}
return 0;
}
public function canComment() {
if ($this->canEdit() || $this->isActiveLearner()) {
return true;
}
return false;
}
public function canView() {
if ($this->canEdit()) {
return true;
}
if ((int)$this->permission == 1) {
return true;
} else if ((int)$this->permission == 2 && isloggedin()){
return true;
} else if ((int)$this->permission == 3 && $this->isActiveLearner()) {
return true;
}
return false;
}
public function canAddGroup() {
if ($this->canEdit()) {
return true;
} else if ($this->isLearner()) {
return true;
}
return false;
}
public function canApprove() {
if (is_admin() && !$this->approved ) {
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 getPosts() {
$id = $this->bos->listCourseblogPosts($this->id, 0, 15);
if ($id) {
return $id;
}
return false;
}
public function getComments() {
$id = $this->bos->listCourseComments($this->id, 0, 15);
if ($id) {
return $id;
}
return false;
}
public function getCoursegroups($sorter = "") {
if ($sorter instanceof Sorter) {
$sorter = $sorter->sorterXML();
}
$id = $this->bos->listCoursegroups($this->id, 0, 15, $sorter);
if ($id) {
return $id;
}
return false;
}
public function getAssignments() {
$id = $this->bos->listAssignments($this->id, 0, 15);
if ($id) {
return $id;
}
return false;
}
public function getAssignmentsFull() {
$assignments = array();
$data = $this->bos->listAssignmentsFull($this->id);
if (isset($data->assignment[0])) {
foreach ($data->assignment as $single) {
$assignment = new Assignment();
$assignment->load((object) $single);
$assignments[$assignment->id] = $assignment;
}
}
return $assignments;
}
public function getAssignmentsWithAnswers() {
$assans = $this->bos->loadAssignmentsWithAnswers($this->idXML());
if ($assans) {
return $assans;
}
return false;
}
public function getLatestInfo() {
$info = $this->bos->loadLatestInfo($this->idXML());
if ($info) {
return $info;
}
return false;
}
function setImageFile($file) {
$image = new Image();
if ($image->upload($file)) {
$this->course_image = $image;
}
}
function idXML() {
$data = "";
$data .= "";
$data .= "".$this->id."";
$data .= "";
return $data;
}
function imageXML() {
$data = "";
if (isset($this->course_image)) {
if (isset($this->course_image->image)) {
$data .= "course_image->name."]]>";
$data .= "course_image->type."]]>";
$data .= "course_image->image)."]]>";
$data .= "".$this->course_image->size."";
}
$data .= "".$this->course_image_delete."";
}
return $data;
}
function dataXML() {
$data = "";
$data .= "";
$data .= "".$this->id."";
$data .= "title."]]>";
$data .= "description."]]>";
$data .= "start."]]>";
$data .= "end."]]>";
$data .= "applyuntil."]]>";
$data .= "".$this->provider."";
$data .= "identifier."]]>";
$data .= "credits."]]>";
$data .= "".$this->permission."";
$data .= "".$this->enrollment_procedure."";
$data .= "".$this->education_level."";
$data .= "language_of_instruction."]]>";
$data .= "attendance_mode."]]>";
$data .= "objective."]]>";
$data .= "assessment."]]>";
$data .= "prerequisite."]]>";
$data .= "course_tag."]]>";
$data .= "".$this->imageXML()."";
$data .= "".$this->status."";
$data .= "";
return $data;
}
function listFacilitatorsFull() {
$facilitators = array();
$data = $this->bos->listFacilitatorsFull($this->id);
if (isset($data->facilitator)) {
foreach ($data->facilitator as $single) {
$facilitator = new Facilitator();
$facilitator->load((object) $single);
$facilitators[$facilitator->id] = $facilitator;
}
}
return $facilitators;
}
function listOutcomesFull() {
$outcomes = array();
$data = $this->bos->listOutcomesFull($this->id);
if (isset($data->learningoutcome)) {
foreach ($data->learningoutcome as $single) {
$outcome = new LearningOutcome();
$outcome->load((object) $single);
$outcomes[$outcome->id] = $outcome;
}
}
return $outcomes;
}
function listCategoriesFull() {
global $Dippler;
return $Dippler->listCategoryTreeFull($this->id);
}
function isFacilitator($id=NULL) {
if (!$id && is_logged_in()) {
$id = get_logged_in_user()->getId();
}
// TODO Consider caching facilitator array in a variable
$facilitators = $this->listFacilitatorsFull();
if (is_array($facilitators) && sizeof($facilitators)>0) {
$user_ids = array();
foreach ($facilitators as $facilitator) {
$user_ids[] = $facilitator->user_id;
}
if (in_array($id, $user_ids)) {
return true;
}
}
return false;
}
function isLearner($email=NULL) {
if (!$email && is_logged_in()) {
$email = get_logged_in_user()->getEmail();
}
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "{$email}";
$data .= "";
$res = $this->bos->isLearner($data);
if ($res) {
return true;
}
return false;
}
function isActiveLearner($email=NULL) {
if (!$email && is_logged_in()) {
$email = get_logged_in_user()->getEmail();
}
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "{$email}";
$data .= "";
$res = $this->bos->isActiveLearner($data);
if ($res) {
return true;
}
return false;
}
function isRegistrationOpen() {
if (!is_logged_in()) {
return false;
}
if ($this->canEdit()) {
return true;
}
if ($this->isLearner()) {
return false;
}
if (get_logged_in_user()->getLevel() < 10) {
return false;
}
if ((int)$this->enrollment_procedure === 1 || (int)$this->enrollment_procedure === 2) {
if ((time() <= (int)($this->applyuntil + 86339))) {
return true;
}
}
return false;
}
/*
* 0 - unknown
* 1 - inactive (confirmation needed)
* 5 - active
*/
function getLearnerDefaultStatus() {
if ((int)$this->enrollment_procedure === 1) {
if ($this->canEdit()) {
return 5;
}
return 1;
} else if ((int)$this->enrollment_procedure === 2) {
if ($this->canEdit()) {
return 5;
}
return 0;
} else if ((int)$this->enrollment_procedure === 0) {
return 0;// XXX REGISTRATION WITH INVITATION NOT DONE YET
}
return 0;
}
function listLearners() {
return $this->bos->listLearners($this->id);
}
function listLearnersFull() {
$learners = array();
$data = $this->bos->listLearnersFull($this->id);
if (isset($data->learner)) {
foreach ($data->learner as $single) {
$learner = new Learner();
$learner->load((object) $single);
$learners[$learner->id] = $learner;
}
}
return $learners;
}
function listAllLearners() {
return $this->bos->listAllLearners($this->id);
}
function listPendingLearners() {
return $this->bos->listPendingLearners($this->id);
}
function addLearner($email) {
$learner = new Learner();
$learner->email = $email;
$learner->course = $this->id;
$learner->firstname = "";
$learner->lastname = "";
$learner->status = $this->getLearnerDefaultStatus();
return $learner->add();
}
function enrollLearner($email) {
$learner = new Learner();
$learner->email = $email;
$learner->course = $this->id;
$learner->firstname = "";
$learner->lastname = "";
$learner->status = $this->getLearnerDefaultStatus();
return $learner->enroll();
}
function removeLearner($id) {
$learner = new Learner($id);
$learner->load();
if ($learner && $learner instanceof Learner) {
return $learner->remove();
}
return false;
}
function activateLearner($id) {
$learner = new Learner($id);
$learner->load();
if ($learner && $learner instanceof Learner) {
$learner->status = 5;
return $learner->activate();
}
return false;
}
function getAssignment($id) {
$assignment = new Assignment($id);
$assignment->load();
if (($assignment->getType() == 'assignment') && ($assignment->course == $this->id)) {
return $assignment;
}
return NULL;
}
function getGroup($id) {
$group = new Coursegroup($id);
$group->load();
if (($group->getType() == 'coursegroup') && ($group->course == $this->id)) {
return $group;
}
return NULL;
}
function getLearner($id) {
$learner = new Learner($id);
$learner->load();
if (($learner->getType() == 'learner') && ($learner->course == $this->id)) {
return $learner;
}
return NULL;
}
function getPost($id) {
$post = new CourseBlogPost($id);
$post->load();
if (($post->getType() == 'courseblogpost') && ($post->course == $this->id)) {
return $post;
}
return NULL;
}
/* function getComment($id) {
$comment = new CourseBlogComment($id);
$comment->load();
if (($comment->getType() == 'courseblogcomment') && ($comment->course == $this->id)) {
return $comment;
}
return NULL;
}
*/
function getLearningOutcome($id) {
$outcome = new LearningOutcome($id);
$outcome->load();
if (($outcome->getType() == 'learningoutcome') && ($outcome->course == $this->id)) {
return $outcome;
}
return NULL;
}
// XXX This mighe need to be moved into Assignment class
function getAnswer($id) {
$answer = new Answer($id);
$answer->load();
if (($answer->getType() == 'answer') && ($answer->getAssignmentEntity()->course == $this->id)) {
return $answer;
}
return NULL;
}
function getResourceFolder($id) {
$folder = new ResourceFolder($id);
$folder->load();
if (($folder->getType() == 'folder') && ($folder->course = $this->id)) {
return $folder;
}
return NULL;
}
function getLearningResource($id) {
$resource = new LearningResource($id);
$resource->load();
if (($resource->getType() == 'resource') && ($resource->course = $this->id)) {
return $resource;
}
return NULL;
}
private function __getResourceFolderRoot() {
$this->resource_folders = array();
$this->learning_resources = array();
$loader = $this->bos->loadResourceRootFolder($this->idXML());
if (isset($loader->folders[0]["folder"])) {
foreach ($loader->folders[0]["folder"] as $folder) {
$folder["parent"] = array(array(NULL));
$folder_object = new ResourceFolder();
$folder_object->load((object) $folder);
$this->resource_folders []= $folder_object;
}
}
//var_dump($loader->resources[0]["learning_resource"]);exit;
if (isset($loader->resources[0]["learning_resource"])) {
foreach ($loader->resources[0]["learning_resource"] as $resource) {
$resource["folder"] = array(array(NULL));
$resource_object = new LearningResource();
$resource_object->load((object) $resource);
$this->learning_resources []= $resource_object;
}
}
}
function getResourceFoldersRoot() {
if ($this->resource_folders === NULL) $this->__getResourceFolderRoot();
return $this->resource_folders;
}
function getLearningResourcesRoot() {
if ($this->learning_resources === NULL) $this->__getResourceFolderRoot();
return $this->learning_resources;
}
function getFolders() {
$folders_list[0] = 'NONE';
$folders = $this->bos->listCourseResourceFolderTree($this->id);
if (isset($folders->folder)) {
foreach ($folders->folder as $folder) {
$folders_list[$folder["id"][0][0]] = $folder["title"][0][0];
$this->__folder_recur($folder, $folders_list, 1);
}
}
return $folders_list;
}
private function __folder_recur($folder, &$folders_list, $level) {
if (isset($folder['folders'][0]['folder'])) {
foreach ($folder['folders'][0]['folder'] as $folder) {
$folders_list[$folder["id"][0][0]] = str_repeat("-", $level).$folder["title"][0][0];
$this->__folder_recur($folder, $folders_list, $level+1);
}
}
}
function getProviders() {
global $Dippler;
return $Dippler->getProviders();
}
function getEducationLevels() {
$list = array();
$remote_list = $this->bos->listDictionaryEducationalLevel($this->id);
foreach ($remote_list as $item_row) {
foreach ($item_row as $item) {
$list[$item["id"][0][0]] = $item["word"][0][0];
}
}
return $list;
}
function getLanguagesOfInstructions() {
$list = array();
$remote_list = $this->bos->listDictionaryLanguageOfInstructions($this->id);
foreach ($remote_list as $item_row) {
foreach ($item_row as $item) {
$list[$item["id"][0][0]] = $item["word"][0][0];
}
}
return $list;
}
function getAttendanceModes() {
return array(_('Campus'), _('Distance with attendance'), _('Distance without attendance'),_('Face-to-face non-campus'),_('Mixed mode'),_('Online (no attendance)'),_('Work-based'));
}
function getPermissions() {
return array(_('Course participants'), _('Logged in'), _('All'));
}
function getEnrollmentProcedures() {
return array(_('By the facilitator'), _('Moderated'), _('Open'));
}
function getStatuses() {
return array(_('Preparation'), _('Active'), _('Finished'));
}
function getImageURL($size = 'small') {
$sizes = array('tiny', 'small', 'medium', 'large');
if (!in_array($size, $sizes)) {
$size = 'small';
}
if (isset($this->course_image) && $this->course_image instanceof Image) {
return WWW_ROOT."images/image.php?id={$this->course_image->id}";
}
return WWW_ROOT."views/graphics/course_icon_{$size}.png";
}
function getCurrentMembersPreset() {
$preset = array();
$learners = $this->listLearnersFull();
if (is_array($learners) && sizeof($learners)>0) {
foreach ($learners as $learner) {
if ($learner->email == get_logged_in_user()->email) {
$preset[] = $learner->id;
}
}
}
return $preset;
}
public function getActivities($offset=0, $limit=10) {
$activities = array();
$data = $this->bos->listActivities($this->id, $offset, $limit);
if (isset($data->activity[0])) {
foreach ($data->activity as $single) {
$activity = new Activity();
$activity->load((object) $single);
$activities[$activity->id] = $activity;
}
}
return $activities;
}
/*
* Bulk Actions
*/
function bulkDeleteGroups($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids) > 0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkDeleteCoursegroups($data);
}
}
return false;
}
function bulkDeleteAssignments($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids)>0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkDeleteAssignments($data);
}
}
return false;
}
function bulkDeleteCategories($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids)>0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkDeleteCategories($data);
}
}
return false;
}
function bulkActivateLearners($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids) > 0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkActivateLearners($data);
}
}
return false;
}
function bulkRemoveLearners($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids) > 0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkRemoveLearners($data);
}
}
return false;
}
function bulkDeleteLearningOutcomes($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && sizeof($ids) > 0) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
foreach ($ids as $id) {
$data .= "{$id}";
}
$data .= "";
$data .= "";
return $this->bos->bulkDeleteLearningOutcomes($data);
}
}
return false;
}
function bulkDeleteResources($ids) {
if ($this->canEdit()) {
if ($ids && is_array($ids) && ((isset($ids['folders']) && is_array($ids['folders']) && $ids['folders'] > 0) || (isset($ids['resources']) && is_array($ids['resources']) && sizeof($ids['resources']) > 0))) {
$data = "";
$data = "";
$data .= "{$this->id}";
$data .= "";
if (isset($ids['folders']) && is_array($ids['folders']) && sizeof($ids['folders']) > 0) {
foreach ($ids['folders'] as $fid) {
$data .= "{$fid}";
}
}
$data .= "";
$data .= "";
if (isset($ids['resources']) && is_array($ids['resources']) && sizeof($ids['resources'] > 0)) {
foreach ($ids['resources'] as $rid) {
$data .= "{$rid}";
}
}
$data .= "";
$data .= "";
return $this->bos->bulkDeleteResources($data);
}
}
return false;
}
/*
* Facilitator search
*/
function searchFacilitators($term) {
$xml = "";
$xml .= "";
$xml .= "{$this->id}";
$xml .= "";
$xml .= "";
$data = $this->bos->searchFacilitators($xml);
if (isset($data->user[0])) {
return $data->user;
}
return NULL;
}
}
?>