/**
  * add new member to course
  * 
  * @param array $userData
  * @param array $courseData
  * @return array
  * 
  * @todo generalize type (value) sanitizing
  */
 public function addNewMember($userData, $courseData)
 {
     $course = new Courses_Model_Course(array(), TRUE);
     if (isset($courseData['type']['value'])) {
         $courseData['type'] = $courseData['type']['value'];
     }
     $course->setFromJsonInUsersTimezone($courseData);
     $user = new Tinebase_Model_FullUser(array('accountFirstName' => $userData['accountFirstName'], 'accountLastName' => $userData['accountLastName']), TRUE);
     $this->_controller->createNewMember($course, $user);
     // return members to update members grid
     return array('results' => $this->_getCourseMembers($course->group_id), 'status' => 'success');
 }
 /**
  * add new member to course
  * 
  * @param Courses_Model_Course $course
  * @param Tinebase_Model_FullUser $user
  * @return Tinebase_Model_FullUser
  * 
  * @todo use importMembers() here to avoid duplication
  */
 public function createNewMember(Courses_Model_Course $course, Tinebase_Model_FullUser $user)
 {
     $this->checkRight(Courses_Acl_Rights::ADD_NEW_USER);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new member for ' . $course->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($course->toArray(), TRUE));
     }
     $password = $user->applyOptionsAndGeneratePassword($this->_getNewUserConfig($course));
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($user->toArray(), TRUE));
     }
     $newMember = $this->_userController->create($user, $password, $password);
     // add to default group and manage access group for user
     $this->_groupController->addGroupMember(Tinebase_Group::getInstance()->getDefaultGroup()->getId(), $newMember->getId());
     $this->_manageAccessGroups(array($newMember->getId()), $course);
     $this->_addToStudentGroup(array($newMember->getId()));
     return $newMember;
 }
Exemplo n.º 3
0
 /**
  * creates/updates a record
  *
  * @todo move non api specific stuff to controller!
  * 
  * @param  array $recordData
  * @return array created/updated record
  */
 public function saveCourse($recordData)
 {
     // create course and group from json data
     $course = new Courses_Model_Course(array(), TRUE);
     $course->setFromJsonInUsersTimezone($recordData);
     $group = new Tinebase_Model_Group(array(), TRUE);
     $group->setFromJsonInUsersTimezone($recordData);
     $i18n = Tinebase_Translation::getTranslation('Courses');
     $groupNamePrefix = $i18n->_('Course');
     $groupNamePrefix = is_array($groupNamePrefix) ? $groupNamePrefix[0] : $groupNamePrefix;
     $group->name = $groupNamePrefix . '-' . $course->name;
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($group->toArray(), true));
     }
     if (empty($group->id)) {
         $savedGroup = $this->_groupController->create($group);
         $course->group_id = $savedGroup->getId();
         $savedRecord = $this->_controller->create($course);
     } else {
         $savedRecord = $this->_controller->update($course);
         $currentMembers = $this->_groupController->getGroupMembers($course->group_id);
         $newCourseMembers = array_diff((array) $group->members, $currentMembers);
         $this->_controller->addCourseMembers($course, $newCourseMembers);
         $deletedAccounts = array_diff($currentMembers, (array) $group->members);
         // delete members wich got removed from course
         Admin_Controller_User::getInstance()->delete($deletedAccounts);
     }
     // add/remove members to/from internet/fileserver group
     if (!empty($group->members)) {
         $this->_manageAccessGroups($group->members, $savedRecord->internet, 'internet');
         $this->_manageAccessGroups($group->members, $savedRecord->fileserver, 'fileserver');
     }
     return $this->_recordToJson($savedRecord);
 }