Пример #1
0
 /**
  * Method for saving Flex models.Mark.
  * @param POST jsonData - holds the markData information in JSON format
  */
 public function addMark()
 {
     if (!($jsonData = $this->input->post('jsonData'))) {
         return;
     }
     $this->load->model('mark');
     $this->load->model('script');
     $this->load->library('json');
     $decoded = $this->json->decode($jsonData);
     $script = new Script();
     $script->setKey($decoded->script);
     $mark = new Mark();
     $mark->setKey($script->getKey());
     $mark->retrieve();
     // make sure the marker has right to mark this
     if ($mark->get('marker') !== $this->_getUser()) {
         $this->_flexResult(I_FlexMarksIn::NOT_AUTH);
         return;
     }
     // store data
     $mark->set('markData', $jsonData);
     $mark->set('targets', serialize($decoded->targets));
     $mark->set('generalComment', $decoded->generalComment);
     // change status
     $mark->submit();
     if (!$mark->update()) {
         // @todo add some Flex handeling for this if it occurs
         $this->_flexResult(I_FlexMarksIn::ERROR);
         return;
     }
     // set script's status to marked
     $script->marked();
     $script->update();
     // get the script data to use in the email
     $script->retrieve();
     $customerEmail = $script->get('email');
     $scriptID = $script->getKey();
     $lastPage = count($script->pages->getPageKeys());
     // save an email for the customers, to be send by cron task
     $subject = 'A tutor has read your exam essay and provided feedback';
     foreach ($decoded->targets as $target) {
         $newTarget['type'] = $target->type;
         $newTarget['text'] = $target->text;
         $emailData['targets'][] = $newTarget;
     }
     $emailData['generalComment'] = $decoded->generalComment;
     // link for user to launch flex viewer
     $emailData['viewURL'] = site_url("/user/scripts/viewfeedback/{$scriptID}/{$lastPage}");
     $msg = $this->load->view('email/marked', $emailData, true);
     $this->load->model('email');
     $this->email->set('sender', '*****@*****.**');
     $this->email->set('receiver', $customerEmail);
     $this->email->set('subject', $subject);
     $this->email->set('message', $msg);
     //$this->email->set('messageHTML',$msgHTML);
     $this->email->create();
     $this->_flexResult(I_FlexMarksIn::SAVE_SUCCESSFUL);
 }