function testRemovePage() { $this->CI->load->model('script'); $script = new Script($this->DBI); $script->setKey(1); $script->retrieve(); $this->assertTrue(count($script->pages->getPageKeys()) === 2, 'Test page group retrieves as expected'); }
/** * 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); }
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'); }
/** * Gets the user's unpaid script if possible, and returns it, or returns a new script * @return $script - new or active script from db */ private function _activeScriptOrNew() { $this->load->model('script'); $script = new Script(); // Does the user have an unpaid script? if ($activeScriptKey = $script->getUnpaidScript($this->session->userdata('email'))) { // if so, then load and retrieve it $script->setKey($activeScriptKey); $script->retrieve(); } else { // No unpaid script; we need to create one $script->createNewScriptFor($this->session->userdata('email')); $script->retrieve(); } return $script; }