public static function getNames(){ $arr=CaseChild::model()->findAll(); $names=array(0=>"None"); foreach($arr as $case){ $names[$case->id]=$case->name; } return $names; }
public function actionSearch(){ $term=$_GET['term']; $contacts=ContactChild::model()->findAllBySql('SELECT * FROM x2_contacts WHERE CONCAT(firstName," ",lastName) LIKE "%'.$term.'%" OR backgroundInfo LIKE "%'.$term.'%" OR email LIKE "%'.$term.'%" OR firstName LIKE "%'.$term.'%" OR lastName LIKE "%'.$term.'%" OR phone LIKE "%'.$term.'%" OR address LIKE "%'.$term.'%"'); $actions=ActionChild::model()->findAllBySql('SELECT * FROM x2_actions WHERE actionDescription LIKE "%'.$term.'%" LIMIT 10000'); $sales=SaleChild::model()->findAllBySql('SELECT * FROM x2_sales WHERE name LIKE "%'.$term.'%" OR description LIKE "%'.$term.'%"'); $accounts=AccountChild::model()->findAllBySql('SELECT * FROM x2_accounts WHERE name LIKE "%'.$term.'%" OR description LIKE "%'.$term.'%" OR tickerSymbol LIKE "%'.$term.'%"'); $projects=ProjectChild::model()->findAll(); $cases=CaseChild::model()->findAll(); $marketing=MarketingChild::model()->findAll(); $names=array(); $descriptions=array(); $notes=array(); $records=array(); $regEx="/$term/i"; foreach($contacts as $contact){ if(preg_match($regEx,$contact->firstName." ".$contact->lastName)>0){ $names[]=$contact; }elseif(preg_match($regEx,$contact->firstName)>0 || preg_match($regEx,$contact->lastName)>0){ $notes[]=$contact; }elseif(preg_match($regEx,$contact->backgroundInfo)>0){ $descriptions[]=$contact; }elseif(preg_match($regEx,$contact->email)>0){ $names[]=$contact; }elseif(preg_match($regEx,$contact->phone)>0){ $names[]=$contact; }elseif(preg_match($regEx,$contact->address)>0){ $names[]=$contact; } } foreach($actions as $action){ if(preg_match($regEx,$action->actionDescription)>0){ $names[]=$action; } } foreach($sales as $sale){ if(preg_match($regEx,$sale->name)>0){ $names[]=$sale; }elseif(preg_match($regEx,$sale->description)>0){ $descriptions[]=$sale; } } foreach($accounts as $account){ if(preg_match($regEx,$account->name)>0){ $names[]=$account; }elseif(preg_match($regEx,$account->tickerSymbol)>0){ $names[]=$account; }elseif(preg_match($regEx,$account->description)>0){ $descriptions[]=$account; }elseif(preg_match($regEx,$account->website)>0){ $names[]=$account; } } foreach($projects as $project){ if(preg_match($regEx,$project->name)>0){ $names[]=$project; }elseif(preg_match($regEx,$project->description)>0){ $descriptions[]=$project; } } foreach($cases as $case){ if(preg_match($regEx,$case->name)>0){ $names[]=$case; }elseif(preg_match($regEx,$case->description)>0){ $descriptions[]=$case; } } foreach($marketing as $item){ if(preg_match($regEx,$item->name)>0){ $names[]=$item; }elseif(preg_match($regEx,$item->description)>0){ $descriptions[]=$item; } } $records=array_merge($names,$descriptions); $records=array_merge($records,$notes); asort($records); $records=Record::convert($records); $dataProvider=new CArrayDataProvider($records,array( 'id'=>'id', 'pagination'=>array( 'pageSize'=>10, ), )); $this->render('search',array( 'records'=>$records, 'dataProvider'=>$dataProvider, 'term'=>$term, )); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = CaseChild::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }