Пример #1
0
 function create()
 {
     Auth::checkLoggedIn();
     $course = Course::fromId(Input::get('courseid'));
     if (!$course->canEdit(Auth::getUser())) {
         throw new Exception('You are not allowed to create an entry in this course.');
     }
     $entry = Entry::create(Auth::getUser(), $course, Input::get('title'), Input::get('description'));
     if (Input::exists('due_at')) {
         $entry->setDueTime(Input::get('due_at'));
     }
     if (Input::exists('display_at')) {
         $entry->setDisplayTime(Input::get('display_at'));
     }
     if (Input::exists('visible')) {
         $entry->setVisible(Input::getBoolean('visible'));
     }
     View::renderJson($entry->getContext(Auth::getUser()));
 }
Пример #2
0
 function remove_student()
 {
     Auth::checkLoggedIn();
     // Get the course and make sure the user can edit it
     $course = Course::fromId(Input::get('courseid'));
     if (!$course->canEdit(Auth::getUser())) {
         throw new Exception('You cannot remove users from this course');
     }
     // Get the user id to remove
     $user = User::fromId(Input::get('userid'));
     // Make sure permissions are not being overstepped
     if ($course->getCreatorUserId() != Auth::getUser()->getUserId() && !$user->isAdmin() && $user->getUserId() == $course->getCreatorUserId()) {
         throw new Exception('You are not allowed to remove the creator from the class.');
     }
     // Remove the user
     $course->removeUser($user);
     // Render the new context
     View::renderJson($course->getContext(Auth::getUser()));
 }
Пример #3
0
 /**
  * Determines whether or not a given user can edit this entry.
  * @param User $user The user to check permissions for.
  * @return boolean
  */
 public function canEdit(User $user)
 {
     $course = Course::fromId($this->getCourseId());
     if ($course->canEdit($user)) {
         return true;
     }
     return $user->getUserId() == $this->getCreatorUserId();
 }
Пример #4
0
 /**
  * Returns the context for this answer.
  * @return array
  */
 public function getContext(User $user)
 {
     // Build the likes array
     $likesUsers = $this->getLikes();
     $likes_contexts = array();
     foreach ($likesUsers as $like) {
         array_push($likes_contexts, $like->getContext($user));
     }
     // See if the professor has liked this answer
     $professorLiked = false;
     $course = Course::fromId(Question::fromId($this->getQuestionId())->getCourseId());
     foreach ($likesUsers as $curUser) {
         if ($course->canEdit($curUser)) {
             $professorLiked = true;
             break;
         }
     }
     $isProfessor = $course->canEdit(User::fromId($this->getUserId()));
     // Return the context
     return array('answerid' => $this->getAnswerId(), 'questionid' => $this->getQuestionId(), 'created_at' => $this->getCreationTime(), 'created_by' => User::fromId($this->getUserId())->getContext($user), 'edited' => $this->isEdited(), 'edited_at' => $this->getEditedTime(), 'edited_by' => User::fromId($this->getEditorUserid())->getContext($user), 'text' => $this->getText(), 'can_edit' => $this->canEdit($user), 'has_liked' => $this->hasLiked($user), 'likes' => $likes_contexts, 'professor_liked' => $professorLiked, 'is_professor' => $isProfessor);
 }