Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 78 |
| DistrictService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
420.00 | |
0.00% |
0 / 78 |
| __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 |
|||
| getAllDistricts | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 12 |
|||
| getAllDistrictsOfAState | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 11 |
|||
| insertDistrict | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| updateDistrict | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| deleteDistrict | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getAllDistrictsOfAStateForDataImport | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 15 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use phpDocumentor\Reflection\Types\Integer; | |
| class DistrictService extends BaseService | |
| { | |
| 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; | |
| } | |
| /** | |
| * | |
| * | |
| * @author gadheyan | |
| * @throws ProfessionalException | |
| * @return | |
| */ | |
| public function getAllDistricts() | |
| { | |
| $query = "select d.id, d.state_id as stateId, d.districtName as name, s.state_name as stateName from districts d INNER JOIN state s ON d.state_id = s.id"; | |
| try { | |
| $responseList = $this->executeQueryForList($query); | |
| if (empty($responseList)) { | |
| throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY, "No Records Found!"); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $responseList; | |
| } | |
| /** | |
| * | |
| * @param unknown $stateId | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getAllDistrictsOfAState($stateId){ | |
| $query = "select d.id, d.state_id as stateId, d.districtName as name, s.state_name as stateName from districts d INNER JOIN state s ON d.state_id = s.id WHERE d.state_id = $stateId"; | |
| try { | |
| $responseList = $this->executeQueryForList($query); | |
| if (empty($responseList)) { | |
| throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY, "No Records Found!"); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $responseList; | |
| } | |
| /** | |
| * | |
| * @param unknown | |
| * @throws ProfessionalException | |
| * @return unknown | |
| */ | |
| public function insertDistrict($district) | |
| { | |
| $district = $this->realEscapeObject($district); | |
| $query = "insert into districts (state_id, districtName) values ('$district->stateId', '$district->name')"; | |
| try{ | |
| $response=$this->executeQueryForObject($query,true); | |
| }catch(\Exception $e) | |
| { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $response; | |
| } | |
| /** | |
| * | |
| * @param $nationality | |
| * @throws ProfessionalException | |
| * @return string | |
| */ | |
| public function updateDistrict($district) | |
| { | |
| $district=$this->realEscapeObject($district); | |
| $query = "update districts set districtName='$district->name', state_id='$district->stateId' where id='$district->id'"; | |
| try{ | |
| $this->executeQuery($query); | |
| }catch(\Exception $e) | |
| { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return "success"; | |
| } | |
| /** | |
| * | |
| * @param integer $id | |
| * @throws ProfessionalException | |
| * @return string | |
| */ | |
| public function deleteDistrict($id) | |
| { | |
| $id=$this->realEscapeString($id); | |
| $query = "delete from districts where id='$id'"; | |
| try{ | |
| $this->executeQuery($query); | |
| }catch(\Exception $e) | |
| { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return "success"; | |
| } | |
| /** | |
| * | |
| * @param integer $id | |
| * @throws ProfessionalException | |
| * @return Array | |
| */ | |
| public function getAllDistrictsOfAStateForDataImport($stateId){ | |
| $cond = ''; | |
| if($stateId){ | |
| $cond .=" AND d.state_id = $stateId "; | |
| } | |
| $query = "SELECT d.id, d.state_id as stateId, d.districtName as name, s.state_name as stateName from districts d INNER JOIN state s ON d.state_id = s.id WHERE 1=1 $cond"; | |
| try { | |
| $responseList = $this->executeQueryForList($query); | |
| if (empty($responseList)) { | |
| throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY, "No Records Found!"); | |
| } | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $responseList; | |
| } | |
| } | |