nodeName; $type = $node->nodeType; if ( $node->hasChildNodes() ) { $children = $node->childNodes; for ( $i=0; $i<$children->length; $i++ ) { $subresult = array(); $item = $children->item($i); $nodename = $item->nodeName; if ( $item->nodeType == XML_TEXT_NODE || $item->nodeType == XML_CDATA_SECTION_NODE) { $result[] = $item->nodeValue; } else { _helper_recur($subresult, $item); if ( $item->hasAttributes() ) { $atts = $item->attributes; if ( !is_null($atts) ) { $subresult['@attributes'] = array(); foreach( $atts as $index=>$attr ) { $subresult['@attributes'][$attr->name] = $attr->value; } } } $result[$nodename][] = $subresult; } } } } function to_object($xmlstring) { $dom = new DOMDocument(); $dom->loadXML($xmlstring); $dom->normalizeDocument(); $result = array(); if ($dom->hasChildNodes() ) { $children = $dom->childNodes; for ( $i=0; $i<$children->length; $i++ ) { _helper_recur($result, $children->item($i) ); } } return (object) $result; } function casttoclass($class, $object) { return unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', serialize($object))); } function get_backoffice_session() { if (isset($_SESSION['backoffice_session'])) { return casttoclass('BackOfficeSession', $_SESSION['backoffice_session']); } return false; } class BackOfficeService { public $statusPat = '/(.*?)<\/status>/'; public $uidPat = '/(.*?)<\/uid>/'; public $sessIdPat = '/(.*?)<\/sessionId>/'; public $timeZonePat = '/(.*?)<\/timeZone>/'; public $c = NULL; public $sid = NULL; public $timeZone = 0; public $status = 0; private $typeID = 4; private $_wsdl = NULL; private $_user = NULL; private $_pass = NULL; public function __construct() { $this->c = new SoapClient(DBOS_WSDL, array('encoding'=>'UTF-8')); $backoffice_session = get_backoffice_session(); $sid = NULL; if ($backoffice_session) { $sid = $backoffice_session->getSessionId(); } if (isset($sid)) { $this->sid = $sid; } else { $this->connect(); } } /** * This because WDSL caching, we do not want to turn of WSDL cache * so we need isAlive method, to check if BOS is still there * if we don't do that and WSDL is cached, we'll get nasty exception. * * This case applies when user is logged into Dippler and then BOS suddenly goes missing * i.e shutdown glassfish * * We could actually call anything at this point, this isAlive method is just a dummy * we could call coursemanager for example, which would have same effect. */ public function isAlive() { if ( !is_null( $this->c ) ) { $resp = $this->c->isAlive(); if ( !is_soap_fault( $resp ) ) { $xml = @new SimpleXMLElement( $resp->return ); if ( $xml ) { return (string) $xml->version; } return false; } } throw new Exception("BOS IS DEAD"); } public function __destruct() { if (isset($this->sid) && $this->sid) { if (!isset($_SESSION['backoffice_session'])) { $this->disconnect(); } elseif (isset($_SESSION['backoffice_session'])) { if (isset($_SESSION['__bossid']) && ($_SESSION['__bossid'] != $this->sid)) { $this->disconnect(); } } } } /** * Returns 0 on success or error code from BackOffice * */ public function connect() { $res = $this->newSession(DBOS_CLIENT, DBOS_PASSWORD); $stat = $this->_getStatus($res); if ( $stat == "0" ) { $this->sid = $this->_getSessionId($res); $this->timeZone = $this->_getTimeZone($res); return 0; } else { $this->status = (int) $stat; return (int) $stat; } } public function disconnect() { $this->closeSession(); } public function setSid($sid) { $this->sid = $sid; } function statusHasError($status) { if ($status > 0) { if ($status == 1) { global $Dippler; forward($Dippler->add_action_tokens_to_url(WWW_ROOT."actions/user/logout.php")); } return true; } return false; } /********************************** * BackOfficeService methods * **********************************/ /* * Session * */ public function newSession($uid, $pwd) { // XXX This will throw an error in case of bad network connection $res = $this->c->newClientSession(array('uid' => $uid, 'pwd' => $pwd)); return $res->return; } public function closeSession() { try { // Suppressing everything $res = @$this->c->closeSession(array('sessId' => $this->sid)); } catch (Exception $e) { // other instance must have already closed connection } } /* * Organization * */ public function getOrganizationName() { $res = $this->c->organizationManager(array('sessId' => $this->sid, 'action' => 'GET_NAME')); $org = to_object($res->return); if ($this->statusHasError($org->status[0][0])) { return false; } else { return $org->data[0][0]; } } public function setOrganizationName($data) { $res = $this->c->organizationManager(array('sessId' => $this->sid, 'action' => 'SET_NAME', 'data' => $data)); $org = to_object($res->return); if ($this->statusHasError($org->status[0][0])) { return false; } else { return true; } } public function getOrganizationUnapprovedUsersCount() { $res = $this->c->organizationManager(array('sessId' => $this->sid, 'action' => 'UNAPPROVED_USERS_COUNT')); $object = to_object($res->return); if ($this->statusHasError($object->status[0][0])) { return false; } else { return $object->data[0]["count"][0][0]; } } /**************************************** * BackOffice User Service methods * ****************************************/ public function userManager($action, $data, $datatype="user") { $res = $this->c->userManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $user = to_object($res->return); if ($this->statusHasError($user->status[0][0])) { return false; } else if ($datatype != ''){ return (object) $user->data[0][$datatype][0]; } else { return true; } } public function loadUser($data) { return $this->userManager('LOAD', $data); } public function approveUser($data) { return $this->userManager('APPROVE', $data); } public function unApproveUser($data) { return $this->userManager('UNAPPROVE', $data); } public function changeUserRole($data) { return $this->userManager('CHANGE_ROLE', $data); } public function deleteUser($data) { return $this->userManager('DELETE', $data, ''); } public function changePassword($data) { return $this->userManager('CHANGE_PASSWORD', $data); } public function changeEmail($data) { return $this->userManager('CHANGE_EMAIL', $data); } public function authenticateUser($email, $pass) { $res = $this->c->authenticateUser(array('sessId' => $this->sid, 'email' => $email, 'password' => $pass)); $res_obj = to_object($res->return); if ($this->statusHasError($res_obj->status[0][0])) { return false; } else { $user = new User(); $user->load($res_obj); if (strcmp($user->getEmail(),$email)) { return false; } else { return $user; } } } public function checkUser($email) { $res = $this->c->checkUser(array('sessId' => $this->sid, 'email' => $email)); $status = $this->_getStatus($res->return); if ($this->statusHasError($status)) { return false; } else { return true; } } public function searchUsers($term) { $res = $this->c->searchUser(array('sessId' => $this->sid, 'term' => $term)); $users = to_object($res->return); if ($this->statusHasError($users->status[0][0])) { return false; } else { $user_array = array(); if (isset($users->data[0]["users"][0]["user"]) && is_array($users->data[0]["users"][0]["user"]) && sizeof($users->data[0]["users"][0]["user"])>0) { foreach( $users->data[0]["users"][0]["user"] as $user) { $user_array []= array('id' => $user["id"][0][0], 'name' => $user["name"][0][0], 'email' => $user["email"][0][0]); } } return $user_array; } } public function addUser($username, $email, $password, $firstname, $lastname, $level) { $res = $this->c->addUser(array('sessId' => $this->sid, 'username' => $username, 'email' => $email, 'password' => $password, 'firstname' => $firstname, 'lastname' => $lastname, 'level' => $level)); $ret = to_object($res->return); if ($this->statusHasError($ret->status[0][0])) { return false; } else { return true; } } /****************************************** * BackOffice Course Service methods * ******************************************/ /****************** * Listing Manager * ******************/ public function listingManager($parent="", $object, $offset = 0, $limit = 10, $sorter = "") { $res = $this->c->listingManager(array('sessId' => $this->sid, 'parent' => $parent, 'object' => $object, 'offset' => $offset, 'limit' => $limit, 'sorter' => $sorter)); $res_obj = to_object($res->return); if ($this->statusHasError($res_obj->status[0][0])) { return false; } else { $ids = array(); $data = $res_obj->data[0]; if (!empty($data)) { foreach($data["id"] as $id) { $ids []= $id[0]; } } return $ids; } } public function extendedListingManager($parent="", $object, $datatype, $offset = 0, $limit = 10, $sorter = "", $pages_count = false) { $res = $this->c->listingManager(array('sessId' => $this->sid, 'parent' => $parent, 'object' => $object, 'offset' => $offset, 'limit' => $limit, 'sorter' => $sorter)); $res_obj = to_object($res->return); if ($this->statusHasError($res_obj->status[0][0])) { return false; } else if ($datatype != '' && $pages_count == true) { $pages = 1; if (isset($res_obj->data[0][$datatype][0]["@attributes"]["pages"])) { $pages = $res_obj->data[0][$datatype][0]["@attributes"]["pages"]; } $objects = (object) $res_obj->data[0][$datatype][0]; return array("pages" => $pages, "objects" => $objects); } else if ($datatype != ''){ return (object) $res_obj->data[0][$datatype][0]; } else { return true; } } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCoursegroups($course_id, $offset = 0, $limit = 0, $sorter="") { return $this->listingManager($course_id, "COURSEGROUP", $offset, $limit, $sorter); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listAssignments($course_id, $offset = 0, $limit = 0) { return $this->listingManager($course_id, "ASSIGNMENT", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCourseblogPosts($course_id, $offset = 0, $limit = 0) { return $this->listingManager($course_id, "BLOGPOST", $offset, $limit); } public function listCourseblogComments($post_id, $offset = 0, $limit = 10) { return $this->listingManager($post_id, "COMMENT", $offset, $limit); } public function listCourseComments($course_id, $offset = 0, $limit = 10) { return $this->listingManager($course_id, "COURSE_COMMENTS", $offset, $limit); } public function listLearners($course_id, $offset = 0, $limit = 10) { return $this->listingManager($course_id, "LEARNER", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listAllLearners($course_id, $offset = 0, $limit = 0) { return $this->listingManager($course_id, "LEARNER_ALL", $offset, $limit); } public function listPendingLearners($course_id, $offset = 0, $limit = 10) { return $this->listingManager($course_id, "LEARNER_PENDING", $offset, $limit); } public function listUsers($offset = 0, $limit = 0) { return $this->listingManager("", "USER", $offset, $limit); } public function listUsersNotApproved($offset = 0, $limit = 0) { return $this->listingManager("", "USER_NOT_APPROVED", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCourseResourceFolderTree($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "RESOURCE_FOLDER_TREE", "foldertree", $offset, $limit); } public function listActivities($course_id, $offset = 0, $limit = 10) { return $this->extendedListingManager($course_id, "ACTIVITY", "activities", $offset, $limit); } public function listDictionaryProvider($course_id=0, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "DICTIONARY_LIST_PROVIDER", "provider", $offset, $limit); } public function listDictionaryLanguageOfInstructions($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "DICTIONARY_LIST_LANGUAGEOFINSTRUCTIONS", "languageofinstructions", $offset, $limit); } public function listDictionaryEducationalLevel($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "DICTIONARY_LIST_EDUCATIONALLEVEL", "educationallevel", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listLearnersFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'LEARNER_FULL', 'learners', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listAllLearnersFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'LEARNER_ALL_FULL', 'learners', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listFacilitatorsFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'FACILITATOR_FULL', 'facilitators', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listOutcomesFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'OUTCOME_FULL', 'learningoutcomes', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCategoriesTreeFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'CATEGORY_TREE_FULL', 'categories', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCategoriesFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'CATEGORY_FULL', 'categories', $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listAssignmentsFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, 'ASSIGNMENT_FULL', 'assignments', $offset, $limit); } public function listCoursesFull($offset = 0, $limit = 10) { return $this->extendedListingManager("", "ORGANIZATION_COURSE_FULL", "courses", $offset, $limit, "", true); } public function listMyCoursesFull($offset = 0, $limit = 10) { return $this->extendedListingManager("", "ORGANIZATION_MYCOURSE_FULL", "courses", $offset, $limit, "", true); } public function listUnapprovedCoursesFull($offset = 0, $limit = 0) { return $this->extendedListingManager("", "ORGANIZATION_NOTAPPROVEDCOURSE_FULL", "courses", $offset, $limit); } public function listUsersFull($offset = 0, $limit = 10) { return $this->extendedListingManager("", "USER_FULL", "users", $offset, $limit, "", true); } public function listUsersNotApprovedFull($offset = 0, $limit = 10) { return $this->extendedListingManager("", "USER_NOT_APPROVED_FULL", "users", $offset, $limit, "", true); } public function listAdminsFull($offset = 0, $limit = 0) { return $this->extendedListingManager("", "ORGANIZATION_ADMINS_FULL", "users", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCourseblogPostsFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "BLOGPOST_FULL", "courseblog_posts", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCoursegroupsFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "COURSEGROUP_FULL", "coursegroups", $offset, $limit); } /** * This method will ignore both $offset and $limit, all outcomes are returned. */ public function listCourseGradesTableFull($course_id, $offset = 0, $limit = 0) { return $this->extendedListingManager($course_id, "COURSE_GRADES_TABLE_FULL", "table", $offset, $limit); } /***************** * Course Manager * *****************/ public function courseManager($action, $data, $datatype="course") { $res = $this->c->courseManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $course = to_object($res->return); if ($this->statusHasError($course->status[0][0])) { return false; } else if ($datatype != ''){ return (object) $course->data[0][$datatype][0]; } else { return true; } } public function createCourse($data) { return $this->courseManager('CREATE', $data); } public function editCourse($data) { return $this->courseManager('EDIT', $data); } public function deleteCourse($data) { return $this->courseManager('DELETE', $data, ''); } public function approveCourse($data) { return $this->courseManager('APPROVE', $data); } public function unapproveCourse($data) { return $this->courseManager('UNAPPROVE', $data); } public function loadCourse($data) { return $this->courseManager('LOAD', $data); } public function createCoursegroup($data) { return $this->courseManager('CREATE_GROUP', $data, "coursegroup"); } public function createAssignment($data) { return $this->courseManager('CREATE_ASSIGNMENT', $data, "assignment"); } public function isLearner($data) { return $this->courseManager('IS_LEARNER', $data, ""); } public function isActiveLearner($data) { return $this->courseManager('IS_ACTIVE_LEARNER', $data, ""); } public function loadLatestInfo($data) { return $this->courseManager('LOAD_LATEST', $data, "course"); } public function loadAssignmentsWithAnswers($data) { return $this->courseManager('LOAD_ASSIGNMENTS_WITH_ANSWERS', $data, "course"); } public function loadRecentFour() { $recent_four = array(); $res = $this->courseManager('LOAD_RECENT', "", "courses"); if (is_object($res)) { if (isset($res->course)) { $res = $res->course; foreach ($res as $recent) { $recent_four []= (object) $recent; } } } return $recent_four; } public function loadFeaturedCourses() { $featured = array(); $res = $this->courseManager('LOAD_FEATURED', "", "courses"); if (is_object($res)) { if (isset($res->course)) { $res = $res->course; foreach ($res as $course) { $featured []= (object) $course; } } } return $featured; } public function bulkDeleteCoursegroups($data) { return $this->courseManager('BULK_DELETE_GROUPS', $data, "response"); } public function bulkDeleteAssignments($data) { return $this->courseManager('BULK_DELETE_ASSIGNMENTS', $data, "response"); } public function bulkDeleteCategories($data) { return $this->courseManager('BULK_DELETE_CATEGORIES', $data, "response"); } public function bulkActivateLearners($data) { return $this->courseManager('BULK_ACTIVATE_LEARNERS', $data, "response"); } public function bulkRemoveLearners($data) { return $this->courseManager('BULK_REMOVE_LEARNERS', $data, "response"); } public function bulkDeleteLearningOutcomes($data) { return $this->courseManager('BULK_DELETE_OUTCOMES', $data, "response"); } public function bulkDeleteResources($data) { return $this->courseManager('BULK_DELETE_RESOURCES', $data, "response"); } public function reorderResourceFolders($data) { return $this->courseManager('REORDER_RESOURCE_FOLDERS', $data, "response"); } public function reorderLearningResources($data) { return $this->courseManager('REORDER_LEARNING_RESOURCES', $data, "response"); } public function bulkApproveCourses($data) { return $this->courseManager('BULK_APPROVE_COURSES', $data, "response"); } /********************* * Assignment Manager * *********************/ public function assignmentManager($action, $data, $datatype="assignment") { $res = $this->c->assignmentManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $assignment = to_object($res->return); if ($this->statusHasError($assignment->status[0][0])) { return false; } else if (isset($assignment->data)){ return (object) $assignment->data[0][$datatype][0]; } else { return true; } } public function loadAssignment($data) { return $this->assignmentManager('LOAD', $data); } public function editAssignment($data) { return $this->assignmentManager('EDIT', $data); } public function deleteAssignment($data) { return $this->assignmentManager('DELETE', $data); } public function loadAnswers($data) { return $this->assignmentManager('LOAD_ANSWERS', $data); } /****************** * Answer Manager * *****************/ public function answerManager($action, $data, $datatype="answer") { $res = $this->c->answerManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $assignment = to_object($res->return); if ($this->statusHasError($assignment->status[0][0])) { return false; } else if (isset($assignment->data)){ return (object) $assignment->data[0][$datatype][0]; } else { return true; } } public function loadAnswer($data) { return $this->answerManager('LOAD', $data); } public function gradeAnswer($data) { return $this->answerManager('GRADE', $data); } /**************** * Group Manager * ****************/ public function groupManager($action, $data, $datatype="coursegroup") { $res = $this->c->groupManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $course = to_object($res->return); if ($this->statusHasError($course->status[0][0])) { return false; } else if (isset($course->data)){ return (object) $course->data[0][$datatype][0]; } else { return true; } } public function loadCoursegroup($data) { return $this->groupManager('LOAD', $data); } public function editCoursegroup($data) { return $this->groupManager('EDIT', $data); } public function deleteCoursegroup($data) { return $this->groupManager('DELETE', $data); } /****************** * Learner Manager * ******************/ public function learnerManager($action, $data, $datatype="learner") { $res = $this->c->learnerManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $course = to_object($res->return); if ($this->statusHasError($course->status[0][0])) { return false; } else if ($datatype != ''){ return (object) $course->data[0][$datatype][0]; } else { return true; } } public function loadLearner($data) { return $this->learnerManager('LOAD', $data); } public function addLearner($data) { return $this->learnerManager('ADD', $data, ''); } public function enrollLearner($data) { return $this->learnerManager('ENROLL', $data, ''); } public function activateLearner($data) { return $this->learnerManager('ACTIVATE', $data); } public function removeLearner($data) { return $this->learnerManager('DELETE', $data, ''); } public function searchForLearners($data) { return $this->learnerManager('SEARCH', $data, 'users'); } public function loadGrade($data) { return $this->learnerManager('LOAD_GRADE', $data, 'grade'); } public function saveGrade($data) { return $this->learnerManager('SAVE_GRADE', $data, ''); } /********************** * Facilitator Manager * **********************/ public function facilitatorManager($action, $data, $datatype="facilitator") { $res = $this->c->facilitatorManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $object = to_object($res->return); if ($this->statusHasError($object->status[0][0])) { return false; } else if ($datatype != ''){ return (object) $object->data[0][$datatype][0]; } else { return true; } } public function loadFacilitator($data) { return $this->facilitatorManager('LOAD', $data); } public function addFacilitator($data) { return $this->facilitatorManager('ADD', $data, ''); } public function removeFacilitator($data) { return $this->facilitatorManager('DELETE', $data, ''); } public function searchFacilitators($data) { return $this->facilitatorManager('SEARCH', $data, 'users'); } /*************** * Blog Manager * ***************/ public function blogManager($blog_id, $action, $data, $datatype) { $res = $this->c->blogManager(array('sessId' => $this->sid, 'action' => $action, 'blog' => $blog_id, 'data' => $data)); $post = to_object($res->return); if ($this->statusHasError($post->status[0][0])) { return false; } else if ($datatype != "") { return (object) $post->data[0][$datatype][0]; } else { return true; } } public function createCourseblogPost($blog_id, $data) { return $this->blogManager($blog_id, "CREATE_POST", $data, "courseblog_post"); } public function editCourseblogPost($blog_id, $data) { return $this->blogManager($blog_id, "EDIT_POST", $data, "courseblog_post"); } public function deleteCourseblogPost($blog_id, $data) { return $this->blogManager($blog_id, "DELETE_POST", $data, ""); } public function loadCourseblogPost($blog_id, $data) { return $this->blogManager($blog_id, "LOAD_POST", $data, "courseblog_post"); } /******************** * Blog Post Manager * ********************/ public function blogPostManager($post_id, $action, $data, $datatype) { $res = $this->c->blogPostManager(array('sessId' => $this->sid, 'action' => $action, 'post' => $post_id, 'data' => $data)); $post = to_object($res->return); if ($this->statusHasError($post->status[0][0])) { return false; } else if ($datatype != ""){ return (object) $post->data[0][$datatype][0]; } else { return true; } } public function createCourseblogComment($post_id, $data) { return $this->blogPostManager($post_id, "CREATE_COMMENT", $data, "courseblog_comment"); } public function editCourseblogComment($post_id, $data) { return $this->blogPostManager($post_id, "EDIT_COMMENT", $data, "courseblog_comment"); } public function deleteCourseblogComment($post_id, $data) { return $this->blogPostManager($post_id, "DELETE_COMMENT", $data, ""); } public function loadCourseblogComment($post_id, $data) { return $this->blogPostManager($post_id, "LOAD_COMMENT", $data, "courseblog_comment"); } /******************* * Resource Manager * *******************/ public function resourceManager($action, $data, $datatype="resource") { $res = $this->c->resourceManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $resource = to_object($res->return); if ($this->statusHasError($resource->status[0][0])) { return false; } else if ($datatype != "") { return (object) $resource->data[0][$datatype][0]; } else { return true; } } public function createResourceFolder($data) { return $this->resourceManager("CREATE_FOLDER", $data, 'resource_folder'); } public function editResourceFolder($data) { return $this->resourceManager("EDIT_FOLDER", $data, 'resource_folder'); } public function deleteResourceFolder($data) { return $this->resourceManager("DELETE_FOLDER", $data, ""); } public function loadResourceFolder($data) { return $this->resourceManager("LOAD_FOLDER", $data, 'resource_folder'); } public function loadResourceRootFolder($data) { return $this->resourceManager("LOAD_ROOT_FOLDER", $data, 'resource_folder'); } public function createLearningResource($data) { return $this->resourceManager("CREATE_RESOURCE", $data, 'learning_resource'); } public function editLearningResource($data) { return $this->resourceManager("EDIT_RESOURCE", $data, 'learning_resource'); } public function deleteLearningResource($data) { return $this->resourceManager("DELETE_RESOURCE", $data, ""); } public function loadLearningResource($data) { return $this->resourceManager("LOAD_RESOURCE", $data, 'learning_resource'); } /*************************** * Learning OutCome Manager * ***************************/ public function outcomeManager($action, $data, $datatype="learningoutcome") { $res = $this->c->outcomeManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $outcome = to_object($res->return); if ($this->statusHasError($outcome->status[0][0])) { return false; } else if ($datatype != "") { return (object) $outcome->data[0][$datatype][0]; } else { return true; } } public function createLearningOutcome($data) { return $this->outcomeManager("CREATE", $data, 'learningoutcome'); } public function editLearningOutcome($data) { return $this->outcomeManager("EDIT", $data, 'learningoutcome'); } public function deleteLearningOutcome($data) { return $this->outcomeManager("DELETE", $data, ""); } public function loadLearningOutcome($data) { return $this->outcomeManager("LOAD", $data, 'learningoutcome'); } public function createCategory($data) { return $this->outcomeManager("CREATE_CATEGORY", $data, 'category'); } /****************** * Profile Manager * ******************/ public function profileManager($action, $data, $datatype="profile") { $res = $this->c->profileManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $profile = to_object($res->return); if ($this->statusHasError($profile->status[0][0])) { return false; } else if ($datatype != ''){ return (object) $profile->data[0][$datatype][0]; } else { return true; } } public function loadProfile($data) { return $this->profileManager("LOAD", $data); } public function saveProfile($data) { return $this->profileManager("SAVE_PROFILE", $data); } /*************** * Image Manager * ***************/ public function imageManager($action, $data) { $res = $this->c->imageManager(array('sessId' => $this->sid, 'action' => $action, 'data' => $data)); $image = to_object($res->return); if ($this->statusHasError($image->status[0][0])) { return false; } else { return (object) $image->data[0]["image"][0]; } } public function loadImage($data) { return $this->imageManager("LOAD", $data); } public function uploadImage($data) { return $this->imageManager("UPLOAD", $data); } /**************** * helpers * ****************/ public function _getTimeZone($inp) { preg_match($this->timeZonePat, $inp, $matches); return $matches[1]; } public function _getStatus($inp) { preg_match($this->statusPat, $inp, $matches); return $matches[1]; } private function _getSessionId($inp) { preg_match($this->sessIdPat, $inp, $matches); return $matches[1]; } } ?>