コード例 #1
0
ファイル: CourseVoter.php プロジェクト: Okami-/ilios
 /**
  * @param CourseInterface $course
  * @param UserInterface $user
  * @return bool
  */
 protected function isWriteGranted($course, $user)
 {
     // grant CREATE/EDIT/DELETE privileges if at least one of the following
     // statements is true:
     // 1. the user's primary school is the course's owning school
     //    and the user has at least one of the 'Faculty', 'Course Director' and 'Developer' roles.
     // 2. the user has WRITE rights on the course's owning school via the permissions system
     //    and the user has at least one of the 'Faculty', 'Course Director' and 'Developer' roles.
     // 3. the user has WRITE rights on the course via the permissions system
     return $this->userHasRole($user, ['Faculty', 'Course Director', 'Developer']) && ($this->schoolsAreIdentical($course->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $course->getSchool())) || $this->permissionManager->userHasWritePermissionToCourse($user, $course);
 }
コード例 #2
0
 /**
  * @param string $attribute
  * @param CourseInterface $course
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $course, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         case self::VIEW:
             return $this->isViewGranted($course->getId(), $course->getSchool()->getId(), $user);
             break;
         case self::CREATE:
         case self::EDIT:
         case self::DELETE:
             return $this->isWriteGranted($course->getId(), $course->getSchool()->getId(), $user);
             break;
     }
     return false;
 }
コード例 #3
0
ファイル: PermissionManager.php プロジェクト: Okami-/ilios
 /**
  * {@inheritdoc}
  */
 public function userHasWritePermissionToCourse(UserInterface $user, CourseInterface $course)
 {
     return $this->userHasPermission($user, self::CAN_WRITE, 'course', $course->getId());
 }
コード例 #4
0
ファイル: Course.php プロジェクト: stopfstedt/ilios
 /**
  * @inheritdoc
  */
 public function removeDescendant(CourseInterface $descendant)
 {
     $this->descendants->removeElement($descendant);
 }
コード例 #5
0
ファイル: CourseManager.php プロジェクト: Okami-/ilios
 /**
  * {@inheritdoc}
  */
 public function deleteCourse(CourseInterface $course)
 {
     $course->setDeleted(true);
     $this->updateCourse($course);
 }
コード例 #6
0
 /**
  * Setup the course manager mock to do basic stuff we need in most tests
  *
  * @param CourseInterface $course
  * @param CourseInterface $newCourse
  * @param integer $interval the length of time in the future for the new academic year
  *
  * @return int
  */
 protected function setupCourseManager(CourseInterface $course, CourseInterface $newCourse, $interval = 1)
 {
     $newYear = $course->getYear() + $interval;
     $this->courseManager->shouldReceive('findOneBy')->withArgs([['id' => $course->getId()]])->andReturn($course)->once();
     $this->courseManager->shouldReceive('findBy')->withArgs([['title' => $course->getTitle(), 'year' => $newYear]])->andReturn(false)->once();
     $this->courseManager->shouldReceive('update')->withArgs([$newCourse, false, false])->once();
     $this->courseManager->shouldReceive('create')->once()->andReturn($newCourse);
     $this->courseManager->shouldReceive('flushAndClear')->once();
     return $newYear;
 }
コード例 #7
0
ファイル: CourseRollover.php プロジェクト: stopfstedt/ilios
 /**
  * @param CourseInterface $newCourse
  * @param CourseInterface $origCourse
  *
  * @return array
  */
 protected function rolloverCourseObjectives(CourseInterface $newCourse, CourseInterface $origCourse)
 {
     $newCourseObjectives = [];
     foreach ($origCourse->getObjectives() as $objective) {
         /* @var ObjectiveInterface $newObjective */
         $newObjective = $this->objectiveManager->create();
         $newObjective->setTitle($objective->getTitle());
         $newObjective->setMeshDescriptors($objective->getMeshDescriptors());
         $newObjective->addCourse($newCourse);
         $this->objectiveManager->update($newObjective, false, false);
         $newCourseObjectives[$objective->getId()] = $newObjective;
     }
     return $newCourseObjectives;
 }