Your IP : 216.73.216.91


Current Path : /var/www/html/llcfapp/api/controller/
Upload File :
Current File : /var/www/html/llcfapp/api/controller/SpStudent.php

<?php
class SpStudent extends BaseController implements IValidateParams{
	public function createOne($data){
		$data = $this->unsetArrayKeys($data, ['id', 'semis_code', 'school_name', 'hm_name', 'medium', 'teacher_count']);
		$data = $this->cleanArray($data);
		$this->response = $this->insert(Config::getTable('spear_student'), $data, false);
		return $this->response;
	}
	public function getOneById($data){
		$this->response = $this->select(Config::getTable('spear_student'), ["*"], "WHERE id = ?", [$data['id']]);
		return $this->response;
	}
	public function updateOne($data){
		$id = $data['id'];
		$data = $this->unsetArrayKeys($data, ['id', 'spear_id', 'semis_code', 'school_name', 'hm_name', 'medium', 'teacher_count']);
		$data = $this->cleanArray($data);
		$this->response = $this->update(Config::getTable('spear_student'), $data, "WHERE id = ?", [$id]);
		return $this->response;
	}
	public function getAll($data){
		$table = Config::getTable('spear_student');		
		$table_spear = Config::getTable('spear');		
		$DTTotalCountQry = <<<QRY
				SELECT 
					count(*) as count
						FROM {$table}
					left join {$table_spear}
						on {$table_spear}.id = {$table}.spear_id
			QRY;
		$DTTotalCount = $this->customSelect($DTTotalCountQry)['result'][0]->count;
		// $DTTotalCount = $this->customSelect("select count(*) as count from {$table}")['result'][0]->count;
		if(!empty($data['search']['value'])){
			$calCols = [
				"spstudent||stu_age" => "CONCAT(FLOOR((TIMESTAMPDIFF(MONTH, dob, CURDATE()) / 12)), 'Y ', MOD(TIMESTAMPDIFF(MONTH, dob, CURDATE()), 12) , 'M') AS 'spstudent||stu_age'," ,
			];
			$gs = $this->globalSearch($data, $table, $calCols);
			$this->response = $this->customSelect($gs['paging']);
			$this->response = $this->prefixColumnWithTableAndMapReqParamInResponse($data['columns'], $this->response);
			$DTFilteredCount = $this->customSelect($gs['where'])['rowsAffected'];
			$DTResponse = [ 
				'draw' => intval($data['draw']),
				'recordsTotal' => $DTTotalCount ?? 0,
				'recordsFiltered' => $DTFilteredCount ?? 0,
				'data' => $this->response['result'] ?? [],
			];
		}else{
			$DTDataQry = <<<QRY
				SELECT 
					{$table}.id as '{$table}||id', 
					{$table}.spear_id as '{$table}||spear_id', 
					{$table_spear}.semis_code as '{$table_spear}||semis_code',
					{$table_spear}.school_name as '{$table_spear}||school_name',
					{$table}.gr_num as '{$table}||gr_num', 
					{$table}.student_name as '{$table}||student_name', 
					{$table}.dob as '{$table}||dob', 
					CONCAT(FLOOR((TIMESTAMPDIFF(MONTH, dob, CURDATE()) / 12)), 'Y ', MOD(TIMESTAMPDIFF(MONTH, dob, CURDATE()), 12) , 'M') AS '{$table}||stu_age', 
					{$table}.b_form_num as '{$table}||b_form_num', 
					{$table}.father_name as '{$table}||father_name', 
					{$table}.father_cnic as '{$table}||father_cnic', 
					{$table}.father_mobile as '{$table}||father_mobile', 
					{$table}.mother_name as '{$table}||mother_name', 
					{$table}.class as '{$table}||class', 
					{$table}.religion as '{$table}||religion'
						FROM {$table}
					left join {$table_spear}
						on {$table_spear}.id = {$table}.spear_id
					{$this->transformDTQuery($data)['paging']}
			QRY;
			// $DTDataQry = "Select *, id as DT_RowId from {$table} {$this->transformDTQuery($data)['paging']}";
			$this->response = $this->customSelect(trim($DTDataQry));

			$DTFilteredCountQry = <<<QRY
				SELECT 
					count(*) as count
						FROM {$table}
					left join {$table_spear}
						on {$table_spear}.id = {$table}.spear_id
					{$this->transformDTQuery($data)['where']}
			QRY;
			$DTFilteredCount = $this->customSelect(trim($DTFilteredCountQry))['result'][0]->count;
			// $DTFilteredCount = $this->customSelect("select count(*) as count from {$table} {$this->transformDTQuery($data)['where']}")['result'][0]->count;
			$DTResponse = [ 
				'draw' => intval($data['draw']),
				'recordsTotal' => $DTTotalCount ?? 0,
				'recordsFiltered' => $DTFilteredCount ?? 0,
				'data' => $this->response['result'] ?? [],
			];
		}
		if($this->response['status'] == 'failure'){
			$DTResponse['error'] = $this->response['msg'];
		}
		return $DTResponse;
	}
	public function validateRequestsParams(){
		$this->mendetoryParamsAgainstEachMethod = [
			'createOne' => [
				"spear_id",
				"gr_num",
				"student_name",
				// "b_form_num",
				// "dob",
				"father_name",
				// "father_cnic",
				// "father_mobile",
				// "mother_name",
				// "class",
				// "religion"
			],
			'updateOne' => [
				"id",
				"gr_num",
				"student_name",
				// "b_form_num",
				// "dob",
				"father_name",
				// "father_cnic",
				// "father_mobile",
				// "mother_name",
				// "class",
				// "religion"
			],
			'getOneById' => ['id'],
			'getAll' => [],
		];
		return $this->mendetoryParamsAgainstEachMethod;
	}
}
?>