Make walk plants default to alpha

Issue #14 resolved
Ellen Cramer created an issue

No description provided.

Comments (4)

  1. Ellen Cramer reporter

    This was difficult due to related fields, 2 steps away.

    See MODEL: WalkLocation.php

        public $plantTitle;
    
    public function rules()
        {
            return array(
                array('walkLocationId, walkId, locationId, order, aLocation, plantTitle', 'safe', 'on'=>'search'),
    
        public function relations()
        {
            return array(
                'aLocation'=>array(self::BELONGS_TO, 'Location', 'locationId'),
            );
        }
    
        public function search()
        {
            $criteria=new CDbCriteria;
            $criteria->distinct = true;
            $criteria->together = true;
            $criteria->compare('walkLocationId',$this->walkLocationId);
            $criteria->compare('walkId',$this->walkId);
            $criteria->compare('locationId',$this->locationId);
            $criteria->compare('aLocation.aPlant.botanicalName',$this->plantTitle,true);
            $criteria->with = array(
                'aLocation', 
                'aLocation.aPlant'=> array('select'=>'*'),
            );
    
            $sort = new CSort();
            $sort->attributes = array(
                'defaultOrder'=>'aPlant',
                'aPlant'=>array(
                    'asc'=>'aPlant.botanicalName',
                    'desc'=>'aPlant.botanicalName desc',
                ),
            );
            $sort->applyOrder($criteria);
    
            return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
                'pagination'=>array('pageSize'=>30),
                'sort'=>$sort,
            ));
        }
    
        private $_plantTitle = null;
        public function getPlantTitle()
        {
            if ($this->_plantTitle === null && $this->aLocation.aPlant.botanicalName !== null)
            {
                $this->_plantTitle = $this->aLocation.aPlant.botanicalName;
            }
            //return $this->_plantTitle;
            return "test plantTitle";
        }
        public function setPostTitle($value)
        {
            $this->_plantTitle = $value;
    

    VIEW

        <?php
        // Gridview of plants related to walks through locations
        $walkLocation = new WalkLocation('search');
        // Filter the search by walkId
        $walkLocation->walkId = $model->walkId;
        // TbGridView
        $this->widget('bootstrap.widgets.TbGridView',array(
            'id'=>'location-plant-grid',
            'dataProvider'=>$walkLocation->search(),
            'filter'=>null,
            'columns'=>array(
                array(
                    'header'=>'',
                    'name'=>'aLocation.aPlant.primaryImage.fileName',
                    'type'=>'raw',       
                    'value'=>'(isset($data->aLocation->aPlant->primaryImage->fileName)) 
                        ? CHtml::image(Yii::app()->params["thumbDir"]
                        .$data->aLocation->aPlant->primaryImage->fileName)
                        : null',
                ),      
                array(
                    'header'=>'Botanical Name',
                    'name'=>'aPlant',
                    'type'=>'raw',
                    'htmlOptions' => array('class'=>'botanical'),
                    'value' => 'CHtml::link($data->aLocation->aPlant->botanicalName, Yii::app()->baseUrl."/plant/".$data->aLocation->plantId)',
                ),
                'aLocation.aPlant.commonName',
                array(
                    'header'=>'Summary',
                    'name'=>'plantId',
                    'type'=>'raw',  
                    'value'=>'$data->aLocation->aPlant->facetTags',
                ),          
            ),
        ));
        ?>
        }   
    
  2. Ellen Cramer reporter

    Added this to the links to the walks to sort by default.

    ?ajax=location-plant-grid&sort=aPlant
    
  3. Log in to comment