Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 123 |
AssignmentReportService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
420.00 | |
0.00% |
0 / 123 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
generateAsyncAssignmentStudentDocFile | |
0.00% |
0 / 1 |
156.00 | |
0.00% |
0 / 71 |
|||
getAllStudentsAssignmentMarks | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 43 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\util\CommonUtil; | |
use com\linways\core\ams\professional\constant\BackendTypes; | |
use com\linways\core\ams\professional\util\S3Utils; | |
use com\linways\core\ams\professional\request\UploadResourceRequest; | |
use com\linways\core\ams\professional\constant\ResourceContext; | |
use com\linways\base\util\SecurityUtils; | |
use com\linways\core\ams\professional\request\GetAsyncReportRequest; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\mapper\AssignmentServiceMapper; | |
use com\linways\core\ams\professional\constant\SettingsConstants; | |
use com\linways\core\ams\professional\service\CommonService; | |
class AssignmentReportService 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 = AssignmentServiceMapper::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; | |
} | |
public function generateAsyncAssignmentStudentDocFile($request) | |
{ | |
try { | |
$files = array(); | |
$zipname = $request->reportName.".zip"; | |
$zipPath=DOCUMENT_ROOT."studentdocs/$request->collegeCode"; | |
if(!empty($request->studentDocList)) | |
{ | |
foreach($request->studentDocList as $student) | |
{ | |
$url=false; | |
$filepath=""; | |
if($student->backend_type==BackendTypes::LOCAL_STORAGE) | |
{ | |
$filepath=DOCUMENT_ROOT.substr($student->path,3); | |
} | |
else | |
{ | |
$fileObj = json_decode($student->storage_object); | |
$url=true; | |
} | |
if(file_exists($filepath) || $url) | |
{ | |
$file = new \stdClass(); | |
$file->source = $filepath; | |
$file->url = $url; | |
if($url) | |
{ | |
$file->bucket = $fileObj->bucket; | |
$file->key=$fileObj->key; | |
} | |
$removeRollNo = CommonService::getInstance()->getSettings(SettingsConstants::REMOVE_ROLL_NO_ASSIGNMENT_DOWNLOAD_GENERATION_NAME,SettingsConstants::ASSIGNMENT_SETTINGS); | |
if($removeRollNo){ | |
$file->name = $url?$fileObj->name:substr($student->path,3); | |
} | |
else{ | |
$file->name = $url?$student->rollNo."-".$fileObj->name:$student->rollNo."-".substr($student->path,3); | |
} | |
$files[] = $file; | |
} | |
} | |
$credentials = new \stdClass(); | |
$credentials->accessKey=SecurityUtils::decryptAndVerify($request->accessKey, "S3-UPLOAD-LINWAYS"); | |
$credentials->secretKey=SecurityUtils::decryptAndVerify($request->secretKey, "S3-UPLOAD-LINWAYS"); | |
$isZipCreated=CommonUtil::createZipUsingZipStream($files, $zipPath, $zipname, false, $credentials); | |
if($isZipCreated) | |
{ | |
$uploadResourceRequest = new UploadResourceRequest(); | |
$uploadResourceRequest->fileName = $request->reportName. ".zip"; | |
$uploadResourceRequest->filePath = $zipPath."/".$zipname; | |
$uploadResourceRequest->context = ResourceContext::ASSIGNMENT_FILE_DOWNLOAD; | |
$uploadResourceRequest->backendType = BackendTypes::S3; | |
$uploadResourceRequest->s3FolderPath = $request->collegeCode. "/AssignmentFile" . "/"; | |
$uploadResourceRequest->bucket = SecurityUtils::decryptAndVerify($request->bucket, "S3-UPLOAD-LINWAYS"); | |
$uploadResourceRequest->accessKey = SecurityUtils::decryptAndVerify($request->accessKey, "S3-UPLOAD-LINWAYS"); | |
$uploadResourceRequest->secretKey = SecurityUtils::decryptAndVerify($request->secretKey, "S3-UPLOAD-LINWAYS"); | |
$uploadResourceRequest->createdBy = $request->createdBy; | |
$uploadResourceRequest->updatedBy = $request->updatedBy; | |
$resourceId = ResourceService::getInstance()->uploadResource($uploadResourceRequest); | |
$getAsyncReportRequest = new GetAsyncReportRequest(); | |
$getAsyncReportRequest->asyncReportId = $request->asyncReportId; | |
$asyncReport = AsyncReportService::getInstance()->getAsyncReport($getAsyncReportRequest)[0]; | |
unlink($zipPath."/".$zipname); | |
$asyncReport->linResourceId = $resourceId; | |
AsyncReportService::getInstance()->saveAsyncReport($asyncReport); | |
} | |
return true; | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
public function getAllStudentsAssignmentMarks($batchId,$semId,$subbatchId = NULL,$assiNum = NULL){ | |
$batchId = $this->realEscapeString($batchId); | |
$semId = $this->realEscapeString($semId); | |
$condition = ""; | |
$sql = "SELECT | |
s.rollNo, | |
s.studentID, | |
s.studentName, | |
s.regNo, | |
sub.subjectID, | |
sub.subjectName, | |
ba.assiNu, | |
am.marksObtained, | |
ba.max_mark, | |
concat(ba.subjectID,ba.assignmentID,ba.assiNu) as subjAssign | |
FROM | |
studentaccount s | |
INNER JOIN | |
assignment_marks am ON am.studentID = s.studentID | |
INNER JOIN | |
batch_assignment ba ON ba.assignmentID = am.assignmentID | |
INNER JOIN | |
subjects sub ON sub.subjectID = ba.subjectID | |
WHERE | |
ba.batchID = $batchId AND ba.semID = $semId | |
"; | |
if (!empty($subbatchId)) { | |
$subbatchId = $this->realEscapeString($subbatchId); | |
$sql.= " AND ( subbatchID = 0 OR subbatchID = ".$subbatchId.") ORDER BY assiNu ASC , rollNo ASC"; | |
} | |
if(!empty($assiNum)){ | |
$assiNum = $this->realEscapeString($assiNum); | |
$sql.= " AND ba.assiNu = ".$assiNum." ORDER BY assiNu ASC , rollNo ASC"; | |
} | |
else{ | |
$sql.= " ORDER BY assiNu ASC , rollNo ASC"; | |
} | |
try { | |
$studentsList = $this->executeQueryForList($sql,$this->mapper[AssignmentServiceMapper::GET_ASSIGNMENT_MARK_LIST_BY_STUDENT]); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode,$e->getMessage()); | |
} | |
return $studentsList; | |
} | |
} | |