/** * Compute a list of LOs for this LMS * * @param array $attributes * name=>value filter array */ public function findLObyAttributes(array $attributes) { if (array_key_exists('loId', $attributes) && array_key_exists('getFullCourse', $attributes) && $attributes['getFullCourse'] == 'true') { // retrieve all objects in course $id = $attributes['loId']; $loId = $id instanceof LOId ? $id : new LOId($id); try { $adaptor = Intuitel::getAdaptorInstanceForCourseLOId($loId); $list = $adaptor->findLOAll(); return $list; } catch (UnknownLOException $ex) { return array(); } catch (UnknownIDException $ex) { return array(); } } else { if (array_key_exists('loId', $attributes)) { // return one object $id = $attributes['loId']; $loId = $id instanceof LOId ? $id : new LOId($id); try { $lo = IntuitelAdaptor::createLO($loId); return array($lo); } catch (UnknownLOException $ex) { return array(); } catch (UnknownIDException $ex) { return array(); } } else { // search every course by params $courses = Intuitel::getIntuitelEnabledCourses(); $total_list = array(); foreach ($courses as $course) { $filter = array('loId' => $course->loId, 'getFullCourse' => 'true'); $list = $this->findLObyAttributes($filter); $total_list = array_merge($total_list, $list); } // filter out unwanted items $final_list = $this->filterUnmatched($total_list, $attributes); return $final_list; } } }
/** * (non-PHPdoc) * @see \intuitel\IntuitelAdaptor::getCoursesEnrolled() */ public function getCoursesEnrolled(UserId $user_id) { $listCoursesEnrolled = array(); $intuitelCourses = Intuitel::getIntuitelEnabledCourses(); $ownedCourses = Intuitel::getAdaptorInstanceForCourse()->getCoursesOwnedByUser($user_id); $native_userid = $user = $this->getNativeUserFromUId($user_id)->id; foreach ($intuitelCourses as $intuitelCourse) { $nativeCourseId = Intuitel::getIDFactory()->getIdfromLoId($intuitelCourse->loId); // get_user_roles_in_course($user->id, $nativeCourseId) TODO decide between this and is_enrolled, with this we can know if the user is student but with is_enrolled we get true for students and teachers. if (is_enrolled(\context_course::instance($nativeCourseId), $native_userid)) { //do not include those courses in which the user is teacher if (array_search($intuitelCourse, $ownedCourses) === FALSE) { $listCoursesEnrolled[] = $intuitelCourse; } } } return $listCoursesEnrolled; }