Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 20 |
CRAP | |
0.00% |
0 / 542 |
| AuditCourseCertificateService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 20 |
11990.00 | |
0.00% |
0 / 542 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| saveCategory | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 34 |
|||
| validateSaveAuditCourseCategory | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 10 |
|||
| insertAuditCourseCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| updateAuditCourseCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 17 |
|||
| deleteAuditCourseCategory | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 26 |
|||
| getCategories | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 44 |
|||
| saveCategoryHead | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 30 |
|||
| validateSaveAuditCourseCategoryHead | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 10 |
|||
| insertAuditCourseCategoryHead | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| deleteAuditCourseCategoryHead | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 23 |
|||
| getCategoryHead | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 24 |
|||
| getAllStudentsForAuditCourse | |
0.00% |
0 / 1 |
380.00 | |
0.00% |
0 / 73 |
|||
| getStudentAuditCourseDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 14 |
|||
| saveStudentAuditCourseCertificate | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 38 |
|||
| saveStudentAuditCourseDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 19 |
|||
| insertStudentAuditCourseDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| updateStudentAuditCourseDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 16 |
|||
| printStudentAuditCourseCertificate | |
0.00% |
0 / 1 |
420.00 | |
0.00% |
0 / 104 |
|||
| countOfAlreadyAssignedCategoryInStudetntCertificate | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 24 |
|||
| <?php | |
| namespace com\linways\ec\core\service; | |
| use com\linways\base\util\MakeSingletonTrait; | |
| use com\linways\base\util\SecurityUtils; | |
| use com\linways\ec\core\constant\StatusConstants; | |
| use com\linways\ec\core\exception\ExamControllerException; | |
| use com\linways\ec\core\dto\AuditCourseCategory; | |
| use com\linways\ec\core\dto\AuditCourseCategoryHead; | |
| use com\linways\ec\core\logging\Events; | |
| use com\linways\ec\core\logging\entities\Staff; | |
| use com\linways\core\ams\professional\logging\AMSLogger; | |
| use com\linways\ec\core\service\CommonExamService; | |
| use com\linways\base\util\TwigRenderer; | |
| use com\linways\core\ams\professional\util\PdfUtil; | |
| use com\linways\core\ams\professional\service\StudentService; | |
| class AuditCourseCertificateService extends BaseService | |
| { | |
| use MakeSingletonTrait; | |
| private function __construct() | |
| { | |
| $this->logger = AMSLogger::getLogger('exam-controller-log'); | |
| } | |
| /** | |
| * Save audit course category | |
| * @param AuditCourseCategory $auditCategory | |
| * @return $id | |
| */ | |
| public function saveCategory(AuditCourseCategory $auditCategory){ | |
| $auditCategory = $this->realEscapeObject($auditCategory); | |
| $staffId = $GLOBALS['userId']; | |
| $auditCategory->createdBy = $auditCategory->createdBy ?? $staffId; | |
| $auditCategory->updatedBy = $auditCategory->updatedBy ?? $staffId; | |
| try { | |
| $this->validateSaveAuditCourseCategory($auditCategory); | |
| if (!empty($auditCategory->id)) { | |
| $auditCategory->id = $this->updateAuditCourseCategory($auditCategory); | |
| } else { | |
| $auditCategory->id = $this->insertAuditCourseCategory($auditCategory); | |
| } | |
| $this->logger->info(Events::EC_SAVE_AUDIT_COURSE_CATEGORY, [ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $auditCategory, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| } catch (\Exception $e) { | |
| $this->logger->error(Events::EC_SAVE_AUDIT_COURSE_CATEGORY, [ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $auditCategory, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException($e->getCode(), "Failed to save Fee Type! Please try again"); | |
| } else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) { | |
| throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot create category.This category already created"); | |
| } else { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| return $auditCategory->id; | |
| } | |
| /** | |
| * Validate Category type Request Before Saving | |
| * @param AuditCourseCategory $auditCategory | |
| * @return NULL | |
| */ | |
| private function validateSaveAuditCourseCategory(AuditCourseCategory $auditCategory){ | |
| if (empty($auditCategory->name)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category name is empty! Please fill name "); | |
| } | |
| if (empty($auditCategory->priority)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category priority is empty! Please fill priority "); | |
| } | |
| if (empty($auditCategory->courseTypeId)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category course type is empty! Please fill course type "); | |
| } | |
| } | |
| /** | |
| * Insert audit course category type | |
| * @param AuditCourseCategory $auditCategory | |
| * @return $id | |
| */ | |
| private function insertAuditCourseCategory(AuditCourseCategory $auditCategory){ | |
| $query = "INSERT INTO ec_audit_course_categories | |
| (categoryName,priority,courseTypeID,created_by,created_date) | |
| VALUES | |
| ('$auditCategory->name','$auditCategory->priority','$auditCategory->courseTypeId','$auditCategory->createdBy',now())"; | |
| try { | |
| $auditCategory->id = $this->executeQuery($query,true)->id; | |
| return $auditCategory->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Update Fee types | |
| * @param AuditCourseCategory $auditCategory | |
| * @return $auditCategory->id | |
| */ | |
| private function updateAuditCourseCategory(AuditCourseCategory $auditCategory){ | |
| $query = "UPDATE | |
| ec_audit_course_categories | |
| SET | |
| categoryName = '$auditCategory->name', | |
| priority = '$auditCategory->priority', | |
| courseTypeID = '$auditCategory->courseTypeId', | |
| updated_by = '$auditCategory->updatedBy', | |
| updated_date = 'utc_timestamp()' | |
| WHERE | |
| id = '$auditCategory->id'"; | |
| try { | |
| $this->executeQuery($query); | |
| return $auditCategory->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete Exam Fee Type | |
| * @param String $id | |
| * @return NULL | |
| */ | |
| public function deleteAuditCourseCategory($id){ | |
| $id = $this->realEscapeString($id); | |
| $staffId = $GLOBALS['userId']; | |
| $searchRequest = new \stdClass(); | |
| $searchRequest->id = $id; | |
| $currentAuditCourseCategoryDetails = reset($this->getCategories($searchRequest)); | |
| if(empty($currentAuditCourseCategoryDetails)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS,"Can't delete ! Category missing."); | |
| } | |
| if(($currentAuditCourseCategoryDetails->categoryHeadId)){ | |
| throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Can't delete ! Category Head already assign."); | |
| } | |
| $query = "DELETE FROM | |
| ec_audit_course_categories | |
| WHERE | |
| id = '$id'"; | |
| try { | |
| $this->executeQuery($query); | |
| // LOGGING | |
| $this->logger->info(Events::EC_DELETE_AUDIT_COURSE_CATEGORY,[ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $currentAuditCourseCategoryDetails, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| }catch (\Exception $e) { | |
| throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Error deleting category ! Please try again"); | |
| } | |
| } | |
| /** | |
| * get Category | |
| * @param $searchRequest | |
| * @return $categories | |
| */ | |
| public function getCategories($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $whereQuery = null; | |
| $whereQuery = ""; | |
| $categories = []; | |
| if (!empty($searchRequest->id)) { | |
| $categoryTypeIdString = is_array($searchRequest->id) ? "'" . implode("','", $searchRequest->id) . "'" : "'" . $searchRequest->id . "'"; | |
| $whereQuery .= " AND eacc.id IN ( $categoryTypeIdString )"; | |
| } | |
| if (!empty($searchRequest->courseTypeId)) { | |
| $courseTypeIdString = is_array($searchRequest->courseTypeId) ? "'" . implode("','", $searchRequest->courseTypeId) . "'" : "'" . $searchRequest->courseTypeId . "'"; | |
| $whereQuery .= " AND ct.courseTypeID IN ( $courseTypeIdString )"; | |
| } | |
| if($searchRequest->isPriority){ | |
| $orderBy = " ORDER BY eacc.priority ASC"; | |
| } | |
| else{ | |
| $orderBy = " ORDER BY eacc.created_date DESC"; | |
| } | |
| $query = "SELECT | |
| DISTINCT | |
| eacc.id as id, | |
| eacc.categoryName as name, | |
| eacc.courseTypeID as courseTypeId, | |
| eacc.priority as priority, | |
| ct.typeName as courseTypeName, | |
| eacsc.id as categoryHeadId, | |
| eacsc.headName as categoryHeadName, | |
| eacsc.priority as categoryHeadPriority, | |
| eacsc.isCredit as isCreaditCategoryHead | |
| FROM | |
| ec_audit_course_categories eacc | |
| INNER JOIN course_type ct ON | |
| ct.courseTypeID = eacc.courseTypeID | |
| LEFT JOIN ec_audit_course_sub_categories eacsc ON | |
| eacsc.categoryID = eacc.id | |
| WHERE | |
| 1 = 1 "; | |
| $categories = $this->executeQueryForList($query . $whereQuery.$orderBy); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| return $categories; | |
| } | |
| /** | |
| * Save audit course category head | |
| * @param AuditCourseCategoryHead $auditCategoryHead | |
| * @return $id | |
| */ | |
| public function saveCategoryHead(AuditCourseCategoryHead $auditCategoryHead){ | |
| $auditCategoryHead = $this->realEscapeObject($auditCategoryHead); | |
| $staffId = $GLOBALS['userId']; | |
| $auditCategoryHead->createdBy = $auditCategoryHead->createdBy ?? $staffId; | |
| $auditCategoryHead->updatedBy = $auditCategoryHead->updatedBy ?? $staffId; | |
| try { | |
| $this->validateSaveAuditCourseCategoryHead($auditCategoryHead); | |
| $auditCategoryHead->id = $this->insertAuditCourseCategoryHead($auditCategoryHead); | |
| $this->logger->info(Events::EC_SAVE_AUDIT_COURSE_CATEGORY_HEAD, [ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $auditCategoryHead, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| } catch (\Exception $e) { | |
| $this->logger->error(Events::EC_SAVE_AUDIT_COURSE_CATEGORY_HEAD, [ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $auditCategoryHead, | |
| "errorCode" => $e->getCode(), | |
| "errorMessage" => $e->getMessage(), | |
| "status" => StatusConstants::FAILED | |
| ]); | |
| if ($e->getCode() !== ExamControllerException::INVALID_PARAMETERS && $e->getCode() !== ExamControllerException::EMPTY_PARAMETERS && $e->getCode() !== "DUPLICATE_ENTRY") { | |
| throw new ExamControllerException($e->getCode(), "Failed to save Fee Type! Please try again"); | |
| } else if ($e->getCode() === ExamControllerException::DUPLICATE_ENTRY) { | |
| throw new ExamControllerException(ExamControllerException::DUPLICATE_ENTRY, "Cannot create category.This category already created"); | |
| } else { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| return $auditCategoryHead->id; | |
| } | |
| /** | |
| * Validate Category head Request Before Saving | |
| * @param AuditCourseCategoryHead $auditCategoryHead | |
| * @return NULL | |
| */ | |
| private function validateSaveAuditCourseCategoryHead(AuditCourseCategoryHead $auditCategoryHead){ | |
| if (empty($auditCategoryHead->name)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category head name is empty! Please fill name "); | |
| } | |
| if (empty($auditCategoryHead->priority)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category head priority is empty! Please fill priority "); | |
| } | |
| if (empty($auditCategoryHead->categoryId)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " category is empty! Please fill category "); | |
| } | |
| } | |
| /** | |
| * Insert audit course category type | |
| * @param AuditCourseCategoryHead $auditCategoryHead | |
| * @return $id | |
| */ | |
| private function insertAuditCourseCategoryHead(AuditCourseCategoryHead $auditCategoryHead){ | |
| $query = "INSERT INTO ec_audit_course_sub_categories | |
| (headName,priority,categoryID,isCredit,created_by,created_date) | |
| VALUES | |
| ('$auditCategoryHead->name','$auditCategoryHead->priority','$auditCategoryHead->categoryId','$auditCategoryHead->isCredit','$auditCategoryHead->createdBy',now())"; | |
| try { | |
| $auditCategoryHead->id = $this->executeQuery($query,true)->id; | |
| return $auditCategoryHead->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete Exam Fee Type | |
| * @param String $id | |
| * @return NULL | |
| */ | |
| public function deleteAuditCourseCategoryHead($id){ | |
| $id = $this->realEscapeString($id); | |
| $staffId = $GLOBALS['userId']; | |
| $searchRequest = new \stdClass(); | |
| $searchRequest->id = $id; | |
| $currentAuditCourseCategoryHeadDetails = reset($this->getCategoryHead($searchRequest)); | |
| if(empty($currentAuditCourseCategoryHeadDetails)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS,"Can't delete ! Category head missing."); | |
| } | |
| $query = "DELETE FROM | |
| ec_audit_course_sub_categories | |
| WHERE | |
| id = '$id'"; | |
| try { | |
| $this->executeQuery($query); | |
| // LOGGING | |
| $this->logger->info(Events::EC_DELETE_AUDIT_COURSE_CATEGORY_HEAD,[ | |
| "staff" => new Staff(["id" => $staffId]), | |
| "request" => $currentAuditCourseCategoryHeadDetails, | |
| "status" => StatusConstants::SUCCESS | |
| ]); | |
| }catch (\Exception $e) { | |
| throw new ExamControllerException(ExamControllerException::HAVE_RELATION,"Error deleting category ! Please try again"); | |
| } | |
| } | |
| /** | |
| * get Category Head | |
| * @param $searchRequest | |
| * @return $categories | |
| */ | |
| public function getCategoryHead($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $whereQuery = null; | |
| $whereQuery = ""; | |
| if (!empty($searchRequest->id)) { | |
| $categoryTypeIdString = is_array($searchRequest->id) ? "'" . implode("','", $searchRequest->id) . "'" : "'" . $searchRequest->id . "'"; | |
| $whereQuery .= " AND eacsc.id IN ( $categoryTypeIdString )"; | |
| } | |
| $query = "SELECT | |
| DISTINCT | |
| eacsc.id as id, | |
| eacsc.headName as name, | |
| eacsc.categoryID as categoryId, | |
| eacsc.priority as priority | |
| FROM | |
| ec_audit_course_sub_categories eacsc | |
| WHERE | |
| 1 = 1 "; | |
| $categories = $this->executeQueryForList($query . $whereQuery.$orderBy); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| return $categories; | |
| } | |
| /** | |
| * get All Students for audit course | |
| * @param $searchRequest | |
| * @return $students | |
| */ | |
| public function getAllStudentsForAuditCourse($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $students = []; | |
| if (empty($searchRequest->groupId) || empty($searchRequest->programId)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " Empty parameter. Please choose batch and program"); | |
| } | |
| $reguestForBatchStudents = new \stdClass(); | |
| $reguestForBatchStudents->groupId = $searchRequest->groupId; | |
| $reguestForBatchStudents->programId = $searchRequest->programId; | |
| $students = CommonExamService::getInstance()->getStudentsDetailsByBatchProgram($reguestForBatchStudents); | |
| if(empty($students)){ | |
| throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No students found in this batch"); | |
| } | |
| $reguestForCategories = new \stdClass(); | |
| $reguestForCategories->courseTypeId = reset($students)->courseTypeId; | |
| $reguestForCategories->isPriority = true; | |
| $categoryList = $this->getCategories($reguestForCategories); | |
| if(empty($categoryList)){ | |
| throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No audit course category found.s"); | |
| } | |
| foreach($students as $student){ | |
| $categories = []; | |
| foreach ($categoryList as $category){ | |
| $categories[$category->id]->id = $category->id; | |
| $categories[$category->id]->name = $category->name; | |
| $categories[$category->id]->courseTypeId = $category->courseTypeId; | |
| $categories[$category->id]->priority = $category->priority; | |
| $categories[$category->id]->courseTypeName = $category->courseTypeName; | |
| if($category->categoryHeadId){ | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->id = $category->categoryHeadId; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->name = $category->categoryHeadName; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->priority = $category->categoryHeadPriority; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->isCredit = $category->isCreaditCategoryHead; | |
| } | |
| } | |
| $categoryListArr = []; | |
| $categoryListArr = $categories; | |
| $appliedDetails = $this->getStudentAuditCourseDetails($student->id); | |
| $student->isApplied = $appliedDetails ? 1 : 0; | |
| if($appliedDetails){ | |
| $categoryDetails = json_decode($appliedDetails->applied_details); | |
| foreach($categoryDetails as $catId => $category){ | |
| $category = (array)$category; | |
| $categoryListArr[$catId]->eventSelected = $category; | |
| $student->hasDetails = 1; | |
| foreach($category as $oneCategory){ | |
| $oneCategory->categoryHeads = (array)$oneCategory->categoryHeads; | |
| foreach($oneCategory->categoryHeads as $catHead){ | |
| if($catHead->value && (strlen($catHead->value) >2)) | |
| $categoryCourseNamesArray[$catHead->value] = $catHead->value; | |
| } | |
| } | |
| } | |
| } | |
| foreach($categoryListArr as $category){ | |
| uasort($category->categoryHeads, function ($a, $b) { | |
| return $a->priority > $b->priority; | |
| }); | |
| if(empty($category->eventSelected)){ | |
| $category->eventSelected = []; | |
| $request = new \stdClass(); | |
| $request->uniqueId = substr(md5(mt_rand()), 0, 7); | |
| $request->categoryHeads = $category->categoryHeads; | |
| $category->eventSelected[] = $request; | |
| } | |
| $category->extraColmn = count($category->categoryHeads) % 2 == 0 ? false : true; | |
| } | |
| $student->categoryList = array_values($categoryListArr); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| return $students; | |
| } | |
| /** | |
| * get student audit certificated | |
| * @return $auditCourseDetails | |
| * @throws ExamControllerException | |
| */ | |
| public function getStudentAuditCourseDetails($studentId) { | |
| $studentId = $this->realEscapeString($studentId); | |
| $sql = "SELECT id, | |
| applied_details, | |
| applied_date | |
| FROM | |
| ec_audit_course_applied_students | |
| WHERE studentID = $studentId "; | |
| try { | |
| $auditCourseDetails = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $auditCourseDetails; | |
| } | |
| /** | |
| * save Student Audit Course Certificate | |
| * @param $searchRequest | |
| * @return $students | |
| */ | |
| public function saveStudentAuditCourseCertificate($student){ | |
| $student = $this->realEscapeObject($student); | |
| try { | |
| $isNotValidCredit = 0; | |
| foreach($student->categoryList as $category){ | |
| foreach($category->eventSelected as $levelKey => $level){ | |
| $found = 0; | |
| $level->categoryHeads = (array)$level->categoryHeads; | |
| foreach($level->categoryHeads as $head){ | |
| $head = (object) $head; | |
| if($head->value){ | |
| $found = 1; | |
| if( $head->isCredit && !is_numeric($head->value)){ | |
| $isNotValidCredit = 1; | |
| } | |
| } | |
| } | |
| if(!$found){ | |
| unset($category->eventSelected[$levelKey]); | |
| } | |
| } | |
| if($category->eventSelected){ | |
| $categories[$category->id] = $category->eventSelected; | |
| } | |
| } | |
| if($isNotValidCredit){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, "Invailed credit"); | |
| } | |
| else{ | |
| $saveAuditCourseCertificate = new \stdClass(); | |
| $saveAuditCourseCertificate->appliedDetails = $categories; | |
| $saveAuditCourseCertificate->studentId = $student->id; | |
| $saveAuditCourseCertificate->id = $this->saveStudentAuditCourseDetails($saveAuditCourseCertificate); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| return $student; | |
| } | |
| /** | |
| * save student audit certificated | |
| * @param $request | |
| */ | |
| public function saveStudentAuditCourseDetails($request) { | |
| $request = $this->realEscapeObject($request); | |
| try { | |
| $requestForSaveAuditCourse = new \stdClass(); | |
| $requestForSaveAuditCourse->appliedDetails = json_encode($request->appliedDetails); | |
| $requestForSaveAuditCourse->date = date('Y-m-d'); | |
| $requestForSaveAuditCourse->studentId = $request->studentId; | |
| $requestForSaveAuditCourse->staffId = $GLOBALS['userId']; | |
| $auditCourseDetails = $this->getStudentAuditCourseDetails($request->studentId); | |
| if($auditCourseDetails){ | |
| $requestForSaveAuditCourse->id = $auditCourseDetails->id; | |
| $this->updateStudentAuditCourseDetails($requestForSaveAuditCourse); | |
| } | |
| else{ | |
| $this->insertStudentAuditCourseDetails($requestForSaveAuditCourse); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Insert student audit course details | |
| * @param $requestForSaveAuditCourse | |
| * @return $id | |
| */ | |
| private function insertStudentAuditCourseDetails( $requestForSaveAuditCourse){ | |
| $query = "INSERT INTO ec_audit_course_applied_students | |
| (studentID,applied_details,applied_date,created_by) | |
| VALUES | |
| ('$requestForSaveAuditCourse->studentId','$requestForSaveAuditCourse->appliedDetails','$requestForSaveAuditCourse->date','$requestForSaveAuditCourse->staffId')"; | |
| try { | |
| $requestForSaveAuditCourse->id = $this->executeQuery($query,true)->id; | |
| return $requestForSaveAuditCourse->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Update student audit course details | |
| * @param $requestForSaveAuditCourse | |
| * @return $id | |
| */ | |
| private function updateStudentAuditCourseDetails( $requestForSaveAuditCourse){ | |
| $query = "UPDATE | |
| ec_audit_course_applied_students | |
| SET | |
| studentID = '$requestForSaveAuditCourse->studentId', | |
| applied_details = '$requestForSaveAuditCourse->appliedDetails', | |
| applied_date = '$requestForSaveAuditCourse->date', | |
| created_by = '$requestForSaveAuditCourse->staffId' | |
| WHERE | |
| id = '$requestForSaveAuditCourse->id'"; | |
| try { | |
| $this->executeQuery($query); | |
| return $requestForSaveAuditCourse->id; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * print Students for audit course | |
| * @param $searchRequest | |
| * @return $students | |
| */ | |
| public function printStudentAuditCourseCertificate($searchRequest){ | |
| $searchRequest = $this->realEscapeObject($searchRequest); | |
| try { | |
| $students = []; | |
| if (empty($searchRequest->groupId) || empty($searchRequest->programId)){ | |
| throw new ExamControllerException(ExamControllerException::EMPTY_PARAMETERS, " Empty parameter. Please choose batch and program"); | |
| } | |
| $reguestForBatchStudents = new \stdClass(); | |
| $reguestForBatchStudents->studentId = $searchRequest->studentId; | |
| $reguestForBatchStudents->groupId = $searchRequest->groupId; | |
| $reguestForBatchStudents->programId = $searchRequest->programId; | |
| $students = CommonExamService::getInstance()->getStudentsDetailsByBatchProgram($reguestForBatchStudents); | |
| if(empty($students)){ | |
| throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No students found in this batch"); | |
| } | |
| $reguestForCategories = new \stdClass(); | |
| $reguestForCategories->courseTypeId = reset($students)->courseTypeId; | |
| $reguestForCategories->isPriority = true; | |
| $categoryList = $this->getCategories($reguestForCategories); | |
| if(empty($categoryList)){ | |
| throw new ExamControllerException(ExamControllerException::NO_DETAILS_FOUND,"No audit course category found.s"); | |
| } | |
| foreach($students as $student){ | |
| $student->studentImage = StudentService::getInstance()->getStudentProfilePic($student->id)->docpath; | |
| $student->totalCredit = 0; | |
| $categories = []; | |
| foreach ($categoryList as $category){ | |
| $categories[$category->id]->id = $category->id; | |
| $categories[$category->id]->name = $category->name; | |
| $categories[$category->id]->courseTypeId = $category->courseTypeId; | |
| $categories[$category->id]->priority = $category->priority; | |
| $categories[$category->id]->courseTypeName = $category->courseTypeName; | |
| if($category->categoryHeadId){ | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->id = $category->categoryHeadId; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->name = $category->categoryHeadName; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->priority = $category->categoryHeadPriority; | |
| $categories[$category->id]->categoryHeads[$category->categoryHeadId]->isCredit = $category->isCreaditCategoryHead; | |
| } | |
| } | |
| $categoryListArr = []; | |
| $categoryListArr = $categories; | |
| $appliedDetails = $this->getStudentAuditCourseDetails($student->id); | |
| if($appliedDetails){ | |
| $categoryDetails = json_decode($appliedDetails->applied_details); | |
| foreach($categoryDetails as $catId => $category){ | |
| $category = (array)$category; | |
| $categoryListArr[$catId]->eventSelected = $category; | |
| $student->hasDetails = 1; | |
| foreach($category as $oneCategory){ | |
| $oneCategory->categoryHeads = (array)$oneCategory->categoryHeads; | |
| $creditArr = array_filter((array)$oneCategory->categoryHeads, function($obj) { | |
| return $obj->isCredit == 1; | |
| }); | |
| if(current($creditArr)->value && is_numeric(current($creditArr)->value)){ | |
| $student->totalCredit += current($creditArr)->value; | |
| } | |
| foreach($oneCategory->categoryHeads as $catHead){ | |
| if($catHead->value && (strlen($catHead->value) >2)) | |
| $categoryCourseNamesArray[$catHead->value] = $catHead->value; | |
| } | |
| } | |
| } | |
| } | |
| foreach($categoryListArr as $category){ | |
| uasort($category->categoryHeads, function ($a, $b) { | |
| return $a->priority > $b->priority; | |
| }); | |
| if(empty($category->eventSelected)){ | |
| $category->eventSelected = []; | |
| $request = new \stdClass(); | |
| $request->uniqueId = substr(md5(mt_rand()), 0, 7); | |
| $request->categoryHeads = $category->categoryHeads; | |
| $category->eventSelected[] = $request; | |
| } | |
| $category->extraColmn = count($category->categoryHeads) % 2 == 0 ? false : true; | |
| } | |
| $student->categoryList = array_values($categoryListArr); | |
| } | |
| $additionalDetails = new \stdClass(); | |
| $additionalDetails->currentDate = date('d F Y'); | |
| $templateName = 'audit_certificate'; | |
| $responseHtml = TwigRenderer::renderTemplateFileToHtml(realpath(DOCUMENT_ROOT."../examcontroller-api/src/com/linways/web/templates/AuditCourseCertificate/$templateName.twig"), [ 'students'=>$students ,'additionalDetails'=>$additionalDetails]); | |
| $prtContent = NULL; | |
| $prtContent .= '<html><head>'; | |
| $prtContent .= ""; | |
| $prtContent .= '</head><title>Audit Course Certificate</title><body>'; | |
| $prtContent .= $responseHtml; | |
| $prtContent .= '</body></html>'; | |
| $totalWidth = 210; | |
| $totalHeight = 297; | |
| $options = array( | |
| 'page-width' => $totalWidth."mm", | |
| 'page-height' => $totalHeight."mm", | |
| 'dpi' => 96, | |
| 'margin-top' => "10mm", | |
| 'margin-left' => "10mm", | |
| 'margin-right' => "10mm", | |
| 'margin-bottom' => "10mm", | |
| // 'binary' => "/usr/local/bin/wkhtmltopdf", // For Mac | |
| 'user-style-sheet' => realpath(DOCUMENT_ROOT . "/libcommon/bootstrap/css/bootstrap.min.css") | |
| ); | |
| $response->dispalyHtmlData = $responseHtml; | |
| $response->printData = PdfUtil::renderPdf($prtContent, $options); | |
| return $response; | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * count alredy assigned category | |
| * @return $countOfAssignedStudents | |
| * @throws ExamControllerException | |
| */ | |
| public function countOfAlreadyAssignedCategoryInStudetntCertificate($categoryId) { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $countOfAssignedStudents = 0; | |
| $sql = "SELECT DISTINCT | |
| eacas.id as id, | |
| eacas.studentID as studentId, | |
| eacas.applied_details as appliedDetails | |
| FROM | |
| ec_audit_course_applied_students eacas | |
| WHERE | |
| 1 = 1"; | |
| try { | |
| $appliedStudentsDetails = $this->executeQueryForList($sql); | |
| foreach($appliedStudentsDetails as $appliedStudent){ | |
| $appliedStudent->appliedDetails = (array)json_decode($appliedStudent->appliedDetails); | |
| $appliedStudent->categoryIds = array_keys($appliedStudent->appliedDetails); | |
| if(in_array($categoryId,$appliedStudent->categoryIds)){ | |
| $countOfAssignedStudents++; | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw new ExamControllerException($e->getCode(),$e->getMessage()); | |
| } | |
| return $countOfAssignedStudents; | |
| } | |
| } |