I’m new to Yii Framework.
I created radiobuttonlist out of two fields in search form-(Approval,ReviewedDate
).
<div class="row">
<?php #echo $form->label($model,'ReviewedDate'); ?>
<?php echo $form->radioButtonList($model, 'ReviewedDate',
array('1' => 'Reviewed', '' => 'Not Reviewed')
); ?>
</div>
<div class="row">
<?php echo $form->radioButtonList($model, 'Approved',
array('0' => 'Rejected', '1' => 'Approved')
); ?>
</div>
Now I have another two fields in the search form (Updateddate
,createddate
).
Such that I use the search form to filter the values of gridview accordingly.
Suppose, I
-
click on the
reviewed
radiobutton, all records where (updateddate>createddate) and (revieweddate=0000-00-00 00:00:00) should be displayed. -
click on the
not reviewed
radiobutton, all records where (updateddate=createddate) and (revieweddate=NULL) should be displayed. -
click on the
approved
radiobutton, all records where (updateddate>createddate) and (revieweddate!=0000-00-00 00:00:00) and (approved=1) should be displayed. -
click on the
rejected
radiobutton, all records where (updateddate>createddate) and (revieweddate!=0000-00-00 00:00:00) and (approved=0)should be displayed.
By default, revieweddate is NULL. When I update the form the value of revieweddate changes to 0000-00-00 00:00:00 and the value of updateddate changes to the currenttime.
Below is the model code:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with=array('apartment');
$criteria->compare('t.Id',$this->Id);
$criteria->compare('Approved',$this->Approved);
$criteria->compare('CreatedDate',$this->CreatedDate,true);
$criteria->compare('UpdatedDate',$this->UpdatedDate,true);
$criteria->compare('ReviewedDate',$this->ReviewedDate,true);
if($this->ReviewedDate != '')
{
$criteria->addCondition('ReviewedDate '.($this->ReviewedDate=="0000-00-00 00:00:00" ? 'IS NOT NULL' : 'IS NULL'));
}
else
{
$criteria->addCondition('ReviewedDate IS NULL');
}
if (isset($this->Approved) && !empty($this->Approved)) {
$criteria = new CDbCriteria;
$criteria->select = 't.*';
$criteria->addCondition("approved='" . $this->Approved . "'");
}
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
How can I filter the above conditions with the use of radiobuttons in search-form