Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 107 |
| ProgressReportService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
812.00 | |
0.00% |
0 / 107 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| createGeneralInstruction | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 13 |
|||
| updateGeneralInstruction | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
| deleteGeneralInstruction | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| getGeneralInstruction | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getProgressReport | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| createOrUpdateProgressReport | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| createProgressReport | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 14 |
|||
| updateProgressReport | |
0.00% |
0 / 1 |
90.00 | |
0.00% |
0 / 21 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\base\util\SecurityUtils; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| class ProgressReportService extends BaseService | |
| { | |
| // /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; | |
| } | |
| /** | |
| * create general instruction | |
| * @param unknown $inst | |
| * @throws ProfessionalException | |
| */ | |
| public function createGeneralInstruction($inst) | |
| { | |
| $semId = $this->realEscapeString($inst->semId); | |
| $batchId = $this->realEscapeString($inst->batchId); | |
| $staffId = $this->realEscapeString($inst->staffId); | |
| $inst->instruction = SecurityUtils::prepareSafeHTML($inst->instruction); | |
| $instruction = $this->realEscapeString($inst->instruction, false); | |
| try { | |
| $sql = "INSERT INTO progress_report_instruction (instruction,batchID,semID,createdBy,updatedBy,createdDate,updatedDate) VALUES ('".$instruction."',$batchId,$semId,$staffId,$staffId,utc_timestamp(),utc_timestamp())"; | |
| $result = $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * | |
| * @param unknown $inst | |
| * @throws ProfessionalException | |
| */ | |
| public function updateGeneralInstruction($inst) | |
| { | |
| $id = $this->realEscapeString($inst->id); | |
| $staffId = $this->realEscapeString($inst->staffId); | |
| $inst->instruction = SecurityUtils::prepareSafeHTML($inst->instruction); | |
| $instruction = $this->realEscapeString($inst->instruction, false); | |
| try { | |
| $sql = "UPDATE progress_report_instruction SET instruction = '$instruction', updatedBy = '$staffId', updatedDate = utc_timestamp() WHERE id=$id"; | |
| $result = $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function deleteGeneralInstruction($id) | |
| { | |
| $id = $this->realEscapeString($id); | |
| try { | |
| $sql = "DELETE FROM progress_report_instruction WHERE id=$id"; | |
| $result = $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * | |
| * @param unknown $batchId | |
| * @param unknown $semId | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\connection\Object | |
| */ | |
| public function getGeneralInstruction($batchId,$semId) | |
| { | |
| $semId = $this->realEscapeString($semId); | |
| $batchId = $this->realEscapeString($batchId); | |
| try { | |
| $sql = "SELECT id, instruction FROM progress_report_instruction WHERE semID=$semId AND batchID=$batchId"; | |
| $instDetails = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $instDetails; | |
| } | |
| /** | |
| * | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\connection\Object | |
| */ | |
| public function getProgressReport($request) | |
| { | |
| $request = $this->realEscapeObject($request); | |
| try { | |
| $sql = "SELECT id, batch_id, sem_id, approved, identifying_context, properties, created_by, updated_by, created_date, updated_date FROM progress_report_settings WHERE sem_id='".$request->semId."' AND batch_id='".$request->batchId."';"; | |
| $report = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $report; | |
| } | |
| /** | |
| * | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\connection\Object | |
| */ | |
| public function createOrUpdateProgressReport($request) | |
| { | |
| $request = $this->realEscapeObject($request); | |
| $data = $this->getProgressReport($request); | |
| if(!empty($data)){ | |
| $report = $this->updateProgressReport($request); | |
| }else{ | |
| $report = $this->createProgressReport($request); | |
| } | |
| return $report; | |
| } | |
| /** | |
| * | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\connection\Object | |
| */ | |
| public function createProgressReport($request) | |
| { | |
| $request = $this->realEscapeObject($request); | |
| foreach ($request->properties as $key => $property) { | |
| $property->data = array_merge((array)$property->data,array()); | |
| } | |
| try { | |
| $sql = "INSERT INTO `progress_report_settings` (`batch_id`, `sem_id`, `identifying_context`, `properties`, `created_by`, `updated_by`, `created_date`, `updated_date`) VALUES ('$request->batchId', '$request->semId', '$request->identifyingContext', '".json_encode($request->properties)."', '$request->createdBy', utc_timestamp(), '$request->updatedBy', utc_timestamp());"; | |
| $this->executeQuery($sql); | |
| $report = $this->getProgressReport($request); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $report; | |
| } | |
| /** | |
| * | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\connection\Object | |
| */ | |
| public function updateProgressReport($request) | |
| { | |
| $request = $this->realEscapeObject($request); | |
| foreach ($request->properties as $key => $property) { | |
| $property->data = array_merge((array)$property->data,array()); | |
| } | |
| $request->identifyingContext ? $updation [] = "identifying_context = '$request->identifyingContext'":null; | |
| $request->properties ? $updation [] = "properties = '".json_encode($request->properties)."'":null; | |
| $request->updatedBy ? $updation [] = "updated_by = '$request->updatedBy'":null; | |
| $request->approved ? $updation [] = "approved = '".($request->approved == 'true'?1:0)."'":null; | |
| $updation [] = "updated_date = UTC_TIMESTAMP()"; | |
| try { | |
| $sql = "UPDATE progress_report_settings | |
| ".($updation?" SET ".implode(' , ',$updation):"")." | |
| WHERE batch_id = '$request->batchId' AND sem_id = '$request->semId';"; | |
| $this->executeQuery($sql); | |
| $report = $this->getProgressReport($request); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $report; | |
| } | |
| } |