From View:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'project-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'rowCssClassExpression'=>'$data->color.$row%2',
'afterAjaxUpdate' => 'reinstallDatePicker',
'selectableRows'=>1,
'selectionChanged'=>'function(id){ location.href="index.php?r=project/view&id="+$.fn.yiiGridView.getSelection(id); }',
'columns'=>array(
array(
'type'=>'raw',
'header'=>'Name',
'name'=>'project_name',
'value'=>'CHtml::link($data->project_name, array("project/view", "id"=>$data->project_prikey))',
'htmlOptions'=>array('style'=>'font-weight:bold; text-decoration:none;'),
),
array(
'name'=>'ONESTATUS',
'htmlOptions'=>array('style'=>'font-weight:bold;'),
'value'=>'$data->ONESTATUS',
'filter'=>CHtml::listData(Note::getStatuses(), 'id', 'text'),
),
array(
'name'=>'project_targetdate',
'type'=>'raw',
'headerHtmlOptions'=>array('style'=>'width:85px;'),
'value'=>'Yii::app()->dateFormatter->format("EEE MMM d, y", $data->project_targetdate)."<BR> (".(((abs($v=(strtotime(date("Y-m-d",strtotime($data->project_targetdate)))-strtotime(date("Y-m-d")))/(3600*24)))>=7) ? round($v/7,1)." weeks" : $v." days").")"',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'project_targetdate',
'language' => 'en',
'i18nScriptFile' => 'jquery.ui.datepicker.js',
'htmlOptions' => array(
'id' => 'datepicker_for_project_targetdate',
'size' => '10',
),
'defaultOptions' => array(
'showOn' => 'focus',
'dateFormat' => 'yy-mm-dd',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
'constrainInput' => false,
)
),
true),
),
...
Search Function:
public function search($merge=null)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('projectForeignCreator','projectUsers');
$criteria->compare('projectForeignCreator.fullname', $this->projectcreator,true);
$criteria->select .= ',j22.note_text as ONENOTE, j22.note_status as ONESTATUS';
$criteria->join = 'LEFT JOIN (select j1.* FROM tracker_note AS j1 LEFT JOIN tracker_note AS j2 ON `j1`.`note_foreign_project`=`j2`.`note_foreign_project` AND `j1`.`note_prikey`<`j2`.`note_prikey` WHERE j2.note_foreign_project IS NULL) as j22 on j22.note_foreign_project=t.project_prikey';
//$criteria->with = array('projectUsers');
$criteria->together = true;
$criteria->compare('projectUsers.id', $this->projectassigned);
$criteria->compare('project_prikey',$this->project_prikey);
$criteria->compare('project_name',$this->project_name,true);
$criteria->compare('j22.note_prikey',$this->ONEKEY,true);
$criteria->compare('j22.note_text',$this->ONENOTE,true);
$criteria->compare('j22.note_status',$this->ONESTATUS,true);
$criteria->compare('project_targetdate',$this->project_targetdate,true);
$criteria->compare('project_description',$this->project_description,true);
$criteria->compare('project_targetdate',$this->project_targetdate,true);
$criteria->compare('project_foreign_creator',$this->project_foreign_creator);
$criteria->compare('project_created',$this->project_created,true);
$criteria->addCondition('project_deleted=0'); //only show non-deleted projects
//$criteria->addCondition('note_deleted=0'); //only show non-deleted notes
if($_GET['YAY']==1) print_r(Yii::app()->getRequest()->getParam('Project[project_name]', null));
if($merge!==null)
{
$criteria->mergeWith($merge);
}
//This 'if' never finds any filter condition, I've tried print_r($_REQUEST) and it's not there.
// if(strpos($criteria->condition,'targetdate')==-1)
// {
//$criteria->addCondition('(project_targetdate >= DATE_SUB(CURDATE(), INTERVAL 1 month) OR note_status<>"DONE")');
// }
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort' => array(
'attributes'=>array(
'ONESTATUS' => array(
'asc' => 'ONESTATUS',
'desc' => 'ONESTATUS DESC',
),
'ONENOTE' => array(
'asc' => 'ONENOTE',
'desc' => 'ONENOTE DESC',
),
'*',
),
'defaultOrder' => array('project_targetdate' => false),
),
'Pagination' => array (
'PageSize' => 100,
),
));
}
I see that the ‘merge’ code isn’t being used at all, leftovers…
And yes, it’s EVIL, and everything else works.
I have a notes table with multiple notes per project. In the main list I only show the last most recent note with the project summary list.
There are plenty of places I could clean this up, but I don’t believe they would affect my problem, but there’s a first for everything.