Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 63 |
StudentFoodOrderService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
210.00 | |
0.00% |
0 / 63 |
__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 |
|||
createFoodOrder | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
updateFoodOrder | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 14 |
|||
deleteFoodOrder | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
getStudentOrderCount | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getStudentFoodOrderId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\dto\StudentFoodOrders; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\dto\AssignMeal; | |
class StudentFoodOrderService 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; | |
} | |
/** | |
* To order food by the student | |
* @param StudentFoodOrders $foodOrder | |
* @throws ProfessionalException | |
*/ | |
public function createFoodOrder($foodOrder) | |
{ | |
$foodOrder->studentId = $this->realEscapeString($foodOrder->studentId); | |
$foodOrder->sessionCode = $this->realEscapeString($foodOrder->sessionCode); | |
$foodOrder->orderDate = $this->realEscapeString($foodOrder->orderDate); | |
$sql = "insert into student_food_orders (studentId,sessioncode,orderDate,createdBy,createdDate,updatedBy,updatedDate) values ('$foodOrder->studentId','$foodOrder->sessionCode','$foodOrder->orderDate','$foodOrder->studentId',utc_timestamp(),'$foodOrder->studentId',utc_timestamp())"; | |
try { | |
$result = $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* To update ordered food by the student | |
* @param StudentFoodOrders $meal | |
* @throws ProfessionalException | |
*/ | |
public function updateFoodOrder($foodOrder) | |
{ | |
$foodOrder->studentId = $this->realEscapeString($foodOrder->studentId); | |
$foodOrder->sessionCode = $this->realEscapeString($foodOrder->sessionCode); | |
$foodOrder->orderDate = $this->realEscapeString($foodOrder->orderDate); | |
$foodOrder->createdBy = $this->realEscapeString($foodOrder->createdBy); | |
$foodOrder->updatedBy = $this->realEscapeString($foodOrder->updatedBy); | |
$foodOrder->id = $this->realEscapeString($foodOrder->id); | |
$sql = "update student_food_orders set studentId= '$foodOrder->studentId', sessioncode = '$foodOrder->sessionCode', orderDate = '$foodOrder->orderDate', orderDate='$foodOrder->orderDate', updatedBy = '$foodOrder->updatedBy', updatedDate = utc_timestamp() where id=$foodOrder->id"; | |
try { | |
$result = $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* To delete a meal assigned to session | |
* @param int $id | |
* @throws ProfessionalException | |
*/ | |
public function deleteFoodOrder($id) | |
{ | |
$id = $this->realEscapeString($id); | |
$sql = "delete from student_food_orders where id='$id'"; | |
try { | |
$result = $this->executeQuery($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* To get the count of students ordered food | |
* @throws ProfessionalException | |
* @return AssignMeal object | |
*/ | |
public function getStudentOrderCount($orderDate) | |
{ | |
$sql= "select ms.id,code,count(studentId) as count from meal_session ms left join student_food_orders | |
sto on (ms.code = sto.sessioncode and orderDate='$orderDate') group by code order by ms.id"; | |
// $sql = "select count(studentId) as count from student_food_orders where orderDate='$orderDate' and sessioncode = '$sessionCode'"; | |
try { | |
$result = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $result; | |
} | |
public function getStudentFoodOrderId($foodOrder) | |
{ | |
$foodOrder->studentId = $this->realEscapeString($foodOrder->studentId); | |
$foodOrder->sessionCode = $this->realEscapeString($foodOrder->sessionCode); | |
$foodOrder->orderDate = $this->realEscapeString($foodOrder->orderDate); | |
$sql = " select id from student_food_orders where orderDate='$foodOrder->orderDate' and sessioncode = '$foodOrder->sessionCode' and studentId = '$foodOrder->studentId'"; | |
try { | |
$result = $this->executeQueryForObject($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $result; | |
} | |
} |