Skip to content

Commit

Permalink
add GridViewTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
PutraSudaryanto committed Jul 6, 2018
1 parent 920ffc3 commit 3d7d39e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions GridViewTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* GridViewTrait
*
* @author Putra Sudaryanto <[email protected]>
* @contact (+62)856-299-4114
* @copyright Copyright (c) 2018 Ommu Platform (www.ommu.co)
* @created date 6 July 2018, 10:50 WIB
* @link https://github.com/ommu/yii-traits
*
* Contains many function that most used :
* keyIndex
* activeDefaultColumns
*
*/

trait GridViewTrait
{
/**
* Generates key index defaultColumns in models
* @return array
*/
public function keyIndex($data)
{
if(!is_array($data))
return $data;

else {
if(array_key_exists('name', $data))
return $data['name'];
}

return false;
}

/**
* Generates key index defaultColumns in models
* @return array
*/
public function activeDefaultColumns($columns)
{
$column = array();

foreach($columns as $val) {
$keyIndex = $this->keyIndex($val);
if($keyIndex)
$column[] = $keyIndex;
}

return $column;
}
}

0 comments on commit 3d7d39e

Please sign in to comment.