/** * the singleton pattern * * @return Courses_Controller_Course */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new Courses_Controller_Course(); } return self::$_instance; }
/** * set all courses to internet = FILTERED * * @return integer */ public function resetCoursesInternetAccess() { if (!$this->_checkAdminRight()) { return 2; } $config = Courses_Config::getInstance(); if (!isset($config->{Courses_Config::INTERNET_ACCESS_GROUP_ON}) || !isset($config->{Courses_Config::INTERNET_ACCESS_GROUP_FILTERED})) { echo "No internet groups defined in config. Exiting\n"; return 2; } $filter = new Courses_Model_CourseFilter(array(array('field' => 'internet', 'operator' => 'not', 'value' => 'FILTERED'))); $count = 0; foreach (Courses_Controller_Course::getInstance()->search($filter) as $course) { $course->internet = 'FILTERED'; $group = Tinebase_Group::getInstance()->getGroupById($course->group_id); $group->members = Tinebase_Group::getInstance()->getGroupMembers($group); try { Courses_Controller_Course::getInstance()->saveCourseAndGroup($course, $group); $count++; } catch (Exception $e) { echo 'Failed to update course: ' . $course->name . PHP_EOL; echo $e . PHP_EOL; } } echo "Updated " . $count . " Course(s)\n"; return 0; }
/** * event handler function * * all events get routed through this function * * @param Tinebase_Event_Abstract $_eventObject the eventObject */ protected function _handleEvent(Tinebase_Event_Abstract $_eventObject) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . ' (' . __LINE__ . ') handle event of type ' . get_class($_eventObject)); } switch (get_class($_eventObject)) { case 'Admin_Event_BeforeDeleteGroup': // remove courses Courses_Controller_Course::getInstance()->deleteByFilter(new Courses_Model_CourseFilter(array(array('field' => 'group_id', 'operator' => 'in', 'value' => $_eventObject->groupIds)))); break; } }
/** * update fileserver/internet access * * @param array $ids * @param string $type * @param boolean $access * @return array */ public function updateAccess($ids, $type, $access) { $result = FALSE; $allowedTypes = array('internet', 'fileserver'); if (in_array($type, $allowedTypes)) { foreach ($ids as $courseId) { $course = $this->_controller->get($courseId); $members = $this->_groupController->getGroupMembers($course->group_id); // update course and groups $this->_manageAccessGroups($members, $access, $type); $course->{$type} = $access; $course = $this->_controller->update($course); } $result = TRUE; } return array('status' => $result ? 'success' : 'failure'); }
/** * testResetCoursesInternetAccess * * @see 0006370: add cli function for setting all courses to filtered internet * @see 0006872: cli function for internet filter does not update memberships */ public function testResetCoursesInternetAccess() { $this->assertEquals('OFF', $this->_course['internet']); ob_start(); $result = $this->_cli->resetCoursesInternetAccess(); $out = ob_get_clean(); $this->assertEquals(0, $result, $out); $updatedCourse = Courses_Controller_Course::getInstance()->get($this->_course['id']); $this->assertEquals('FILTERED', $updatedCourse->internet); $this->assertEquals("Updated 1 Course(s)\n", $out); $groupMembers = Tinebase_Group::getInstance()->getGroupMembers($updatedCourse->group_id); $this->assertTrue(count($groupMembers) > 0); $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($groupMembers[0]); $this->assertTrue(in_array($this->_internetFilteredGroup->getId(), $groupMemberships), 'filtered internet group not found in group memberships: ' . print_r($groupMemberships, TRUE)); }
/** * try to add a Course */ public function testAddCourse() { $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); // checks $this->assertEquals($course['description'], $courseData['description']); $this->assertEquals($course['type'], $courseData['type']['value']); $this->assertEquals(Tinebase_Core::getUser()->getId(), $courseData['created_by'], 'Created by has not been set.'); $this->assertTrue(!empty($courseData['group_id'])); $this->assertGreaterThan(0, count($courseData['members'])); // cleanup $this->_json->deleteCourses($courseData['id']); // check if it got deleted $this->setExpectedException('Tinebase_Exception_NotFound'); Courses_Controller_Course::getInstance()->get($courseData['id']); }
/** * reset password for given account * - call Admin_Frontend_Json::resetPassword() * * @param array $account data of Tinebase_Model_FullUser or account id * @param string $password the new password * @param bool $mustChange * @return array */ public function resetPassword($account, $password, $mustChange) { $password = $this->_controller->getStudentPassword($password); $adminJson = new Admin_Frontend_Json(); return $adminJson->resetPassword($account, $password, (bool) $mustChange); }