| Current Path : /var/www/html/planmalaysia/backend/models/ |
| Current File : /var/www/html/planmalaysia/backend/models/ContentCalendarSearch.php |
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\ContentCalendar;
/**
* ContentCalendarSearch represents the model behind the search form of `backend\models\ContentCalendar`.
*/
class ContentCalendarSearch extends ContentCalendar
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['content_calendar_id', 'active_fg', 'featured','content_calendar_pax'], 'integer'],
[['content_calendar_date', 'content_calendar_description', 'content_calendar_category','created_at', 'created_by', 'updated_at', 'updated_by', 'content_calendar_location', 'content_calendar_time','content_calendar_date','content_calendar_time_end'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ContentCalendar::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
if(!empty($params['ContentCalendarSearch']['nextmonthstart']) && !empty($params['ContentCalendarSearch']['nextmonthend'])){
$datestart = str_replace('/','-',$params['ContentCalendarSearch']['nextmonthstart']);
$dateend = str_replace('/','-',$params['ContentCalendarSearch']['nextmonthend']);
$query->andFilterWhere([
'between', 'content_calendar_date' , date('Y-m-d',strtotime($datestart)), date('Y-m-d',strtotime($dateend))
]);
}
$query->andFilterWhere(['like', 'content_calendar_description', $this->content_calendar_description])
->andFilterWhere(['like', 'content_calendar_location', $this->content_calendar_location])
->andFilterWhere(['like', 'content_calendar_time', $this->content_calendar_time])
->andFilterWhere(['like', 'created_by', $this->created_by])
->andFilterWhere(['like', 'updated_by', $this->updated_by])
->orderBy(['content_calendar_id' => SORT_DESC])
;
return $dataProvider;
}
}