Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 227 |
ExtraActivitiesService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 13 |
1806.00 | |
0.00% |
0 / 227 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
getAllActivitiesAssignedToStudentsInABatch | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 27 |
|||
getCourseOutcomes | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
upsertExtraActivities | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 36 |
|||
searchFeedbacks | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 23 |
|||
deleteExtraActivitiesCoMappingByActivityId | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
|||
getAllDistinctActivityNames | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
getAllActivities | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 22 |
|||
getActivityById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 17 |
|||
getCoPercentageOfActivity | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getActivityStudentDetailsById | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 42 |
<?php | |
namespace com\linways\core\ams\professional\service\nba; | |
use com\linways\core\ams\professional\service\BaseService; | |
use com\linways\core\ams\professional\request\nba\SearchFeedbacks; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\mapper\nba\ExtraActivitiesServiceMapper; | |
use com\linways\core\ams\professional\request\nba\GetExtraActivityRequest; | |
use com\linways\core\ams\professional\service\BatchService; | |
use com\linways\core\ams\professional\service\SemesterService; | |
use com\linways\core\ams\professional\service\CommonService; | |
use com\linways\core\ams\professional\dto\SettingsConstents; | |
class ExtraActivitiesService 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() | |
{ | |
$this->mapper = ExtraActivitiesServiceMapper::getInstance()->getMapper(); | |
} | |
// 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 GetExtraActivityRequest $request | |
* @return void | |
*/ | |
public function getAllActivitiesAssignedToStudentsInABatch($request) | |
{ | |
$sql = ""; | |
$responseList = []; | |
$request = $this->realEscapeObject($request); | |
if (empty($request->batchId)) { | |
throw new ProfessionalException(ProfessionalException::INSUFFICIENT_PARAMETERS, 'Given subject or batch is invalid.'); | |
} | |
$bulkFeedbackList = $this->getAllActivities($request->batchId); | |
if ( !empty($bulkFeedbackList)) { | |
foreach ($bulkFeedbackList as $bulkFeedback) { | |
$bulk_feedbackIDs[] = $bulkFeedback->id; | |
} | |
$bulk_feedbackIDs = implode(',',$bulk_feedbackIDs); | |
$studentList = $this->getActivityStudentDetailsById ( $bulk_feedbackIDs , $request->batchId, $request->semId, $request->subjectId, $request->staffId); | |
$courseOutcomes = $this->getCoPercentageOfActivity ( $request, $bulk_feedbackIDs ); | |
// Assigning each studentList and CO contributions into its object | |
foreach ($bulkFeedbackList as $bulkFeedback) { | |
$bulk_feedbackID = $bulkFeedback->id; | |
$response = $bulkFeedback; | |
$response->studentList = array_filter($studentList, function($obj) use ($bulk_feedbackID) { | |
return $obj->bulk_feedbackID === $bulk_feedbackID; | |
}); | |
$response->courseOutcomes = array_filter($courseOutcomes, function($obj) use ($bulk_feedbackID) { | |
return $obj->bulk_feedbackID === $bulk_feedbackID; | |
}); | |
$responseList[] = $response; | |
} | |
} | |
return $responseList; | |
} | |
public function getCourseOutcomes($request) | |
{ | |
$response = null; | |
$request = $this->realEscapeObject($request); | |
$sql = "SELECT id, code, objective, description, subjectID, staffID, batchID, semID, order_no FROM nba_course_outcome WHERE subjectID = ".$request->subjectId." AND batchID = ".$request->batchId." AND semID = ".$request->semId.""; | |
try { | |
$response = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $response; | |
} | |
/** | |
* | |
* @param GetExtraActivityRequest $request | |
* @return void | |
*/ | |
public function upsertExtraActivities($request, $coDetails) | |
{ | |
$ignoreNotAttendedStudents = CommonService::getInstance()->getSettings(SettingsConstents::STUDENT_EXTRA_ACTITITY, SettingsConstents::IGNORE_NOT_ATTENDED_STUDENTS); | |
$sql = ''; | |
$coIds = []; | |
$staffId = $_SESSION['staffID']; | |
$coDetails = $this->realEscapeArray($coDetails); | |
$request = $this->realEscapeObject($request); | |
$studentList = $this->getActivityStudentDetailsById($request->activityId, $request->batchId, $request->semId, $request->subjectId); | |
$studentIdList = []; | |
foreach ($studentList as $student) { | |
if ( $ignoreNotAttendedStudents == 1 && $student->isAttended == 0 ) { | |
continue; | |
} | |
$studentIdList[] = $student->studentID; | |
} | |
$studentIds = implode(",", $studentIdList); | |
$sql = "INSERT INTO nba_map_extra_activities_to_course_outcome ( feedback_about_student_feedbackID, nba_course_outcome_id, co_percentage, batchID, semID, subjectID, created_by, created_date, updated_by, updated_date) "; | |
$contribution = 100 / count($coDetails); | |
foreach ($coDetails as $coId) { | |
$values[] = "(SELECT feedbackID, ".$coId.", IF (isAttended, ".$contribution.", 0), ".$request->batchId.", ".$request->semId.", ".$request->subjectId.", ".$staffId.", utc_timestamp(), ".$staffId.", utc_timestamp() FROM feedback_about_student WHERE bulk_add_feedback_about_student_id = ".$request->activityId." and studentId in (".$studentIds."))"; | |
$coIds[]= $coId; | |
} | |
$sql .= implode(' UNION ', $values); | |
$sql .= " ON DUPLICATE KEY UPDATE | |
co_percentage = VALUES(co_percentage), | |
updated_by = VALUES(updated_by), | |
updated_date = utc_timestamp()"; | |
$coIds = implode(',', $coIds); | |
$this->deleteExtraActivitiesCoMappingByActivityId($request, $coIds); | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return true; | |
} | |
/** | |
* Method to get feedback ids. | |
* | |
* @param SearchFeedbacks $request | |
* @return void | |
*/ | |
public function searchFeedbacks($request) | |
{ | |
$responseList = null; | |
$request = $this->realEscapeObject($request); | |
$sql = "SELECT feedbackID as id, feedback_name as name FROM feedback_about_student WHERE 1=1 "; | |
if(!empty($request->feedbackId)){ | |
$sql .= " AND feedbackID = '$request->feedbackId' "; | |
} | |
if(!empty($request->feedbackTypeId)){ | |
$sql .= " AND student_feedback_type_id = '$request->feedbackTypeId' "; | |
} | |
if(!empty($request->feedbackName)){ | |
$sql .= " AND LOWER(TRIM(feedback_name)) = '$request->feedbackName'"; | |
} | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
if (empty($responseList)) { | |
return null; | |
} | |
return $responseList; | |
} | |
/** | |
* Delete Extra activities to CO mapping for bulk activity | |
* | |
* @param GetExtraActivityRequest $request | |
* @param string $coIds | |
* @throws ProfessionalException | |
* @return boolean | |
*/ | |
public function deleteExtraActivitiesCoMappingByActivityId($request, $coIds = NULL) | |
{ | |
$request = $this->realEscapeObject($request); | |
$coIds = $this->realEscapeString($coIds); | |
$sql = "DELETE mapco.* FROM nba_map_extra_activities_to_course_outcome mapco INNER JOIN feedback_about_student fas ON (mapco.feedback_about_student_feedbackID = fas.feedbackID) WHERE fas.bulk_add_feedback_about_student_id = ".$request->activityId." AND mapco.batchID = ".$request->batchId." AND mapco.semID = ".$request->semId." AND mapco.subjectID = ".$request->subjectId." "; | |
if ($coIds != NULL) { | |
$sql .= " AND mapco.nba_course_outcome_id NOT IN (".$coIds.") "; | |
} | |
try { | |
$this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return true; | |
} | |
/** | |
* get all distinct Activity Names(feedback_name in feedback_about_student table) | |
* | |
* @return void | |
*/ | |
public function getAllDistinctActivityNames() | |
{ | |
$sql = ""; | |
$responseList = []; | |
$feedBackList = []; | |
$sql = "SELECT distinct feedback_name as feedbackName FROM feedback_about_student"; | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
foreach ($responseList as $value) { | |
$feedBackList[] = $value->feedbackName; | |
} | |
return $feedBackList; | |
} | |
/** | |
* Get all activities in a batch (Activities are batch specific) | |
* | |
* @return void | |
*/ | |
public function getAllActivities($batchId, $semId = NULL, $subjectId = NULL) { | |
$semId = $this->realEscapeString($semId); | |
$batchId = $this->realEscapeString($batchId); | |
$subjectId = $this->realEscapeString($subjectId); | |
$conditions = ''; | |
// $conditions .= $semId ? " AND bulkfb.semID = ".$semId." " : ''; | |
// $conditions .= $subjectId ? " AND bulkfb.subjectID = ".$subjectId." " : ''; | |
$sql = "SELECT | |
bulkfb.id, | |
bulkfb.name AS feedbackName, | |
bulkfb.description, | |
sft.is_activity, | |
sft.id AS feedbackTypeId, | |
sft.name AS feedbackTypeName, | |
sft.description AS activity_type_desc, | |
sft.activity_points, | |
sft.use_in_co, | |
sft.use_in_po FROM bulk_add_feedback_about_student bulkfb INNER JOIN student_feedback_type sft ON (bulkfb.student_feedback_type_id = sft.id AND sft.is_activity = 1 AND (sft.use_in_co = 1 OR sft.use_in_po = 1)) WHERE bulkfb.batchID = ".$batchId." ".$conditions.""; | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $responseList; | |
} | |
public function getActivityById ( $activity_id ) { | |
$sql = "SELECT | |
bulkfb.id AS activity_id, | |
bulkfb.name AS activity_name, | |
bulkfb.description AS activity_desc, | |
bulkfb.student_feedback_type_id, | |
sft.name AS activity_type_name, | |
sft.description AS activity_type_desc, | |
sft.activity_points, | |
sft.use_in_co, | |
sft.use_in_po FROM bulk_add_feedback_about_student bulkfb INNER JOIN student_feedback_type sft ON ( bulkfb.student_feedback_type_id = sft.id AND sft.is_activity = 1 AND sft.use_in_co = 1 ) WHERE bulkfb.id = ".$activity_id.""; | |
try { | |
$response = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $response; | |
} | |
public function getCoPercentageOfActivity ( $request, $activityId) { | |
$request = $this->realEscapeObject($request); | |
$activityId = $this->realEscapeString($activityId); | |
// Don't change "bulk_add_feedback_about_student_id IN " in the sql query as the activity is can be comma seperated activity ids | |
$sql = "SELECT mapco.nba_course_outcome_id AS co_id, mapco.co_percentage, fas.bulk_add_feedback_about_student_id AS bulk_feedbackID FROM nba_map_extra_activities_to_course_outcome mapco INNER JOIN feedback_about_student fas ON (mapco.feedback_about_student_feedbackID = fas.feedbackID) WHERE fas.bulk_add_feedback_about_student_id IN (".$activityId.") AND mapco.batchID = ".$request->batchId." AND mapco.semID = ".$request->semId." AND mapco.subjectID = ".$request->subjectId." GROUP BY fas.bulk_add_feedback_about_student_id, mapco.nba_course_outcome_id"; | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $responseList; | |
} | |
public function getActivityStudentDetailsById ( $activity_id , $batchId, $semId, $subjectId, $staffId = NULL) { | |
$activity_id = $this->realEscapeString($activity_id); | |
$semId = $this->realEscapeString($semId); | |
$batchId = $this->realEscapeString($batchId); | |
$subjectId = $this->realEscapeString($subjectId); | |
if(empty($sortByColumn)){ | |
try{ | |
$sortByColumn = BatchService::getInstance()->getStudentSortByColumnOfABatch($batchId); | |
}catch(\Exception $e){ | |
$sortByColumn = 'rollNo'; | |
} | |
} | |
$subbatches = BatchService::getInstance()->getSubbatchBySubject($subjectId, $semId, $batchId, $staffId); | |
$isCurrentSem = SemesterService::getInstance()->isCurrentSemester($batchId, $semId); | |
// Don't change "bulk_add_feedback_about_student_id IN " in the sql query | |
if(empty($subbatches)) | |
{ | |
if($isCurrentSem) | |
{ | |
$sql = "SELECT fas.bulk_add_feedback_about_student_id AS bulk_feedbackID, fas.feedbackID, sa.studentID, sa.studentName, fas.isAttended, sa.rollNo, sa.regNo FROM feedback_about_student fas INNER JOIN studentaccount sa ON (fas.studentID = sa.studentID) WHERE fas.bulk_add_feedback_about_student_id IN (".$activity_id.") and sa.batchID = $batchId ORDER BY $sortByColumn"; | |
} | |
else | |
{ | |
$sql = "SELECT fas.bulk_add_feedback_about_student_id AS bulk_feedbackID, fas.feedbackID, sa.studentID, sa.studentName, fas.isAttended, sa.rollNo, sa.regNo FROM feedback_about_student fas INNER JOIN studentaccount sa ON (fas.studentID = sa.studentID) WHERE fas.bulk_add_feedback_about_student_id IN (".$activity_id.") and sa.studentID in (select studentID from studentaccount where batchID = $batchId union select studentID from failed_students where previousBatch = $batchId and failedInSemester > $semId) ORDER BY $sortByColumn;"; | |
} | |
} | |
else | |
{ | |
if($isCurrentSem) | |
{ | |
$sql = "SELECT distinct fas.bulk_add_feedback_about_student_id AS bulk_feedbackID, fas.feedbackID, sa.studentID, sa.studentName, fas.isAttended, sa.rollNo, sa.regNo from sbs_relation sr inner join subbatch_sbs ssbs on sr.sbsID = ssbs.sbsID inner join subbatch_student ss on ss.subbatchID = ssbs.subbatchID inner join studentaccount sa on sa.studentID = ss.studentID inner join feedback_about_student fas on (fas.studentID = sa.studentID) where sr.batchID = $batchId and sr.semID = $semId and subjectID = $subjectId and fas.bulk_add_feedback_about_student_id IN (".$activity_id.") ORDER BY $sortByColumn;"; | |
} | |
else | |
{ | |
$sql = "SELECT distinct fas.bulk_add_feedback_about_student_id AS bulk_feedbackID, fas.feedbackID, sa.studentID, sa.studentName, fas.isAttended, sa.rollNo, sa.regNo from sbs_relation sr inner join subbatch_sbs ssbs on sr.sbsID = ssbs.sbsID inner join subbatch_student ss on ss.subbatchID = ssbs.subbatchID inner join studentaccount sa on sa.studentID = ss.studentID inner join feedback_about_student fas on (fas.studentID = sa.studentID) where sr.batchID = $batchId and sr.semID = $semId and subjectID = $subjectId and fas.bulk_add_feedback_about_student_id IN (".$activity_id.") and sa.studentID in (select studentID from studentaccount where batchID = $batchId union select studentID from failed_students where previousBatch = $batchId and failedInSemester > $semId) ORDER BY $sortByColumn"; | |
} | |
} | |
try { | |
$responseList = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $responseList; | |
} | |
} |