Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 172 |
| StudentMarkReportService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
2862.00 | |
0.00% |
0 / 172 |
| __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 |
|||
| generateJoinConditions | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 18 |
|||
| saveFilter | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
| deleteFilter | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 8 |
|||
| getAllSavedSearches | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
| getFilterValuesByOperandCode | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 28 |
|||
| searchStudentMarkDetails | |
0.00% |
0 / 1 |
600.00 | |
0.00% |
0 / 79 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\constant\report\StudentMarkReportOperands; | |
| use com\linways\core\ams\professional\service\report\ReportCourseService; | |
| use com\linways\core\ams\professional\service\report\ReportCourseTypeService; | |
| use com\linways\core\ams\professional\service\report\ReportCoursePatternService; | |
| use com\linways\core\ams\professional\service\report\ReportDepartmentService; | |
| use com\linways\core\ams\professional\service\report\ReportCampusTypeService; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\service\report\ReportBatchService; | |
| use com\linways\core\ams\professional\dto\StudentMarkReportEngine; | |
| use com\linways\core\ams\professional\request\Report\ReportSearchStudentRequest; | |
| use com\linways\core\ams\professional\request\Report\GetAllSavedSearchRequest; | |
| class StudentMarkReportService extends BaseService | |
| { | |
| private $mapper = []; | |
| // /Condition 1 - Presence of a static member variable | |
| private static $_instance = null; | |
| // /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; | |
| } | |
| /** | |
| * Generating join queries | |
| * | |
| * @param $alias | |
| * @param $fieldName | |
| * @param $operator | |
| * @param $values | |
| * @return string | |
| */ | |
| private function generateJoinConditions($alias, $fieldName, $operator, $values) | |
| { | |
| if (!$alias) { | |
| $alias = ""; | |
| } | |
| switch ($operator) { | |
| case "IS": | |
| return " AND $alias.$fieldName IN ('" . implode("','", $values) . "')"; | |
| case "IS_NOT": | |
| return " AND $alias.$fieldName NOT IN ('" . implode("','", $values) . "')"; | |
| case "EQUAL_TO": | |
| return " AND $alias.$fieldName ='$values'"; | |
| case "LESS_THAN": | |
| return " AND $alias.$fieldName < '$values'"; | |
| case "GREATER_THAN": | |
| return " AND $alias.$fieldName > '$values'"; | |
| } | |
| return ""; | |
| } | |
| public function saveFilter(StudentMarkReportEngine $studentMarkReport) | |
| { | |
| if(!$studentMarkReport->id) | |
| { | |
| $sql ="INSERT INTO student_mark_report_engine (report_name, report_desc, report_format, report_filter, created_by, created_date, updated_by, updated_date) VALUES ('$studentMarkReport->reportName', '$studentMarkReport->reportDesc', '$studentMarkReport->reportFormat', '$studentMarkReport->reportFilter', '$studentMarkReport->createdBy', utc_timestamp(), '$studentMarkReport->updatedBy', utc_timestamp())"; | |
| } | |
| else | |
| { | |
| $sql ="UPDATE student_mark_report_engine SET report_name='$studentMarkReport->reportName', report_desc='$studentMarkReport->reportDesc', report_format='$studentMarkReport->reportFormat', report_filter='$studentMarkReport->reportFilter', updated_by='$studentMarkReport->updatedBy', updated_date=utc_timestamp() WHERE id=$studentMarkReport->id"; | |
| } | |
| try { | |
| return $this->executeQuery($sql, true)->id; | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| public function deleteFilter($id) | |
| { | |
| $sql="DELETE FROM student_mark_report_engine where id=$id"; | |
| try { | |
| return $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Returns all the previously stored search combinations | |
| * | |
| * @param GetAllSavedSearchRequest $request | |
| * @return Object | |
| * @throws ProfessionalException | |
| */ | |
| public function getAllSavedSearches(GetAllSavedSearchRequest $request) | |
| { | |
| $request = $this->realEscapeObject($request); | |
| if (empty($request->createdBy)) { | |
| throw new ProfessionalException(ProfessionalException::INVALID_REQUEST, "invalid request sent"); | |
| } | |
| $sql = "SELECT id,report_name as name, report_desc as description, report_format as reportFormat,report_filter as filterConditions | |
| FROM student_mark_report_engine | |
| WHERE created_by = $request->createdBy | |
| ORDER BY updated_date DESC"; | |
| try { | |
| return $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * @param $operandId | |
| * @return array|Object | |
| * @throws ProfessionalException | |
| */ | |
| public function getFilterValuesByOperandCode($operandCode, $relatedFields=NULL) | |
| { | |
| $operandCode = $this->realEscapeObject($operandCode); | |
| $relatedFields = $this->realEscapeArray($relatedFields); | |
| if (empty($operandCode)) { | |
| throw new ProfessionalException(ProfessionalException::INVALID_OPERAND_ID, "Select a valid filter item"); | |
| } | |
| try { | |
| switch ($operandCode) { | |
| case StudentMarkReportOperands::COURSE: | |
| return ReportCourseService::getInstance()->getCourseFilterValues(); | |
| case StudentMarkReportOperands::COURSE_TYPE: | |
| return ReportCourseTypeService::getInstance()->getAllCourseTypes(); | |
| case StudentMarkReportOperands::COURSE_PATTERN: | |
| return ReportCoursePatternService::getInstance()->getAllCoursePatterns(); | |
| case StudentMarkReportOperands::DEPARTMENT: | |
| return ReportDepartmentService::getInstance()->getAllDepartments(); | |
| case StudentMarkReportOperands::BATCH: | |
| return ReportBatchService::getInstance()->getBatchesByRelatedField($relatedFields); | |
| case StudentMarkReportOperands::CAMPUS_TYPE: | |
| return ReportCampusTypeService::getInstance()->getAllCampusTypes(); | |
| case StudentMarkReportOperands::BATCH_START_YEAR: | |
| return BatchService::getInstance()->getAllBatchStartYearsForAdvancedStudentSearch(); | |
| break; | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| public function searchStudentMarkDetails(ReportSearchStudentRequest $reportSearchStudentRequest){ | |
| if($reportSearchStudentRequest->reportFormat=="COURSE_WISE") | |
| { | |
| $sql ="select sa.studentID, sa.studentName, sa.regNo, sa.admissionNo, sa.studentEmail, sa.studentPhone, sa.parentPhone, sa.studentAddress, bt.batchName, sem.semName, dept.deptName, dept.departmentDesc, ecm.no_of_arrears as noOfArrears, ecm.percentage, ecm.cgpa, ecm.total_marks as totalMarks from studentaccount sa INNER JOIN batches bt ON bt.batchID=sa.batchID INNER JOIN semesters sem ON sem.semID=bt.semID INNER JOIN department dept ON dept.deptID=bt.deptID INNER JOIN ec_course_consolidated_mark_details ecm ON ecm.student_id=sa.studentID LEFT JOIN course_type ct ON ct.courseTypeID=bt.courseTypeID LEFT JOIN course_pattern cp ON cp.patternID=bt.patternID LEFT JOIN pattern_deptcourses pd ON pd.patterncourseID=bt.patterncourseID WHERE sa.studentID IS NOT NULL"; | |
| } | |
| else if($reportSearchStudentRequest->reportFormat=="SEMESTER_WISE") | |
| { | |
| $sql ="select sa.studentID, sa.studentName, sa.regNo, sa.admissionNo, sa.studentEmail, sa.studentPhone, sa.parentPhone, sa.studentAddress, bt.batchName, sem.semName, dept.deptName, dept.departmentDesc, ecm.no_of_arrears as noOfArrears, ecm.percentage, ecm.sgpa, ecm.total_marks as totalMarks from studentaccount sa INNER JOIN batches bt ON bt.batchID=sa.batchID INNER JOIN semesters sem ON sem.semID=bt.semID INNER JOIN department dept ON dept.deptID=bt.deptID INNER JOIN ec_semster_consolidated_mark_details ecm ON ecm.student_id=sa.studentID AND ecm.sem_id=bt.semID LEFT JOIN course_type ct ON ct.courseTypeID=bt.courseTypeID LEFT JOIN course_pattern cp ON cp.patternID=bt.patternID LEFT JOIN pattern_deptcourses pd ON pd.patterncourseID=bt.patterncourseID WHERE sa.studentID IS NOT NULL"; | |
| } | |
| $condition=""; | |
| if(!empty($reportSearchStudentRequest->courseTypeRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->courseTypeRequests as $courseTypeRequest) { | |
| $condition .= $this->generateJoinConditions("ct", "courseTypeID", $courseTypeRequest->operator, $courseTypeRequest->courseTypeIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->batchRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->batchRequests as $batchRequests) { | |
| $condition .= $this->generateJoinConditions("bt", "batchID", $batchRequests->operator, $batchRequests->batchIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->courseRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->courseRequests as $courseRequest) { | |
| $condition .= $this->generateJoinConditions("pd", "patterncourseID", $courseRequest->operator, $courseRequest->courseIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->departmentRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->departmentRequests as $departmentRequest) { | |
| $condition .= $this->generateJoinConditions("bt", "deptID", $departmentRequest->operator, $departmentRequest->departmentIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->coursePatternRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->coursePatternRequests as $coursePatternRequest) { | |
| $condition .= $this->generateJoinConditions("cp", "patternID", $coursePatternRequest->operator, $coursePatternRequest->patternIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->admissionYearRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->admissionYearRequests as $admissionYearRequest) { | |
| $condition .= $this->generateJoinConditions("bt", "batchStartYear", $admissionYearRequest->operator, $admissionYearRequest->admissionYears); | |
| } | |
| }if(!empty($reportSearchStudentRequest->studentRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->studentRequests as $studentRequest) { | |
| $condition .= $this->generateJoinConditions("sa", "studentID", $studentRequest->operator, $studentRequest->studentIds); | |
| } | |
| } | |
| if(!empty($reportSearchStudentRequest->studentMarkRequests)) | |
| { | |
| foreach ($reportSearchStudentRequest->studentMarkRequests as $studentMarkRequest) { | |
| $columnName=""; | |
| switch($studentMarkRequest->operand) | |
| { | |
| case StudentMarkReportOperands::NO_OF_ARREARS: | |
| $columnName='no_of_arrears'; | |
| break; | |
| case StudentMarkReportOperands::PERCENTAGE: | |
| $columnName='percentage'; | |
| break; | |
| case StudentMarkReportOperands::CGPA: | |
| $columnName='cgpa'; | |
| break; | |
| case StudentMarkReportOperands::TOTAL_MARKS: | |
| $columnName='total_marks'; | |
| break; | |
| } | |
| $condition .= $this->generateJoinConditions("ecm", $columnName, $studentMarkRequest->operator, $studentMarkRequest->value); | |
| } | |
| } | |
| $sql .=$condition; | |
| try { | |
| return $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| } | |