Exemplo n.º 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);
 }
Exemplo n.º 2
0
 function testEmptyStoring()
 {
     $this->CI->load->model('mark');
     $this->CI->load->model('script');
     // set script's status to marked
     $script = new Script();
     $script->setKey(1);
     $script->retrieve();
     $pageKeyOriginal = $script->pages->getPageKeys();
     $script = new Script();
     $script->setKey(1);
     $script->marked();
     $script->update();
     $script = new Script();
     $script->setKey(1);
     $script->retrieve();
     $this->assertTrue($pageKeyOriginal === $script->pages->getPageKeys(), 'Ensure updating other values doesn\'t over-write pageKeys');
     $script->pages->addPage(1, 'fourx', 'old');
     $script->update();
     $script = new Script();
     $script->setKey(1);
     $script->retrieve();
     $this->assertTrue(count($script->pages->getPageKeys()), 'Ensure can add pageKeys');
 }
Exemplo n.º 3
0
 /**
  * Deals with all script uploads, whether ajax or en masses
  * @pages all filenames in $_FILES to be uploaded
  * @return arrary of arrays with (bool:success,string:message)
  * @todo unlink temporary files
  */
 public function _upload($page, Script $script, $pageNum = null)
 {
     // allows us to take either one page or an array
     $this->load->helper('url');
     $this->lang->load('upload');
     $this->load->library('secureupload');
     $uploadResult;
     $publicResult;
     // we've actually got a page uploaded - error 4 if no file - for the multiple uploads w/o js that will have empty
     // file inputs and we don't want error messages for each of those
     // were $_FILES successfully POSTed?
     if (@$_FILES[$page]['error'] === 0) {
         $oldPageName = $_FILES[$page]['name'];
         $newName = $script->newPageName();
         $uploadResult = $this->_uploadPage($page, $newName);
     } else {
         // find out why not
         if (!isset($_FILES[$page]) || $_FILES[$page]['error'] === 4) {
             $publicResult = 'NO_FILE';
             return $publicResult;
         }
         if ($_FILES[$page]['error'] === 1 || $_FILES[$page]['error'] === 2) {
             SecureUpload::cleanTemporary($page);
             $publicResult = SecureUpload::TOO_LARGE;
             return $publicResult;
         }
         // return a generic error
         return SecureUpload::UNSUCCESSFUL;
     }
     switch ($uploadResult) {
         case SecureUpload::SUCCESSFUL:
             $script->pages->addPage($pageNum, $newName, $oldPageName);
             $script->update();
             $publicResult = SecureUpload::SUCCESSFUL;
             break;
         case SecureUpload::MOVE_FAILED:
             $publicResult = SecureUpload::MOVE_FAILED;
             break;
         case 'too large':
         case SecureUpload::TOO_LARGE:
             $publicResult = SecureUpload::TOO_LARGE;
             break;
         case SecureUpload::WRONG_TYPE:
             $publicResult = SecureUpload::WRONG_TYPE;
             break;
         default:
             $publicResult = SecureUpload::UNSUCCESSFUL;
             break;
     }
     return $publicResult;
 }