/**
  * creates/updates a record
  *
  * @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);
     $savedRecord = $this->_controller->saveCourseAndGroup($course, $group);
     return $this->_recordToJson($savedRecord);
 }
Esempio n. 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);
 }