FuelPHP Bin
$orders = Model_Order::query() ->related(array( 'status', 'customer', 'customer_device', 'customer_device.device', 'customer_device.device.manufacturer', 'branch', 'technician', 'technician.metadata', 'order_spares' )) ->offset($input['start']) ->limit($input['length']) ->order_by($input['columns'][$input['order'][0]['column']]['name'], $input['order'][0]['dir']) ->and_where_open() ->or_where_open() ->where('branch_id', 'IN', array_keys(\Session::get('pce_user.active_branches'))) ->and_where_open() ->or_where('customer.first_name', 'LIKE', '%'.$input['search']['value'].'%') ->or_where('customer.last_name', 'LIKE', '%'.$input['search']['value'].'%') ->or_where('customer_device.device.manufacturer.manufacturer_name', 'LIKE', '%'.$input['search']['value'].'%') ->or_where('customer_device.device.device_model', 'LIKE', '%'.$input['search']['value'].'%') ->or_where('technician.metadata.value', 'LIKE', '%'.$input['search']['value'].'%') ->or_where('status.status_name', 'LIKE', '%'.$input['search']['value'].'%') ->and_where_close() ->or_where_close() ->or_where('id', '=', $input['search']['value']) ->and_where_close(); if(($input['unfinished_only'] === 'true')) $orders = $orders->where('status.is_finished', '=', '0'); $orders = $orders->get();