|
|
|
@ -34,71 +34,6 @@ class Controller extends BaseController
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected function setUpPayload($condition, $tableSelf) |
|
|
|
|
{ |
|
|
|
|
$alias = "selfTable"; |
|
|
|
|
$builder = DB::table($tableSelf." AS ".$alias); |
|
|
|
|
$builder = $builder->select($alias.".*"); |
|
|
|
|
if($condition){ |
|
|
|
|
if(isset($condition['joins'])){ |
|
|
|
|
$selectColumn = []; |
|
|
|
|
$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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$data['builder'] = $builder; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// new version for custom select in selfTable |
|
|
|
|
protected function setUpPayloadSelect($condition, $tableSelf) |
|
|
|
|
{ |
|
|
|
|
$alias = "selfTable"; |
|
|
|
|
$builder = DB::table($tableSelf." AS ".$alias); |
|
|
|
@ -108,8 +43,11 @@ class Controller extends BaseController
|
|
|
|
|
foreach($condition['select'] as $select){ |
|
|
|
|
$builder = $builder->addSelect($alias.".".$select); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$builder = $builder->addSelect($alias.".*"); |
|
|
|
|
} |
|
|
|
|
if(isset($condition['joins'])){ |
|
|
|
|
if(isset($condition['joins'])){ |
|
|
|
|
$selectColumn = []; |
|
|
|
|
$no = 0; |
|
|
|
|
foreach($condition['joins'] as $join){ |
|
|
|
|
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias; |
|
|
|
@ -124,7 +62,7 @@ class Controller extends BaseController
|
|
|
|
|
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); |
|
|
|
|
$no++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(isset($condition['columns'])){ |
|
|
|
|
$listWhere = $condition['columns']; |
|
|
|
@ -161,15 +99,11 @@ class Controller extends BaseController
|
|
|
|
|
$builder = $builder->orderBy($alias.".".$column, $sortBy); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
$builder = $builder->select($alias.".*"); |
|
|
|
|
} |
|
|
|
|
$data['builder'] = $builder; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function groupWhere($oldBuilder, $groupWhere, $alias) |
|
|
|
|
{ |
|
|
|
|
$builder = $oldBuilder; |
|
|
|
|