function create()
 {
     Auth::checkLoggedIn();
     $entry = Entry::fromId(Input::get('entryid'));
     if (!$entry->canView(Auth::getUser())) {
         throw new Exception('You are not allowed to ask a question in this entry.');
     }
     $question = Question::create(Auth::getUser(), $entry, Input::get('title'), Input::get('text'), Input::getBoolean('private'));
     View::renderJson($question->getContext(Auth::getUser()));
 }
 function upload_attachment()
 {
     Auth::checkLoggedIn();
     $entry = Entry::fromId(Input::get('entryid'));
     // Make sure the user can edit this entry
     if (!$entry->canEdit(Auth::getUser())) {
         throw new Exception('You are not allowed to edit this entry.');
     }
     // Get the uploaded attachments and add them to the entry
     $attachments = Attachment::handleUpload();
     foreach ($attachments as $attachment) {
         $entry->addAttachment($attachment);
     }
     // Render the new context
     View::renderJson($entry->getContext(Auth::getUser()));
 }
Beispiel #3
0
 /**
  * Determines whether or not a given user can edit the question.
  * @param User $user The user to check.
  * @return boolean
  */
 public function canEdit(User $user)
 {
     // See if they are a professor for the course
     $entry = Entry::fromId($this->getEntryId());
     if ($entry->canEdit($user)) {
         return true;
     }
     // See if they asked the question
     $firstAnswer = QuestionAnswer::fromId($this->getFirstAnswerId());
     if ($firstAnswer->getUserId() == $user->getUserId()) {
         return true;
     }
     // They cannot edit
     return false;
 }