我的代码如下
控制器代码:
class statController extends baseController {
public function index() {
$this->registry->template->projectsWise = $this->selectProjectWise();
$this->registry->template->show("stat");
}
private static function selectStat($query, $values) {
$statMapper = new statMapper();
$select = new common();
$select->setItems($query);
$select->setValues($values);
return $statMapper->select($select);
}
private function selectProjectWise() {
$date = date("Y-m-d");
$values = array($date, $date);
return self::selectStat("project_wise", $values);
}
private function selectLocationWise(){
$date = date("Y-m-d");
$values = array($date, $date, 1);
return self::selectStat("location_wise", $values);
}
映射器代码:
class statMapper extends baseMapper {
private $query = array(
"project_wise" => "SELECT p.proj_Name, p.proj_Type, p.proj_Category, COUNT(ra.emp_Id) as allocation FROM project AS p, resource_assignment AS ra WHERE p.proj_Start_Date <= '%s' AND p.proj_End_Date >= '%s' AND p.proj_Status = 1 AND ra.proj_Id = p.proj_Id GROUP BY p.proj_Name ",
"location_wise" => "SELECT e.user_Location, p.proj_Name, p.proj_Type, p.proj_Category, COUNT(ra.emp_Id) as allocation FROM project AS p, resource_assignment AS ra, employee as e WHERE p.proj_Start_Date <= '%s' AND p.proj_End_Date >= '%s' AND p.proj_Status = %d AND ra.proj_Id = p.proj_Id GROUP BY p.proj_Name "
);
public function select($select) {
$connect = parent::connect();
$query = sprintf($this->query[$select->getItems()], $select->getValues()[0], $select->getValues()[1]);
try {
$result = $connect->query($query);
if ($result) {
$table = array();
while ($row = $result->fetch_object()) {
$table[] = $row;
}
return $table;
parent::disconnect();
} else {
throw (new Exception($connect->error . "<br/>" . $query . "<br/>"));
}
} catch (Exception $exp) {
require_once 'views/error.php';
exit();
}
}
}
我($query->"location_wise")
在statController->selectLocationWise()
函数中添加了 3 个说明符。当我使用它时,我如何添加$select->getValues()[2]
价值statMapper->select()
,而不是手动添加。