private function _sendPayment($marker, $marks, $assessmentAssoc, $assessmentFix = 0) { if (count($marks) === 0 && empty($assessmentAssoc)) { return false; } foreach ($marks as $markAssoc) { $mark = new Mark(); $mark->setKey($markAssoc[$mark->getKeyField()]); $mark->paid(); $mark->update(); $markKeys[] = $markAssoc[$mark->getKeyField()]; } $assessmentAmount = 0; if (!empty($assessmentAssoc)) { $assessment = new Assessment(); $assessment->setKey($assessmentAssoc[$assessment->getKeyField()]); $assessment->paid(); $assessment->update(); $markKeys[] = 'Assessment script'; $assessmentAmount = 1; } if ($assessmentFix) { $assessmentFix = new AssessmentFix(); $assessmentFix->setKey($this->_getUser()); $assessmentFix->paid(); $assessmentFix->update(); $markKeys[] = 'Assessment bounty'; } $this->load->model('wage'); $amount = ($assessmentFix + count($marks) + $assessmentAmount) * 1.5; $wage = new Wage(); $wage->paid($marker, $amount, $markKeys); $wage->create(); return $amount; }
/** * 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); }