/**
  * 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');
 }
예제 #2
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);
 }