|
|
|
@ -97,6 +97,79 @@ class Controller extends BaseController
|
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// new version for custom select in selfTable |
|
|
|
|
protected function setUpPayloadSelect($condition, $tableSelf) |
|
|
|
|
{ |
|
|
|
|
$alias = "selfTable"; |
|
|
|
|
$builder = DB::table($tableSelf." AS ".$alias); |
|
|
|
|
// $builder = $builder->select($alias.".*"); |
|
|
|
|
if($condition){ |
|
|
|
|
if(isset($condition['select'])){ |
|
|
|
|
foreach($condition['select'] as $select){ |
|
|
|
|
$builder = $builder->select($alias.".".$select); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(isset($condition['joins'])){ |
|
|
|
|
$no = 0; |
|
|
|
|
foreach($condition['joins'] as $join){ |
|
|
|
|
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias; |
|
|
|
|
$tableName = $join['name']; |
|
|
|
|
$columnJoin = $join['column_join']; // foreign key table sini |
|
|
|
|
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan |
|
|
|
|
$columnResult = $join['column_results']; |
|
|
|
|
|
|
|
|
|
foreach($columnResult as $sColumn){ |
|
|
|
|
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); |
|
|
|
|
} |
|
|
|
|
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); |
|
|
|
|
$no++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(isset($condition['columns'])){ |
|
|
|
|
$listWhere = $condition['columns']; |
|
|
|
|
|
|
|
|
|
$builder = $builder->where(function ($query) use($listWhere, $alias){ |
|
|
|
|
foreach($listWhere as $where){ |
|
|
|
|
$value = $where['value']; |
|
|
|
|
if($value && $value!="" && $value!=" "){ |
|
|
|
|
$column = $where['name']; |
|
|
|
|
$operator = strtolower($where['logic_operator']); // like, =, <>, range |
|
|
|
|
$value2 = isset($where['value1']) ? $where['value1'] : ""; |
|
|
|
|
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; |
|
|
|
|
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(isset($condition['group_column'])){ |
|
|
|
|
$builder = $this->groupWhere($builder, $condition['group_column'], $alias); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['count'] = clone $builder; |
|
|
|
|
|
|
|
|
|
if(isset($condition['paging'])){ |
|
|
|
|
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(isset($condition['orders'])){ |
|
|
|
|
$orders = $condition['orders']; |
|
|
|
|
$sortBy = $orders['ascending'] ? "ASC" : "DESC"; |
|
|
|
|
$columnOrder = $orders['columns']; |
|
|
|
|
foreach($columnOrder as $column){ |
|
|
|
|
$builder = $builder->orderBy($alias.".".$column, $sortBy); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$builder = $builder->select($alias.".*"); |
|
|
|
|
} |
|
|
|
|
$data['builder'] = $builder; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function groupWhere($oldBuilder, $groupWhere, $alias) |
|
|
|
|
{ |
|
|
|
|
$builder = $oldBuilder; |
|
|
|
|