/** * the singleton pattern * * @return Tinebase_Department */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new Tinebase_Department(); } return self::$_instance; }
/** * Tears down the fixture * This method is called after a test is executed. * * @access protected */ protected function tearDown() { if (!empty($this->_coursesToDelete)) { $this->_json->deleteCourses($this->_coursesToDelete); } // delete department Tinebase_Department::getInstance()->delete($this->_department); }
/** * init department * * @see 0010554: create default department (school) on Courses installation */ public static function _initializeDepartment() { // create a default department if none exists $departments = Tinebase_Department::getInstance()->getAll(); if (count($departments) === 0) { $translation = Tinebase_Translation::getTranslation('Courses'); $school = new Tinebase_Model_Department(array('name' => $translation->_('School'), 'description' => $translation->_('Defaul school for Courses application'))); Tinebase_Department::getInstance()->create($school); } }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->_json = new Courses_Frontend_Json(); $this->_department = Tinebase_Department::getInstance()->create(new Tinebase_Model_Department(array('name' => Tinebase_Record_Abstract::generateUID()))); $this->_groupsToDelete = new Tinebase_Record_RecordSet('Tinebase_Model_Group'); foreach (array(Courses_Config::INTERNET_ACCESS_GROUP_ON, Courses_Config::INTERNET_ACCESS_GROUP_FILTERED, Courses_Config::STUDENTS_GROUP) as $configgroup) { $this->_configGroups[$configgroup] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array('name' => $configgroup))); $this->_groupsToDelete->addRecord($this->_configGroups[$configgroup]); Courses_Config::getInstance()->set($configgroup, $this->_configGroups[$configgroup]->getId()); } Courses_Config::getInstance()->set(Courses_Config::SAMBA, new Tinebase_Config_Struct(array('basehomepath' => '\\\\jo\\', 'homedrive' => 'X:', 'logonscript_postfix_teacher' => '-lehrer.cmd', 'logonscript_postfix_member' => '.cmd', 'baseprofilepath' => '\\\\jo\\profiles\\'))); $this->_schemaConfig = Courses_Config::getInstance()->get(Courses_Config::STUDENTS_USERNAME_SCHEMA); $this->_usernameLengthConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::MAX_USERNAME_LENGTH); $this->_defaultDepartmentConfig = Courses_Config::getInstance()->get(Courses_Config::DEFAULT_DEPARTMENT); }
/** * 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')); }
/** * search / get departments * * @param array $filter filter array * @param array $paging pagination info * @return array */ public function searchDepartments($filter, $paging) { $result = $this->_search($filter, $paging, Tinebase_Department::getInstance(), 'Tinebase_Model_DepartmentFilter'); return $result; }
/** * returns config for new users * * @param Courses_Model_Course $course * @return array */ protected function _getNewUserConfig(Courses_Model_Course $course) { $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name); return array('accountLoginNamePrefix' => $this->_config->get(Courses_Config::STUDENT_LOGINNAME_PREFIX, FALSE) ? $course->name . '-' : '', 'group_id' => $course->group_id, 'accountEmailDomain' => isset($this->_config->domain) ? $this->_config->domain : '', 'accountHomeDirectoryPrefix' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $course->name . '/' : '', 'userNameSchema' => $this->_config->get(Courses_Config::STUDENTS_USERNAME_SCHEMA, 1), 'password' => $this->getStudentPassword($course->name), 'course' => $course, 'accountLoginShell' => '/bin/false', 'samba' => isset($this->_config->samba) ? array('homePath' => $this->_config->samba->basehomepath, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $course->name . $this->_config->samba->logonscript_postfix_member, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $course->name . '\\', 'pwdCanChange' => new Tinebase_DateTime('@1'), 'pwdMustChange' => new Tinebase_DateTime('@1')) : array()); }
/** * Search for records matching given arguments * * @param array $filter * @param array $paging * @return array */ public function searchCourseTypes($filter, $paging) { $result = Tinebase_Department::getInstance()->search(new Tinebase_Model_DepartmentFilter())->toArray(); return array('results' => $result, 'totalcount' => count($result), 'filter' => $filter); }
/** * add exitings accounts to course * * @param string $_courseId * @param array $_members */ public function addCourseMembers($_courseId, array $_members = array()) { $course = $_courseId instanceof Courses_Model_Course ? $_courseId : $this->get($_courseId); $tinebaseUser = Tinebase_User::getInstance(); $tinebaseGroup = Tinebase_Group::getInstance(); $courseName = strtolower($course->name); $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name); foreach ($_members as $userId) { $user = $tinebaseUser->getFullUserById($userId); $tinebaseGroup->removeGroupMember($user->accountPrimaryGroup, $user); $user->accountPrimaryGroup = $course->group_id; $user->accountHomeDirectory = isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $courseName . '/' . $user->accountLoginName : ''; if (isset($user->sambaSAM)) { $sambaSAM = $user->sambaSAM; $sambaSAM->homePath = $this->_config->samba->basehomepath . $user->accountLoginName; $sambaSAM->logonScript = $courseName . $this->_config->samba->logonscript_postfix_member; $sambaSAM->profilePath = $this->_config->samba->baseprofilepath . $schoolName . '\\' . $courseName . '\\' . $user->accountLoginName; $user->sambaSAM = $sambaSAM; } $tinebaseUser->updateUser($user); $tinebaseGroup->addGroupMember($user->accountPrimaryGroup, $user); if (isset($this->_config->students_group) && !empty($this->_config->students_group)) { $tinebaseGroup->addGroupMember($this->_config->students_group, $user); } } }