Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 161 |
| FileService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 18 |
1332.00 | |
0.00% |
0 / 161 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| __clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| getFileCategories | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| createFileCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| updateFileCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| getFileCategoryById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| createFileCategoryRoles | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
| getFileCategoryRolesByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| deleteFileCategoryRoles | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| deleteFileCategory | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| getfileLocationDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| createFileLocationDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| updateFileLocationDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| deleteFileLocationDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| getFileLocationDetailsById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| getFileCategoryByRole | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
| getfileLocationDetailsByCategoryId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\dto\FileCategory; | |
| use com\linways\core\ams\professional\dto\FileLocationDetails; | |
| class FileService 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; | |
| } | |
| /** | |
| * Get all file categories | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getFileCategories() | |
| { | |
| $sql = "select id, code, name, description from category"; | |
| try { | |
| $categoryDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $categoryDetails; | |
| } | |
| /** | |
| * create file category | |
| * @param FileCategory $fileCategory | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function createFileCategory($fileCategory) | |
| { | |
| $fileCategory = $this->realEscapeObject($fileCategory); | |
| $sql = "insert into category (code, name, description, createdBy, createdDate, updatedBy, updatedDate) values (\"$fileCategory->code\",\"$fileCategory->name\",\"$fileCategory->description\", $fileCategory->createdBy,utc_timestamp(), $fileCategory->createdBy, utc_timestamp())"; | |
| try { | |
| return $this->executeQueryForObject($sql,true); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * update file category | |
| * @param FileCategory $fileCategory | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function updateFileCategory($fileCategory) | |
| { | |
| $fileCategory = $this->realEscapeObject($fileCategory); | |
| $sql = "update category set code = \"$fileCategory->code\", name = \"$fileCategory->name\", description = \"$fileCategory->description\", updatedBy = $fileCategory->updatedBy, updatedDate = utc_timestamp() where id = $fileCategory->id"; | |
| try { | |
| return $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * get file category by id | |
| * @param int $id | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getFileCategoryById($id) | |
| { | |
| $id = $this->realEscapeString($id); | |
| $sql = "select code, cat.name, description, role from category cat left join category_role cr on cat.id = cr.categoryId where cat.id = $id"; | |
| try { | |
| $categoryDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $categoryDetails; | |
| } | |
| /** | |
| * create file catgory roles | |
| * @param int $categoryId | |
| * @param string $roles | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function createFileCategoryRoles($categoryId,$roles) | |
| { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $roles = $this->realEscapeArray($roles); | |
| $sql = "insert into category_role (categoryId, role) values "; | |
| foreach ($roles as $role) | |
| { | |
| $sql.= "($categoryId,\"$role\"), "; | |
| } | |
| $sql = rtrim($sql,", "); | |
| try { | |
| return $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Get file category roles by categoryId | |
| * @param int $categoryId | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getFileCategoryRolesByCategoryId($categoryId) | |
| { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $sql = "select role from category_role where categoryId = $categoryId"; | |
| try { | |
| $roles = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $roles; | |
| } | |
| /** | |
| * Delete file category roles | |
| * @param int $categoryId | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\dto\MySqlResult | |
| */ | |
| public function deleteFileCategoryRoles($categoryId) | |
| { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $sql = "delete from category_role where categoryId = $categoryId"; | |
| try { | |
| return $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete file category | |
| * @param int $categoryId | |
| * @throws ProfessionalException | |
| */ | |
| public function deleteFileCategory($categoryId) | |
| { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $sql = "delete from category where id = $categoryId"; | |
| try { | |
| $this->executeQuery($sql); | |
| $this->deleteFileCategoryRoles($categoryId); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return true; | |
| } | |
| /** | |
| * Get file location details | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getfileLocationDetails() | |
| { | |
| $sql = "select fl.id as fileId, categoryId, fl.name as fileName, link, code, cat.name, description from file_location_details fl left join category cat on fl.categoryId = cat.id"; | |
| try { | |
| $fileLocationDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $fileLocationDetails; | |
| } | |
| /** | |
| * Create file location details | |
| * @param FileLocationDetails $fileStorage | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function createFileLocationDetails($fileStorage) | |
| { | |
| $fileStorage = $this->realEscapeObject($fileStorage); | |
| $sql = "insert into file_location_details (categoryId, name, link, createdBy, createdDate, updatedBy, updatedDate) values ($fileStorage->categoryId, \"$fileStorage->name\", \"$fileStorage->link\", $fileStorage->createdBy, UTC_TIMESTAMP(), $fileStorage->updatedBy, UTC_TIMESTAMP())"; | |
| try { | |
| return $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * update file location details | |
| * @param FileLocationDetails $fileStorage | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function updateFileLocationDetails($fileStorage) | |
| { | |
| $fileStorage = $this->realEscapeObject($fileStorage); | |
| $sql = "update file_location_details set categoryId = $fileStorage->categoryId, name = \"$fileStorage->name\", link = \"$fileStorage->link\", updatedBy = $fileStorage->updatedBy, updatedDate = UTC_TIMESTAMP() where id = $fileStorage->id"; | |
| try { | |
| return $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Delete file location details | |
| * @param string $id | |
| * @throws ProfessionalException | |
| * @return \com\linways\base\dto\MySqlResult | |
| */ | |
| public function deleteFileLocationDetails($id) | |
| { | |
| $id = $this->realEscapeString($id); | |
| $sql = "delete from file_location_details where id = $id"; | |
| try { | |
| return $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * get file location details by Id | |
| * @param string $id | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getFileLocationDetailsById($id) | |
| { | |
| $id = $this->realEscapeString($id); | |
| $sql = "select categoryId, name, link from file_location_details where id = $id"; | |
| try { | |
| $fileDetails = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $fileDetails; | |
| } | |
| /** | |
| * get file category details by role | |
| * @param string $role | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getFileCategoryByRole($role) | |
| { | |
| $roles = $this->realEscapeArray($role); | |
| foreach ($roles as $role ) | |
| { | |
| $sql_role.="'".$role."', " ; | |
| } | |
| $sql_role = rtrim($sql_role,", "); | |
| $sql = "select distinct cat.id, code, name from category cat left join category_role cr on cat.id = cr.categoryId where role in ($sql_role)"; | |
| try { | |
| $categoryDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $categoryDetails; | |
| } | |
| /** | |
| * Get file location details by categoryId | |
| * @throws ProfessionalException | |
| * @return object|array|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getfileLocationDetailsByCategoryId($categoryId) | |
| { | |
| $categoryId = $this->realEscapeString($categoryId); | |
| $sql = "select fl.id as fileId, categoryId, fl.name as fileName, link, code, cat.name, description from file_location_details fl left join category cat on fl.categoryId = cat.id where categoryId = $categoryId"; | |
| try { | |
| $fileLocationDetails = $this->executeQueryForList($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $fileLocationDetails; | |
| } | |
| } | |