コード例 #1
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * 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);
 }
コード例 #2
0
 /**
  * save course with corresponding group
  * 
  * @param Courses_Model_Course $course
  * @param Tinebase_Model_Group $group
  * @return Courses_Model_Course
  * 
  * @todo this should be moved to normal create/update (inspection) functions
  */
 public function saveCourseAndGroup(Courses_Model_Course $course, Tinebase_Model_Group $group)
 {
     $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__ . ' Saving course ' . $course->name . ' with group ' . $group->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($group->toArray(), true));
     }
     if (empty($group->id)) {
         $savedGroup = $this->_groupController->create($group);
         $course->group_id = $savedGroup->getId();
         $savedRecord = $this->create($course);
     } else {
         $savedRecord = $this->update($course);
         $currentMembers = $this->_groupController->getGroupMembers($course->group_id);
         $newCourseMembers = array_diff((array) $group->members, $currentMembers);
         if (count($newCourseMembers) > 0) {
             $this->addCourseMembers($course, $newCourseMembers);
         }
         $deletedAccounts = array_diff($currentMembers, (array) $group->members);
         // delete members which got removed from course
         $this->_userController->delete($deletedAccounts);
     }
     $groupMembers = Tinebase_Group::getInstance()->getGroupMembers($course->group_id);
     // add/remove members to/from internet/fileserver group
     if (!empty($groupMembers)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($groupMembers) . ' group members');
         }
         $this->_manageAccessGroups($groupMembers, $savedRecord);
         // $this->_manageAccessGroups($group->members, $savedRecord, 'fileserver');
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No group members found.');
         }
     }
     return $savedRecord;
 }