Texto
|
PHP Class, example
|
|
After days working with classes, it may be helpfull having some examples here: Some parts of the code have been replaced,
<?php
final class SearhPeopleException extends Exception {}
class searchPeople
{
protected $search, $limit, $clinic_id, $date;
protected $productName=array(), $clinicProducts = array();
public function __construct($search = array(),$clinic_id=false, $date=false) {
if(empty($search))throw new SearhPeopleException("The parameter SEACH is required, arrived : $search.");
$date = ($date) ? $date : date('Y-m-d');
$this->search = $search;
$this->clinic_id = $clinic_id;
$this->date=$date;
}
/*
* Return Insureds
*/
public function getInsureds($limit = 50) {
$this->limit = $limit+1;
$insureds = array();
$query = $this->queryInsureds();
$c = 0; $more = false;
if(!empty($query)){
foreach($query as $r){
}
}
return $insureds;
}
/*
* Return insureds and build the search
*/
private function queryInsureds(){
$search = $this->search;
$cProducts = $this->clinicProducts;
$query = Doctrine::getTable('Insured')
->createQuery('i')
->select('i.id, p.name as product_name, p.id as product_id')
->leftJoin('i.InsuredProduct ip')
->leftJoin('ip.Product p');
if(!empty($this->clinic_id)){
$query->whereIn('p.id', $cProducts);
$query->andWhere('ip.date_end >= '.$this->date);
}else{
$query->where('ip.date_end >= '.$this->date);
}
$query->addWhere("$col LIKE ?", "%{$v[1]}%");
$query->addWhere("$col = ?", "$v[1]");
$result = $query->limit("$this->limit")->execute();
return $result;
}
private function personalNumber($n){
$number = trim($n);
if($number!='' && strlen($number)>=8){
if(strlen($number)==8){
$number = strtoupper($number);
$number .= substr("TRWAGMYFPDXBNJZSQVHLCKE",strtr($number,"XYZ","012")%23,1);
}else{
$number = strtoupper($number);
}
}
return $number;
}
}
?> |