Your IP : 216.73.216.91


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

<?php
class Donor extends BaseController implements IValidateParams{
	public function createOne($data){
		unset($data['id']);
		$this->response = $this->insert(Config::getTable('donor'), $data, false);
		return $this->response;
	}
	public function updateOne($data){
		$id = $data['id'];
		unset($data['id']);
		$this->response = $this->update(Config::getTable('donor'), $data, "WHERE id = ?", [$id]);
		return $this->response;
	}
	public function getOneById($data){
		$this->response = $this->select(Config::getTable('donor'), ["*"], "WHERE id = ?", [$data['id']]);
		return $this->response;
	}
	public function getAll($data){
		$table = Config::getTable('donor');		
		$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 getAllDonors(){
		$this->response = $this->select(Config::getTable('donor'), ["id", "donor_name"]);
		return $this->response;
	}
	public function validateRequestsParams(){
		$this->mendetoryParamsAgainstEachMethod = [
			'createOne' => [
				"donor_name", 
				"donor_whatsapp",
				"donor_ref_name",
			],
			'updateOne' => [
				"donor_name", 
				"donor_whatsapp",
				"donor_ref_name",
			],
			'getOneById' => ["id"],
			'getAll' => [],
			'getAllDonors' => []
		];
		return $this->mendetoryParamsAgainstEachMethod;
	}
}
?>