/** * 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; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); // enable courses app Tinebase_Application::getInstance()->setApplicationState(array(Tinebase_Application::getInstance()->getApplicationByName('Courses')->getId()), Tinebase_Application::ENABLED); $this->_cli = new Courses_Frontend_Cli(); try { $internetGroup = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array('name' => 'internetOn'))); } catch (Exception $e) { $internetGroup = Tinebase_Group::getInstance()->getGroupByName('internetOn'); } Courses_Config::getInstance()->set(Courses_Config::INTERNET_ACCESS_GROUP_ON, $internetGroup->getId()); try { $this->_internetFilteredGroup = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array('name' => 'internetFiltered'))); } catch (Exception $e) { $this->_internetFilteredGroup = Tinebase_Group::getInstance()->getGroupByName('internetFiltered'); } Courses_Config::getInstance()->set(Courses_Config::INTERNET_ACCESS_GROUP_FILTERED, $this->_internetFilteredGroup->getId()); $department = Tinebase_Department::getInstance()->create(new Tinebase_Model_Department(array('name' => Tinebase_Record_Abstract::generateUID()))); $json = new Courses_Frontend_Json(); $this->_course = $json->saveCourse(array('name' => Tinebase_Record_Abstract::generateUID(), 'description' => 'blabla', 'type' => $department->getId(), 'internet' => 'OFF')); }
/** * Returns default student password * * @param string $courseName * @return string */ public function getStudentPassword($courseName) { return strtolower($courseName) . $this->_config->get(Courses_Config::STUDENT_PASSWORD_SUFFIX, ''); }
/** * import file * * @param string $_filename * @param Tinebase_Model_ImportExportDefinition $_definition * @param boolean $_useJsonImportFn * @param boolean $removeGroupList * @return array course data */ protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE, $removeGroupList = FALSE) { $definition = $_definition !== NULL ? $_definition : $this->_getCourseImportDefinition(); $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); if ($removeGroupList) { $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']); Addressbook_Controller_List::getInstance()->delete($group->list_id); } if ($_useJsonImportFn) { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile($_filename); Courses_Config::getInstance()->set(Courses_Config::STUDENTS_IMPORT_DEFINITION, $definition->name); $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']); $this->assertGreaterThan(0, $result['results']); } else { $maildomain = TestServer::getPrimaryMailDomain(); $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array('group_id' => $courseData['group_id'], 'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/', 'accountEmailDomain' => $maildomain, 'password' => $courseData['name'], 'samba' => array('homePath' => '//basehome/', 'homeDrive' => 'H:', 'logonScript' => 'logon.bat', 'profilePath' => '\\\\profile\\'))); $tempFilename = TestServer::replaceEmailDomainInFile($_filename); $importer->importFile($tempFilename); } $courseData = $this->_json->getCourse($courseData['id']); return $courseData; }
/** * Returns instance of Tinebase_Config * * @return Tinebase_Config */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new self(); } return self::$_instance; }
/** * Returns registry data of the application. * * @return mixed array 'variable name' => 'data' */ public function getRegistryData() { $config = Courses_Config::getInstance(); $courseTypes = Tinebase_Department::getInstance()->search(new Tinebase_Model_DepartmentFilter()); if (isset($config->default_department)) { for ($i = 0; $i <= count($courseTypes); $i++) { if ($courseTypes[$i]->name == $config->default_department) { $defaultType = $courseTypes[$i]->getId(); break; } } } else { $defaultType = count($courseTypes) > 0 ? $courseTypes[0]->getId() : ''; } $result = array('defaultType' => array('value' => $defaultType, 'records' => $this->searchCourseTypes(NULL, NULL))); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' result: ' . print_r($result, true)); } return $result; }
/** * create new teacher login name from course name * * @param Courses_Model_Course $course * @param Zend_Translate $i18n * @return string */ protected function _getTeacherLoginName($course, $i18n = NULL) { if ($i18n === NULL) { $i18n = Tinebase_Translation::getTranslation('Courses'); } $loginname = $i18n->_('Teacher') . Courses_Config::getInstance()->get('teacher_login_name_delimiter', '-') . $course->name; $maxLoginNameLength = Tinebase_Config::getInstance()->get(Tinebase_Config::MAX_USERNAME_LENGTH); if (!empty($maxLoginNameLength) && strlen($loginname) > $maxLoginNameLength) { $loginname = substr($loginname, 0, $maxLoginNameLength); } return strtolower($loginname); }