where($display, 'LIKE', '%' . $term . '%'); } else { $query->orWhere($display, 'LIKE', '%' . $term . '%'); } $first = false; } } return $query; } else { return []; } } /** * Returns data for the dashboard * * @return array */ public static function getDashboardData($include_param_display = false) { $sort_direction = static::$dashboard_reorder ? 'desc' : static::$dashboard_sort_direction; $query = self::orderBy(static::$dashboard_sort_column, $sort_direction); $query_param_display = []; foreach (static::$dashboard_columns as $column) { if (array_key_exists('type', $column) && $column['type'] == 'user') { $query->where($column['name'], Auth::id()); break; } } if (count(static::$valid_query_params) > 0) { foreach (static::$valid_query_params as $param) { if (request()->query($param['key'], null) != null) { if ($include_param_display) { $query_param_model = 'App\\Models\\' . $param['model']; $query_param_column = $query_param_model::find(request()->query($param['key'])); if ($query_param_column !== null) { array_push($query_param_display, [ 'title' => $param['title'], 'value' => $query_param_column[$param['display']] ]); } } $query->where($param['column'], request()->query($param['key'])); } } } if (static::$items_per_page === 0) { $results = $query->get(); } else { if (static::$filter && request()->query('search', null) != null) { $query = static::searchDisplay(request()->query('search'), $query); } $results = $query->paginate(static::$items_per_page); } if ($include_param_display) { return [ 'rows' => $results, 'paramdisplay' => $query_param_display ]; } else { return $results; } } /** * Retrieves the current query string containing valid query parameters * * @return string */ public static function getQueryString() { $valid_query_params = static::$valid_query_params; $string = ''; if (static::$items_per_page !== 0 && static::$filter) { array_push($valid_query_params, [ 'key' => 'search' ]); } foreach ($valid_query_params as $param) { if (request()->query($param['key'], null) != null) { if ($string !== '') { $string .= '&'; } $string .= $param['key'] . '=' . request()->query($param['key']); } } return $string; } /** * Determines whether a user column exists and whether it matches the current user if it does * * @return boolean */ public function userCheck() { $user_check = true; foreach (static::$dashboard_columns as $column) { if (array_key_exists('type', $column) && $column['type'] == 'user') { if ($this->{$column['name']} != Auth::id()) { $user_check = false; } break; } } return $user_check; } }