Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 123 |
| TermpaperSubmissionService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
702.00 | |
0.00% |
0 / 123 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| addTermpaperSubmissionStudentDetails | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 22 |
|||
| addTermpaperSubmissionStudentDetailsMultiple | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 14 |
|||
| updateTermpaperSubmittedStudentDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| searchTermpaperSubmittedStudentDetails | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 68 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service\examcontroller; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\service\BaseService; | |
| use com\linways\core\ams\professional\service\SMSService; | |
| use com\linways\core\ams\professional\service\StudentService; | |
| class TermpaperSubmissionService extends BaseService | |
| { | |
| // /Condition 1 - Presence of a static member variable | |
| private static $_instance = null; | |
| private $mapper = []; | |
| // /Condition 2 - Locked down the constructor | |
| private function __construct() | |
| { | |
| } | |
| // Prevent any oustide instantiation of this class | |
| // /Condition 3 - Prevent any object or instance of that class to be cloned | |
| private function __clone() | |
| { | |
| } | |
| // Prevent any copy of this object | |
| // /Condition 4 - Have a single globally accessible static method | |
| public static function getInstance() | |
| { | |
| if (!is_object(self::$_instance)) // or if( is_null(self::$_instance) ) or if( self::$_instance == null ) | |
| self::$_instance = new self (); | |
| return self::$_instance; | |
| } | |
| /** | |
| * @param $termpaperSubmissionArray | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function addTermpaperSubmissionStudentDetails ($termpaperSubmission) { | |
| $termpaperSubmission = $this->realEscapeObject($termpaperSubmission); | |
| if (!empty ($termpaperSubmission)) { | |
| try { | |
| $studentId = $termpaperSubmission->studentId; | |
| $studentDetails = StudentService::getInstance()->getStudentDetailsByIds([$studentId])[0]; | |
| $termpaperSubmission->batchId = $studentDetails->batchID; | |
| $termpaperSubmission->semId = $studentDetails->semID; | |
| $sql_check = "SELECT tssd.id FROM termpaper_submitted_student_details tssd INNER JOIN batches b ON b.batchID = '$termpaperSubmission->batchId' WHERE studentaccount_id = '$studentId' "; | |
| $submissionId = $this->executeQueryForObject($sql_check)->id; | |
| if ( $submissionId ) { | |
| $termpaperSubmission->id = $submissionId; | |
| $this->updateTermpaperSubmittedStudentDetails($termpaperSubmission); | |
| } | |
| else { | |
| $sql = "INSERT INTO termpaper_submitted_student_details (studentaccount_id, staffaccounts_id, is_sms_send, batches_id, semesters_id, created_by) VALUES ('$studentId', '$termpaperSubmission->staffId', '$termpaperSubmission->isSmsSend', '$termpaperSubmission->batchId', '$termpaperSubmission->semId', '$termpaperSubmission->createdBy')"; | |
| $termpaperSubmissionId = $this->executeQueryForObject($sql, true); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| } | |
| /** | |
| * @param $termpaperSubmissionArray | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function addTermpaperSubmissionStudentDetailsMultiple ($termpaperSubmissionArray) { | |
| $termpaperSubmissionArray = $this->realEscapeArray($termpaperSubmissionArray); | |
| if (!empty ($termpaperSubmissionArray)) { | |
| foreach ($termpaperSubmissionArray as $termpaperSubmission) { | |
| $insertValues[] = "('$termpaperSubmission->studentId', '$termpaperSubmission->staffId', '$termpaperSubmission->isSmsSend', '$termpaperSubmission->batchId', '$termpaperSubmission->semId' )"; | |
| } | |
| $sql = "INSERT INTO termpaper_submitted_student_details (studentaccount_id, staffaccounts_id, is_sms_send, batches_id, semesters_id) VALUES | |
| " . implode(', ', $values); | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| } | |
| /** | |
| * @param $termpaperSubmission | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function updateTermpaperSubmittedStudentDetails ($termpaperSubmission) { | |
| $termpaperSubmission = $this->realEscapeObject($termpaperSubmission); | |
| if (!empty ($termpaperSubmission)) { | |
| $sql = "UPDATE termpaper_submitted_student_details SET staffaccounts_id = '$termpaperSubmission->staffId', is_sms_send = '$termpaperSubmission->isSmsSend' WHERE id = '$termpaperSubmission->id' "; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| } | |
| /** | |
| * @param $termpaperSubmission | |
| * @return Object|null | |
| * @throws ProfessionalException | |
| * @author Vishnu M | |
| */ | |
| public function searchTermpaperSubmittedStudentDetails($termpaperSubmission) { | |
| $termpaperSubmission = $this->realEscapeObject($termpaperSubmission); | |
| if ($termpaperSubmission->batchId) { | |
| $sql = null; | |
| $condition = null; | |
| if ($termpaperSubmission->studentName) { | |
| $condition .= " AND sa.studentName LIKE ('%$termpaperSubmission->studentName%') "; | |
| } | |
| if ($termpaperSubmission->regNo) { | |
| $condition .= " AND sa.regNo LIKE ('%$termpaperSubmission->regNo%') "; | |
| } | |
| if ($termpaperSubmission->studentId) { | |
| $condition .= " AND tpssd.studentaccount_id = '$termpaperSubmission->studentId' "; | |
| } | |
| if ($termpaperSubmission->staffId) { | |
| $condition .= " AND tpssd.staffaccounts_id = '$termpaperSubmission->staffId' "; | |
| } | |
| if ($termpaperSubmission->isSmsSend != "") { | |
| $condition .= " AND tpssd.is_sms_send = '$termpaperSubmission->isSmsSend' "; | |
| } | |
| if ($termpaperSubmission->semId) { | |
| $condition .= " AND tpssd.semesters_id = '$termpaperSubmission->semId' "; | |
| } | |
| if ($termpaperSubmission->isSubmitted === "1") { | |
| $condition .= " AND tpssd.id IS NOT NULL "; | |
| } else if ($termpaperSubmission->isSubmitted === "0") { | |
| $condition .= " AND tpssd.id IS NULL "; | |
| } | |
| $studentDetails = null; | |
| $sql = " | |
| SELECT | |
| sa.studentID AS id, | |
| sa.studentName AS name, | |
| sa.regNo, | |
| sa.studentPhone AS phoneNo, | |
| tpssd.is_sms_send AS isSmsSend, | |
| staff.staffID AS staffId, | |
| staff.staffName, | |
| b.batchID AS batchId, | |
| b.batchName, | |
| s.semID as semId, | |
| s.semName, | |
| tpssd.id AS submissionId, | |
| tpssd.created_date AS submittedDate, | |
| tpssd.updated_date AS resubmittedDate | |
| FROM | |
| studentaccount sa | |
| LEFT JOIN | |
| termpaper_submitted_student_details tpssd ON sa.studentID = tpssd.studentaccount_id | |
| LEFT JOIN | |
| staffaccounts staff ON tpssd.staffaccounts_id = staff.staffID | |
| LEFT JOIN | |
| batches b ON b.batchID = tpssd.batches_id | |
| LEFT JOIN | |
| semesters s ON s.semID = tpssd.semesters_id | |
| WHERE | |
| sa.batchID = '$termpaperSubmission->batchId' | |
| $condition | |
| ORDER BY sa.regNo ASC"; | |
| try { | |
| $studentDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $studentDetails; | |
| } else { | |
| throw new ProfessionalException(ProfessionalException::INVALID_BATCH_ID, "No batch selected"); | |
| } | |
| } | |
| } |