function dbeav_filter_parser($filter = array(), &$object) { if (!is_array($filter)) { return $filter; } $tPre = '`' . $object->table_name(true) . '`' . '.'; $where = [1]; // 因为searchOptions 会员非 dbschme定义的字段 $qb = $object->database()->createQueryBuilder(); $cols = array_merge($object->searchOptions(), $object->_columns()); // 过滤无用的filter条件 $filter = array_where($filter, function ($filterKey, $filterValue) use($cols) { return !is_null($filterValue) && (isset($cols[$filterKey]) || strpos($filterKey, '|')); }); foreach ($filter as $filterKey => $filterValue) { if (strpos($filterKey, '|')) { list($columnName, $type) = explode('|', $filterKey); $where[] = $this->processTypeSql($tPre . $columnName, $type, $filterValue, $qb); } else { $columnName = $filterKey; if (is_array($filterValue)) { $where[] = $this->processTypeSql($tPre . $columnName, 'in', $filterValue, $qb); } else { $where[] = $this->processTypeSql($tPre . $columnName, 'nequal', $filterValue, $qb); } } } return call_user_func_array(array($qb->expr(), 'andX'), $where); }
public function index() { if (!Auth::check()) { return LoginController::getIndex(); } LoginController::updateUserPermissions(); //why not # Trail Trail::clear(); $tables = array_where(config('center.tables'), function ($key, $value) { return !$value->hidden && LoginController::checkPermission($value->name, 'view'); }); $groups = $objects = []; foreach ($tables as $table) { $latest = DB::table($table->name)->leftJoin(config('center.db.users') . ' as u2', $table->name . '.updated_by', '=', 'u2.id')->select('u2.name as updated_name', $table->name . '.updated_at')->orderBy($table->name . '.updated_at', 'desc')->first(); if (!isset($groups[$table->list_grouping])) { $groups[$table->list_grouping] = []; } $groups[$table->list_grouping][] = (object) ['title' => $table->title, 'list_grouping' => $table->list_grouping, 'link' => action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name), 'updated_name' => isset($latest->updated_name) ? $latest->updated_name : '', 'updated_at' => isset($latest->updated_at) ? $latest->updated_at : '', 'count' => number_format(DB::table($table->name)->count())]; } foreach ($groups as $group) { $objects = array_merge($objects, $group); } $table = new Table(); $table->rows($objects); $table->column('title', 'string', trans('center::site.table')); $table->column('count', 'integer', trans('center::site.count')); $table->column('updated_name', 'updated_name', trans('center::site.updated_name')); $table->column('updated_at', 'updated_at', trans('center::site.updated_at')); $table->groupBy('list_grouping'); $table = $table->draw('tables'); return view('center::tables.index', compact('table')); }
/** * Return a single country by code * * @param sting $code * @return array */ public static function get($code) { $result = array_where(static::$countries, function ($key, $value) use($code) { return $value === $code; }); return $result; }
public function hasChangesExcept(array $except) { $differences = array_where($this->getDifferences(), function ($key) use($except) { return !in_array($key, $except); }); return count($differences) > 0 ? true : false; }
/** * Return a single prefix by id * * @param integer $id * @return array */ public static function get($id) { $result = array_where(static::$prefixes, function ($key, $value) use($id) { return $value == $id; }); return $result; }
/** * Protect Crud functions of controller. * * @return string */ protected function protectMethods() { $request = $this->request; // available methods for resources. $resources = $this->crud['resources']; // protection methods being passed in a route. $methods = $this->getAction('protect_methods'); // get method being called on controller. $caller = $this->parseMethod(); // determine if we use resource or restful http method to protect crud. $called = in_array($caller, $resources) ? $caller : $request->method(); // if controller is a resource or closure // and does not have methods like // UserController@index but only // UserController we use crud restful. $methods = is_array($methods) ? $methods : (in_array($caller, $resources) ? $this->crud['resource'] : $this->crud['restful']); // determine crud method we're trying to protect $crud = array_where($methods, function ($k, $v) use($called) { return in_array($called, $v); }); // crud method is read, view, delete etc // match it against our permissions // view.user or delete.user // multiple keys like create,store? // use OR operator and join keys with alias. $permission = implode('|', array_map(function ($e) { return $e . '.' . $this->parseAlias(); }, array_keys($crud))); return !$this->forbiddenRoute() && $request->user()->can($permission); }
/** * Flash only fields where flash = true * * @param array $fields */ protected function flashInput(array $fields) { $flash = array_where($fields, function ($key, $config) { return $config['flash']; }); Input::flashOnly(array_keys($flash)); }
public function index() { $forums = Forum::where("parent_id", 0)->with("subForums")->orderBy("left_id")->get(); $forums = array_where($forums, function ($_i, $forum) { return $forum->canBeViewedBy(Auth::user()); }); return view("forum.forums.index", compact("forums")); }
public function index() { $forums = Forum::where('parent_id', 0)->with('subForums')->orderBy('left_id')->get(); $forums = array_where($forums, function ($_i, $forum) { return $forum->canBeViewedBy(Auth::user()); }); return view('forum.forums.index', compact('forums')); }
/** * Get city name by pinyin. * * @param $pinyin * @return mixed * * @author Cali */ public static function cityName($pinyin) { $cities = json_decode(File::get(database_path(self::CITIES_FILE_PATH))); $city = array_where($cities, function ($key, $value) use($pinyin) { return strtolower($value->pinyin) === strtolower($pinyin); }); return is_null($city) || count($city) === 0 ? $pinyin : array_values($city)[0]->name; }
public function getLanguage($languageCode) { $languages = $this->languages; $language = array_where($languages, function ($key, $value) use($languageCode) { return $value['code'] == $languageCode; }); return current($language); }
public function getThumbnails(string $url) { $data = $this->getData($url); $data = array_where($data['links']['thumbnail'], function ($key, $value) { return $this->isImage($value); }); $data = array_pluck($data, 'href'); return $data; }
public function showSaved() { $message = 'Looks like you have no template to show. Let\'s create one from <a class="btn btn-primary btn-flat" href="' . route("user::templates") . '">Template Gallery</a>'; $templates = Auth::user()->templates; $savedTemplates = array_where($templates, function ($key, $template) { return $template->htmlviewmenus->count() > 0; }); $templatesCount = collect($savedTemplates)->count(); return view('my_template_view', compact('savedTemplates', 'templatesCount', 'message'))->with('user', Auth::user()); }
private function checkArray($array) { $arr = array_where($array, function ($key, $value) { if (is_array($value)) { return $this->checkArray($value); } return !empty($value); }); return $arr; }
function existDataArray($data, $index) { if (isset($data[$index])) { $array = array_where($data[$index], function ($key, $value) { if (trim($value) != "") { return $value; } }); } else { $array = []; } return $array; }
protected function recordPrimaryImage(array $images) { $primary_image = current(array_values(array_where($images, function ($key, $image) { if ($image['category'] == 'primary') { return true; } return false; }))); if (empty($primary_image)) { return; } $this->images_remembered[] = $this->getRememberableImage($primary_image); $this->filtered_images[] = $primary_image; }
/** * Display a listing of documentos * * @return Response */ public function index() { $documentos = Documento::select("id", "titulo", "morosos", "activo")->activo()->get(); $list = []; foreach (File::files(public_path() . "/docs") as $documento) { $list[] = array("titulo" => substr(strrchr($documento, '/'), 1), "url" => asset('docs/' . substr(strrchr($documento, '/'), 1)), "mime" => substr(strrchr($documento, '.'), 1)); } $docs = array_where($list, function ($key, $documento) { return $documento["titulo"] != 'index.html'; }); $data["documentos_dinamicos"] = $documentos; $data["documentos_clasicos"] = array_values($docs); return Response::json($data, 200); }
protected function inputFor($action, $merge = true) { $rules = $this->users->getValidator()->rules($action, $merge); $fields = array_keys($rules); $confirmed_fields = array_where($rules, function ($key, $rule) { if (is_array($rule)) { return in_array('confirmed', $rule); } else { return $rule !== false; } }); foreach (array_keys($confirmed_fields) as $key) { $fields[] = $key . '_confirmation'; } return array_only($this->input(), $fields); }
/** * Load the correct tag data config to show in create/edit view selects * * @param string $fieldName * @param string $currentValue | null * * @return array */ public static function getTagDataForSelect($fieldName, $currentValue = null) { $allTypes = config(sprintf('asgard.tag.config.tag_%s_text', $fieldName)); if ($fieldName === 'type') { $returnArray = array_where($allTypes, function ($key, $value) use($fieldName) { return self::isDisabled($fieldName, $value) === 'disabled' ? false : true; }); if (empty($currentValue) === false) { if (in_array($currentValue, $returnArray) === false) { $returnArray[] = [$currentValue => $currentValue]; } } return $returnArray; } return $allTypes; }
/** * Get a single user * * @param $name * @return $this */ public function pvpByUser($name) { $name = urldecode($name); $collection = Redis::get(UpdatePvpLeaderboard::$key); $collection = unserialize($collection); // Grab the elements matching the name from all regions $eu = array_where($collection['eu'], function ($key, $value) use($name) { return $value['name'] == $name; }); $na = array_where($collection['na'], function ($key, $value) use($name) { return $value['name'] == $name; }); $element = array_values(array_merge($eu, $na)); // Return the first element! $json = count($element) == 0 ? 'false' : $element[0]; return $this->apiResponse($json, 12 * 60 * 60); }
public function remove() { $ids = Session::get('compare_cart'); if (Input::has('id')) { $remove_id = Input::get('id'); $ids = array_where($ids, function ($k, $v) use($remove_id) { return $v != $remove_id; }); Session::put('compare_cart', $ids); } // Find TourSchedules if (!empty($ids)) { $tour_schedules = \App\TourSchedule::with('tour', 'tour.travel_agent', 'tour.travel_agent.images')->whereIn('id', $ids)->published()->orderBy('departure')->get(); } else { $tour_schedules = new Collection(); } return Response::json(['data' => $tour_schedules->toArray()], 200); }
public function show($orderId = null) { $orders = Store\Order::with('user', 'address', 'address.country', 'items.product'); if ($orderId) { $orders->where('orders.order_id', $orderId); } else { $orders->where('orders.status', 'paid'); } $ordersItemsQuantities = Store\Order::itemsQuantities($orders); $orders = $orders->orderBy('created_at')->get(); $productId = (int) Request::input('product'); if ($productId) { $orders = array_where($orders, function ($_i, $order) use($productId) { return $order->items()->where('product_id', $productId)->exists(); }); } return view('admin.store.orders.show', compact('orders', 'ordersItemsQuantities')); }
public function index() { // return response()->json([], 200, [], JSON_NUMERIC_CHECK); $classrooms = Classroom::select('cs.student_id as chosen', 'classrooms.attendees_limit', 'classrooms.name', 'classrooms.code', 'classrooms.id', 'classrooms.teacher_id', 'classrooms.subject_subject_id', 'classrooms.day', 'classrooms.hour')->join('subject_subjects as subsub', 'subsub.id', '=', 'classrooms.subject_subject_id')->join('student_subjects as stusub', function ($join) { $join->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', $this->student->id)->where('stusub.state', '=', 'study')->where('stusub.semester_id', '=', $this->semester->id); })->leftJoin('classroom_students as cs', function ($j) { $j->on('cs.classroom_id', '=', 'classrooms.id')->where('cs.student_id', '=', $this->student->id)->where('cs.semester_id', '=', semester()->id); })->whereIn('classrooms.gender', [$this->student->gender, 'b'])->with('subject')->withCount('students')->groupBy('classrooms.id')->get()->groupBy('subject_subject_id')->toArray(); $new_classrooms = []; foreach ($classrooms as $classroom) { $exist = array_where($classroom, function ($key, $value) { return $value['chosen'] > 0; }); if (!count($exist)) { $new_classrooms[] = $classroom; } } return response()->json($new_classrooms, 200, [], JSON_NUMERIC_CHECK); }
/** * Get a list of installed AbuseIO notifications and return as an array * * @return array */ public static function getNotification() { $notificationClassList = ClassMapGenerator::createMap(base_path() . '/vendor/abuseio'); /** @noinspection PhpUnusedParameterInspection */ $notificationClassListFiltered = array_where(array_keys($notificationClassList), function ($key, $value) { // Get all notifications, ignore all other packages. if (strpos($value, 'AbuseIO\\Notification\\') !== false) { return $value; } return false; }); $notifications = []; $notificationList = array_map('class_basename', $notificationClassListFiltered); foreach ($notificationList as $notification) { if (!in_array($notification, ['Factory', 'Notification'])) { $notifications[] = $notification; } } return $notifications; }
/** * Get a list of installed AbuseIO parsers and return as an array * @return array */ public static function getParsers() { $parsers = []; $parserClassList = ClassMapGenerator::createMap(base_path() . '/vendor/abuseio'); /** @noinspection PhpUnusedParameterInspection */ $parserClassListFiltered = array_where(array_keys($parserClassList), function ($key, $value) { // Get all parsers, ignore all other packages. if (strpos($value, 'AbuseIO\\Parsers\\') !== false) { return $value; } return false; }); $parserList = array_map('class_basename', $parserClassListFiltered); foreach ($parserList as $parser) { if (!in_array($parser, ['Factory', 'Parser'])) { $parsers[] = $parser; } } return $parsers; }
function cross($current, $synk, $strictMatch = true) { $new = []; $unbound = array_merge($current, []); foreach ($synk as $data) { $found = false; foreach ($current as $entity) { if ($found |= static::same($entity, $data, $strictMatch)) { $this->update($entity, $this->dataToEntityData($data)); $unbound = array_where($unbound, function ($k, $v) use($entity) { return $v != $entity; }); break; } } if (!$found) { $new[] = $data; } } return [$unbound, $new]; }
static function get_cheapest_upcoming_schedules_to_tour($tour) { $schedules = $tour->schedules; if (!$schedules) { return null; } //////////////////////// // Upcoming schedules // //////////////////////// $upcoming_schedules = array_where($schedules, function ($k, $v) { if (!$v->departure_until) { return \Carbon\Carbon::yesterday()->lt(\Carbon\Carbon::parse($v->departure)); } else { return \Carbon\Carbon::yesterday()->lt(\Carbon\Carbon::parse($v->departure_until)); } }); //////////////////////////////// // Sort By Cheapest Schedules // //////////////////////////////// $cheapest_upcoming_schedules = array_sort($upcoming_schedules, function ($upcoming_schedule) { if (!$upcoming_schedule->promos) { return $upcoming_schedule->price; } else { $current_promo = array_where($upcoming_schedule->promos, function ($k, $v) { return \Carbon\Carbon::yesterday()->gte(\Carbon\Carbon::createFromFormat('Y-m-d', $v->since)) && \Carbon\Carbon::yesterday()->lte(\Carbon\Carbon::createFromFormat('Y-m-d', $v->until)); }); if (head($current_promo)->price) { return min(head($current_promo)->price, $upcoming_schedule->price); } else { return $upcoming_schedule->price; } } }); /////////////////// // Return result // /////////////////// return $cheapest_upcoming_schedules; }
/** * Processes the form. * * @return \Illuminate\Http\RedirectResponse */ public function update() { $user = $this->currentUser; $rules = ['email' => "required|unique:users,email,{$user->email},email", 'password' => 'sometimes|required', 'password_confirm' => 'required_with:password|same:password']; $input = array_where(Input::get(), function ($key, $value) { if (str_contains($key, 'password') && empty($value)) { return false; } return true; }); $validator = Validator::make($input, $rules); $validator->passes(); $messages = $validator->errors(); if ($messages->isEmpty()) { try { Sentinel::getUserRepository()->update($user, $input); return Redirect::route('user.edit_profile')->withSuccess('Your profile was successfully updated.'); } catch (NotUniquePasswordException $e) { return Redirect::back()->withInput()->withErrors('This password was used before. You must choose a unique password.'); } } return Redirect::back()->withInput()->withErrors($messages); }
/** * Get the blog post data. * * @param SplFileInfo $file * * @return \stdClass */ public function getPostData(SplFileInfo $file) { $this->file = $file; if ($this->file->getExtension() == 'md') { $postData = Markdown::parseWithYAML($this->file->getContents())[1]; } else { $view = $this->viewFactory->make(str_replace('.blade.php', '', $this->file->getRelativePathname())); $postData = []; $view->render(function ($view) use(&$postData) { $postData = $view->getFactory()->getSections(); }); } // Get only values with keys starting with post:: $postData = array_where($postData, function ($key) { return starts_with($key, 'post::'); }); // Remove 'post::' from $postData keys foreach ($postData as $key => $val) { $postData[str_replace('post::', '', $key)] = $val; unset($postData[$key]); } $postData['path'] = str_replace(KATANA_PUBLIC_DIR, '', $this->getDirectoryPrettyName()) . '/'; return json_decode(json_encode($postData), false); }
<?php Breadcrumbs::register('dashboard', function ($breadcrumbs) { $breadcrumbs->push(trans('messages.dashboard'), route('admin.dashboard.index'), ['icon' => config('menus')['dashboard']['icon']]); }); $models = array_divide(array_where(config('menus'), function ($key, $value) { return $key != 'dashboard'; }))[0]; foreach ($models as $model) { Breadcrumbs::register($model . '.index', function ($breadcrumbs) use($model) { $breadcrumbs->parent('dashboard'); $breadcrumbs->push(trans('messages.' . $model), route('admin.' . $model . '.index')); }); Breadcrumbs::register($model . '.create', function ($breadcrumbs, $table) use($model) { $breadcrumbs->parent($model . '.index'); $breadcrumbs->push(trans('messages.create') . $table, route('admin.' . $model . '.create')); }); Breadcrumbs::register($model . '.edit', function ($breadcrumbs, $table) use($model) { $breadcrumbs->parent($model . '.index'); $breadcrumbs->push(trans('messages.edit') . $table, route('admin.' . $model . '.edit')); }); }