Your IP : 216.73.216.91


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

<?php
class Spear extends BaseController implements IValidateParams{
	public function createOne($data){
		unset($data['id']);
		$this->response = $this->insert(Config::getTable('spear'), $data, false);
		return $this->response;
	}
	public function getOneById($data){
		$this->response = $this->select(Config::getTable('spear'), ["*"], "WHERE id = ?", [$data['id']]);
		return $this->response;
	}
	public function getOneBySemisCode($data){
		$this->response = $this->select(Config::getTable('spear'), ["*, id as spear_id"], "WHERE semis_code = ?", [$data['semis_code']]);
		return $this->response;
	}
	public function updateOne($data){
		$id = $data['id'];
		unset($data['id']);
		$this->response = $this->update(Config::getTable('spear'), $data, "WHERE id = ?", [$id]);
		return $this->response;
	}
	public function getAll($data){
		$table = Config::getTable('spear');		
		$DTTotalCount = $this->customSelect("select count(*) as count from {$table}")['result'][0]->count;
		if(!empty($data['search']['value'])){
			$fullTextDT = $this->fullTextSearchDTQuery($data, $table);
			$this->response = $this->customSelect($fullTextDT['paging']);
			$DTFilteredCount = $this->customSelect($fullTextDT['where'])['rowsAffected'];
			$DTResponse = [ 
				'draw' => intval($data['draw']),
				'recordsTotal' => $DTTotalCount ?? 0,
				'recordsFiltered' => $DTFilteredCount ?? 0,
				'data' => $this->response['result'] ?? [],
			];
		}else{
			$DTDataQry = "Select *, id as DT_RowId from {$table} {$this->transformDTQuery($data)['paging']}";
			$DTFilteredCount = $this->customSelect("select count(*) as count from {$table} {$this->transformDTQuery($data)['where']}")['result'][0]->count;
			$this->response = $this->customSelect($DTDataQry);
			$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' => [
				"semis_code",
				"school_name",
				// "address",
				// "hm_name",
				// "hm_contact_num",
				// "hm_whatsapp_num",
				// "emerg_num",
				// "teacher_count",
				// "non_teacher_count",
				// "medium",
				// "stu_count",
				// "class1",
				// "class2",
				// "class3",
				// "class4",
				// "class5",
			],
			'updateOne' => [
				"semis_code",
				"school_name",
				// "address",
				// "hm_name",
				// "hm_contact_num",
				// "hm_whatsapp_num",
				// "emerg_num",
				// "teacher_count",
				// "non_teacher_count",
				// "medium",
				// "stu_count",
				// "class1",
				// "class2",
				// "class3",
				// "class4",
				// "class5",
			],
			'getOneById' => ['id'],
			'getOneBySemisCode' => ['semis_code'],
			'getAll' => [],
		];
		return $this->mendetoryParamsAgainstEachMethod;
	}
}
?>