Find us on facebook

Showing posts with label GridView Yii. Show all posts
Showing posts with label GridView Yii. Show all posts

Sep 20, 2014

Many-Many in Grid view

grid view
'dataProvider' => $dataProvider
array(          
'name'=>'diningype',
'value'=> '$data->typeLabel'
),

Model
public function relations()
{
return array(
'diningtypes' => array (
self::MANY_MANY,
'DiningTypes',
'menu_diningtypes(menu_id, diningtypes_type_id)'
),
);
}

public function getTypeLabel()
{
$label = '';
foreach($this->diningtypes as $diningtype) {
$label .= "$diningtype->name, ";
}
return $label;
}

Controller
$dataProvider = $model ->with('diningtypes')->search();

Aug 21, 2014

Many to Many relationship shown in the grid

In Controller
protected function gridCategoryDescription($data,$row)
    {
       return $this->_lastProductId != $data->id ? $data->discription : '';          
    }

protected function gridCategoryPrice($data,$row)
    {
        if($this->_lastProductId != $data->id)
        {
            $this->_lastProductId = $data->id;
            return $data->code;
        }
        else
             return '';
    }

In view
array(            
'name'=>'discription',
'value'=>array($this,'gridCategoryDescription')
),

array(            
'name'=>'code',
'value'=>array($this,'gridCategoryPrice')
),

Aug 2, 2014

Make Buttons Visible or Not visible according to permissions Given

<?php
$user_id=Yii::app()->user->id;
$AuthAssignments = AuthAssignment::model() -> findAll(array("condition"=>"userid = $user_id","order"=>"itemname"));

$Authitemchildren = Authitemchild::model() -> findAll();
$visibleView = 'false;';
$visibleEdit = 'false;';
$visibleDelete = 'false;';
foreach($Authitemchildren as $Authitemchild){
foreach($AuthAssignments as $AuthAssignment){
if($Authitemchild['parent']==$AuthAssignment['itemname'] && $Authitemchild['child']=='MainMenu.View'){
$visibleView = 'true;';
}else if($Authitemchild['parent']==$AuthAssignment['itemname'] && $Authitemchild['child']=='MainMenu.Update'){
$visibleEdit = 'true;';
}
else if($Authitemchild['parent']==$AuthAssignment['itemname'] && $Authitemchild['child']=='MainMenu.Delete'){
$visibleDelete = 'true;';
}
}
}


In buttons

array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{View}{Edit}{Delete}',
'buttons'=>array
(
 
'View' => array
(
'label'=>'View',
'visible' => $visibleView,
'url'=>'Yii::app()->createUrl("MainMenu/view", array("id"=>$data->id))',
'imageUrl' => Yii::app()->baseUrl . '/images/icon/viewicon.jpg',
'options'=>array(
'style'=>'width:130px;height:130px;',
//   'class'=>'btn btn-small btn-info',
),
),
),),

Button visibility in Grid view

array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{view}{edit}{delete}',
'buttons'=>array
(


'view' => array
(
'label'=>'View',
'visible' => '(isset($data->id))?false:true;',
'url'=>'Yii::app()->createUrl("MainMenu/view", array("id"=>$data->id))',
'imageUrl' => Yii::app()->baseUrl . '/images/icon/viewicon.jpg',
'options'=>array(
'style'=>'width:130px;height:130px;',
//   'class'=>'btn btn-small btn-info',
),
),

Jun 25, 2014

Add a field that is not a table field into grid in YII

public $date;
public $time;
public $datetime;
public $order_type;

public function attributeLabels()
{
return array(
'datetime' =>'Delivery/Collection Date & Time',
'order_type' =>'Order Type',
etc...
); }

protected function afterFind() {
parent::afterFind();
//$delivery_date_new = strstr($this->delivery_date, '+', true);

if(strpos($this->delivery_date,'+') !== false){
$pieces = explode(" ", $this->delivery_date);
$timenew=explode(":", $pieces[1]);
$this->time=$timenew[0].":".$timenew[1];
$this->date = $pieces[0];
$this->datetime=$this->date." ".$this->time;
}else{
$this->time = $this->dilivery_time;
$this->date = $this->delivery_date;
$this->datetime=$this->delivery_date." ".$this->dilivery_time;
}
if ($this->delivery_type == 0)
{
$this->order_type = "Takeaway";
} elseif ($this->delivery_type == 1) {
$this->order_type = "Delivery";
} else {
$this->order_type = "Table";
}



return $this;
}