public function appProject($lang, $slug) { $project = Dic::valueBySlugs('projects', $slug, ['fields', 'textfields']); #Helper::tad($project); if (!$project) { App::abort(404); } $project = DicLib::loadImages($project, ['image']); $project_page = Page::by_id($project->page_id); #Helper::tad($project_page); if (!$project_page) { App::abort(404); } $prev_project = null; $next_project = null; $prev_project = Dic::valuesBySlug('projects', function ($query) use($project) { $query->where('lft', '<', $project->lft); $query->orderBy('lft', 'ASC'); $query->take(1); }, ['fields', 'textfields'], true, true, true); #Helper::ta($prev_project); $next_project = Dic::valuesBySlug('projects', function ($query) use($project) { $query->where('lft', '>', $project->lft); $query->orderBy('lft', 'ASC'); $query->take(1); }, ['fields', 'textfields'], true, true, true); #Helper::tad($next_project); return View::make(Helper::layout('project'), compact('project', 'project_page', 'prev_project', 'next_project')); }
$route = Route::current(); #dd($route); $id = $route->getParameter('id'); $record = Dic::valueBySlugAndId('blog', $id, ['fields', 'textfields']); if (!$record) { echo json_encode(['responseType' => 'error', 'responseCode' => 404]); return; } $record = DicLib::loadImages($record, ['image', 'header_img']); #Helper::tad($record); $others_news = Dic::valuesBySlug('blog', function ($query) use($record) { $query->where('id', '!=', $record->id); $query->orderBy('created_at', 'desc'); $query->take(5); }, ['fields', 'textfields']); $others_news = DicLib::loadImages($others_news, ['image']); #Helper::tad($others_news); ?> @section('style') @stop @section('content') <section class="b-title " style="background-image: url({{ isset($record->header_img) && is_object($record->header_img) ? $record->header_img->full() : '' }});"> <div class="b-title__logo _invisible"> <img src="{{ Config::get('site.theme_path') }}/img/logo/ikra-top.png" height="102" width="129" alt="ИКРА IKRA"> </div>
/** * Экстрактит все записи словаря внутри коллекции * * $collection = DicVal::extracts($collection); * * @param $elements * @param bool $unset * @param bool $extract_ids * @return Collection */ public static function extracts($elements, $field = null, $unset = false, $extract_ids = true) { return DicLib::extracts($elements, $field, $unset, $extract_ids); }
#dd($route); $id = $route->getParameter('id'); $event = Dic::valueBySlugAndId('events', $id, ['fields', 'textfields']); if (!$event) { echo json_encode(['responseType' => 'error', 'responseCode' => 404]); return; } $event = DicLib::loadImages($event, ['image', 'header_img']); #Helper::tad($event); $others_events = Dic::valuesBySlug('events', function ($query) use($event) { #$query->where('id', '!=', $event->id); $query->filter_by_field('date_start', '>=', date('Y-m-d')); $query->order_by_field('date_start', 'asc'); $query->take(5); }, ['fields', 'textfields']); $others_events = DicLib::loadImages($others_events, ['image']); #Helper::tad($others_news); ?> @section('style') @stop @section('content') <section class="b-title " style="background-image: url({{ isset($event->header_img) && is_object($event->header_img) ? $event->header_img->full() : '' }});"> <div class="b-title__logo _invisible"> <img src="{{ Config::get('site.theme_path') }}/img/logo/ikra-top.png" height="102" width="129" alt="ИКРА IKRA"> </div>
public static function returnRoutes($prefix = null) { /** * Здесь нужно кешировать города, направления, типы курсов, партнеры, клиенты * Загружаем из БД - сохраняем в кеше на 10 минут например * При сохранении этих сущностей - сбрасывать кеш (в настройках словарей) * dic.city, dic.direction, dic.type, dic.partners, dic.clients и т.д. * * Ниже идет получение города юзера из БД - заменить на получение из кеша */ $dics_for_cache = ['city', 'direction', 'type', 'course', 'teachers', 'stories', 'partners', 'clients', 'professions', 'students_work', 'reviews', 'cases', 'workers']; foreach ($dics_for_cache as $dic_name) { ## Refresh dics cache #Cache::forget('dic_' . $dic_name); $dic_[$dic_name] = Cache::get('dic_' . $dic_name); if (!$dic_[$dic_name]) { Cache::forget('dic_' . $dic_name); $dic_[$dic_name] = Dic::valuesBySlug($dic_name, null, ['fields', 'textfields', 'related_dicvals'], true, true, true); $dic_[$dic_name] = DicLib::loadImages($dic_[$dic_name], ['avatar', 'image', 'logo', 'photo', 'header_img']); Cache::add('dic_' . $dic_name, $dic_[$dic_name], self::$global_cache_min); } View::share('dic_' . $dic_name, $dic_[$dic_name]); #Helper::d($dic_name); Helper::ta($dic_{$dic_name}); } #Helper::tad($dic_{'city'}); #die; /** * Определяем город юзера, если есть пометка в COOKIES. Иначе - Москва (id из конфига). * Предзагружаем из сессии, кешируем в сессию, делаем глобальным для шаблонизатора. */ $dic_city = $dic_['city']; #Helper::tad($dic_city); $refresh_city = false; #$refresh_city = true; $user_city_cache_key = self::$user_city_cache_key; $user_city_cache_min = self::$user_city_cache_min; if ($refresh_city) { Session::forget($user_city_cache_key); } $city = @$dic_city[Session::get($user_city_cache_key)]; #Helper::tad($city); if (!$city || $refresh_city) { Session::forget($user_city_cache_key); if (isset($_COOKIE['city_id']) && is_numeric($_COOKIE['city_id'])) { $city = @$dic_city[$_COOKIE['city_id']]; } if (!$city || $refresh_city) { $city = @$dic_city[Config::get('site.default_city_id')]; } Session::set($user_city_cache_key, $city->id); } #Helper::tad($city); #die; View::share($user_city_cache_key, $city); View::share($user_city_cache_key . '_slug', $city->slug); /** * Общие роуты */ Route::group(array(), function () { #Route::any('/ajax/send-message', array('as' => 'ajax.send-message', 'uses' => __CLASS__.'@postSendMessage')); Route::any('/ajax/change_city', array('as' => 'ajax.change_city', 'uses' => __CLASS__ . '@ajaxChangeCity')); Route::any('/ajax/get_courses', array('as' => 'ajax.get_courses', 'uses' => __CLASS__ . '@ajaxGetCourses')); Route::any('/ajax/form_question', array('as' => 'app.form_question', 'uses' => __CLASS__ . '@formQuestion')); Route::any('/ajax/form_course_register', array('as' => 'app.form_course_register', 'uses' => __CLASS__ . '@formCourseRegister')); Route::any('/ajax/form_corp', array('as' => 'app.form_corp', 'uses' => __CLASS__ . '@formCorp')); Route::any('/ajax/form_subscribe', array('as' => 'app.form_subscribe', 'uses' => __CLASS__ . '@formSubscribe')); Route::any('/ajax/form_course', array('as' => 'app.form_course', 'uses' => __CLASS__ . '@formCourse')); }); }
<?php return array('fields' => function () { return array('image' => array('title' => 'Картинка', 'type' => 'image', 'params' => array('maxFilesize' => 4)), 'color' => array('title' => 'Код цвета (#000000 - #ffffff)', 'type' => 'text', 'others' => ['placeholder' => '#000000'])); }, 'hooks' => array('before_index_view' => function ($dic, $dicvals) { $dicvals = DicLib::loadImages($dicvals, ['image']); }), 'first_line_modifier' => function ($line, $dic, $dicval) { #Helper::ta($dicval); return (isset($dicval->image) && is_object($dicval->image) ? '<img src="' . $dicval->image->thumb() . '" height="20"/> ' : '') . '<span style="color:' . $dicval->color . '">' . $dicval->name . '</span>'; }, 'second_line_modifier' => function ($line, $dic, $dicval) { return $dicval->color; });
/** * Возвращает записи из словаря по системному имени словаря и набору IDs нужных записей. * Третьим параметром можно передать метку, указывающую на необходимость сделать экстракт каждой записи. * * @param $slug * @param $val_ids * @param string $with * @param bool $extract * @param bool $unset * @return $this|Collection|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|null|static */ public static function valuesBySlugAndIds($slug, $val_ids, $with = 'all', $extract = true, $unset = true, $extract_ids = false) { $return = new Collection(); #$dic = Dic::where('slug', $slug)->first(); #$dic = @Config::get(self::$cache_key)['by_slug'][$slug]; $dic = Dic::by_slug($slug); if (!is_object($dic) || !is_array($val_ids) || !count($val_ids)) { return $return; } $values = DicVal::where('dic_id', $dic->id)->where('version_of', NULL)->whereIn('id', $val_ids); if ($with == 'all') { $with = ['meta', 'fields', 'textfields', 'seo', 'related_dicvals']; } else { $with = (array) $with; } $db_remember_timeout = Config::get('app.settings.main.db_remember_timeout'); if (count($with)) { ## ## Cache relations ## if (NULL != $db_remember_timeout && is_numeric($db_remember_timeout) && $db_remember_timeout > 0) { $temp = []; foreach ($with as $relation) { $temp[$relation] = function ($query) use($db_remember_timeout) { $query->remember($db_remember_timeout); }; } $with = $temp; } $values = $values->with($with); } ## ## Cache query ## if (NULL != $db_remember_timeout && is_numeric($db_remember_timeout) && $db_remember_timeout > 0) { $values->remember($db_remember_timeout); } $values = $values->get(); #Helper::tad($values); if ($extract) { $values = DicLib::extracts($values, null, $unset, $extract_ids); } #Helper::tad($values); return $values; }
* Тут нужно проверить работу с новым форматом данных в DicValRel, * привести в соответствие с методом из scope_id. * Сделать это нужно при первой же необходимости использования select-multiple. */ $value = (array) $value; $value = array_flip($value); foreach ($value as $v => $null) { $value[$v] = array('dicval_child_dic' => 'scope'); } $element->related_dicvals()->sync($value); return @count($value); }, 'value_modifier' => function ($value, $element) { $return = is_object($element) && $element->id ? $element->related_dicvals()->get()->lists('id') : ($return = array()); return $return; }), 'basic' => array('no_label' => true, 'title' => 'Чекбокс обычный', 'type' => 'checkbox', 'label_class' => 'normal_checkbox'), 'type_ids' => array('title' => 'Группа чекбоксов', 'type' => 'checkboxes', 'columns' => 2, 'values' => $lists['ontrade_types'], 'handler' => function ($value, $element, $field_name = 'type_ids') use($lists_ids) { $value = DicLib::formatDicValRel($value, $field_name, $element->dic_id, $lists_ids['ontrade_types']); #$element->related_dicvals($field_name)->sync($value); DicValRel::where('dicval_parent_id', $element->id)->where('dicval_parent_field', $field_name)->delete(); if (count($value)) { foreach ($value as $v => $val) { $element->related_dicvals($field_name)->attach($v, $val); } } return @count($value); }, 'value_modifier' => function ($value, $element, $field_name = 'type_ids') { $return = is_object($element) && $element->id ? $element->related_dicvals($field_name)->get()->lists('name', 'id') : ($return = array()); return $return; }), 'promise_id' => array('title' => 'Обещание', 'type' => 'textline', 'view_text' => @$lists['promises'][$dicval->promise_id]), 'map' => array('type' => 'custom', 'content' => View::make('system.views.map_google_block', ['element' => $dicval])->render(), 'scripts' => View::make('system.views.map_google_script', ['element' => $dicval, 'geo_prefix' => '"Россия, Ростов-на-Дону, "', 'default_lat' => '47.25221300', 'default_lng' => '39.69359700', 'default_zoom' => '11'])->render())); }, 'menus' => function ($dic, $dicval = NULL) { $menus = array(); $menus[] = array('raw' => '<br/>');
$dics_slugs = array('direction', 'course', 'teachers'); $dics = Dic::whereIn('slug', $dics_slugs)->with('values')->get(); $dics = Dic::modifyKeys($dics, 'slug'); #Helper::tad($dics); $lists = Dic::makeLists($dics, 'values', 'name', 'id'); #Helper::dd($lists); $lists_ids = Dic::makeLists($dics, null, 'id', 'slug'); #Helper::dd($lists_ids); #Helper::ta($lists); #Helper::tad($dicval); $value_course_id = @$dicval->allfields[Config::get('app.locale')]['course_id']; if (!$value_course_id) { $value_course_id = Input::get('filter.fields.course_id'); } return array('course_id' => array('title' => 'Курс', 'type' => 'select', 'values' => $lists['course'], 'default' => Input::get('filter.fields.course_id') ?: null), 'direction_id' => array('title' => 'Направление занятия', 'type' => 'select', 'values' => $lists['direction'], 'default' => Input::get('filter.fields.direction_id') ?: null), 'when' => array('title' => 'Когда', 'type' => 'text'), 'what' => array('title' => 'Что делаем', 'type' => 'textarea_redactor'), 'teacher_id' => array('title' => 'Куратор блока', 'type' => 'select', 'values' => $lists['teachers'], 'default' => Input::get('filter.fields.teacher_id') ?: null), 'teachers' => array('title' => 'Все преподаватели блока', 'type' => 'checkboxes', 'columns' => 2, 'values' => $lists['teachers'], 'handler' => function ($value, $element, $field_name = 'teachers') use($lists_ids) { $value = DicLib::formatDicValRel($value, $field_name, $element->dic_id, $lists_ids['teachers']); #$element->related_dicvals($field_name)->sync($value); DicValRel::where('dicval_parent_id', $element->id)->where('dicval_parent_field', $field_name)->delete(); if (count($value)) { foreach ($value as $v => $val) { $element->related_dicvals($field_name)->attach($v, $val); } } return @count($value); }, 'value_modifier' => function ($value, $element, $field_name = 'teachers') { $return = is_object($element) && $element->id ? $element->related_dicvals($field_name)->get()->lists('name', 'id') : ($return = array()); return $return; }), '-' => array('type' => 'custom', 'content' => '<br/><strong>ИЛИ</strong><br/><br/>'), 'col_1' => array('title' => 'Колонка 1', 'type' => 'textarea_redactor'), 'col_2' => array('title' => 'Колонка 2', 'type' => 'textarea_redactor')); }, 'menus' => function ($dic, $dicval = NULL) { $menus = array(); $menus[] = array('raw' => '<br/>');
<?php return array('fields' => function () { return array('desc' => array('title' => 'Описание параметра', 'type' => 'textarea')); }, 'hooks' => array('before_all' => function ($dic) { }, 'before_index' => function ($dic) { }, 'before_index_view' => function ($dic, $dicvals) { $dicvals->load('textfields'); #Helper::tad($dicvals); $dicvals = DicLib::extracts($dicvals, null, true, true); }), 'second_line_modifier' => function ($line, $dic, $dicval) { #$dicval->extract(true); return $dicval->slug . (isset($dicval->desc) && $dicval->desc ? ' — <i>' . $dicval->desc . '</i>' : ''); }, 'slug_label' => 'Системное имя параметра');
$current_page = Input::get('tab') == 'blog' ? Input::get('page') : 1; Paginator::setCurrentPage($current_page); $blogs = Dic::valuesBySlug('blog', function ($query) { $query->orderBy('created_at', 'desc'); }, ['fields', 'textfields'], true, true, true, 6); $blogs = DicLib::loadImages($blogs, ['image']); #Helper::tad($blogs); #dd($blogs); $current_page = Input::get('tab') == 'events' ? Input::get('page') : 1; Paginator::setCurrentPage($current_page); $events = Dic::valuesBySlug('events', function ($query) use($current_city) { $query->filter_by_field('city_id', '=', $current_city->id); $query->filter_by_field('date_start', '>=', date('Y-m-d')); $query->order_by_field('date_start', 'asc'); }, ['fields', 'textfields'], true, true, true, 1); $events = DicLib::loadImages($events, ['image']); #Helper::tad($events); #dd($events); Paginator::setCurrentPage(1); $current_tab = 'blog'; if (Input::get('tab') == 'events') { $current_tab = Input::get('tab'); } elseif (Input::get('tab') == 'social') { $current_tab = Input::get('tab'); } ?> @section('style') @stop
public function index($dic_id) { $dic = Dictionary::where(is_numeric($dic_id) ? 'id' : 'slug', $dic_id)->first(); if (!$this->checkDicPermission($dic)) { App::abort(404); } $this->dicval_permission($dic, 'dicval_view'); $dic->settings = json_decode($dic->settings, 1); $this->checkDicUrl($dic, $dic_id); $this->callHook('before_all', $dic); $this->callHook('before_index', $dic); ## Get element $elements = new DicVal(); $tbl_dicval = $elements->getTable(); $elements = $elements->where($tbl_dicval . '.dic_id', (int) $dic->id)->where($tbl_dicval . '.version_of', '=', NULL)->with('fields'); #$elements = DB::table('dictionary_values')->where('dic_id', $dic->id)->select('dictionary_values.*'); if (NULL !== ($filter = Input::get('filter'))) { #Helper::d($filter); if (isset($filter['fields']) && is_array($filter) && count($filter)) { $tbl_fields = new DicFieldVal(); $tbl_fields = $tbl_fields->getTable(); #Helper::d($filter['fields']); foreach ($filter['fields'] as $key => $value) { $rand_tbl_alias = md5(rand(99999, 999999)); $elements = $elements->join($tbl_fields . ' AS ' . $rand_tbl_alias, function ($join) use($tbl_dicval, $tbl_fields, $key, $value, $rand_tbl_alias) { $join->on($rand_tbl_alias . '.dicval_id', '=', $tbl_dicval . '.id')->where($rand_tbl_alias . '.key', '=', $key)->where($rand_tbl_alias . '.value', '=', $value); })->addSelect($rand_tbl_alias . '.value AS ' . $key); } } } ## Ordering $sort_order = $dic->sort_order_reverse ? 'DESC' : 'ASC'; #Helper::dd($dic->sort_by); /** * Кол-во элементов, подпадающих под условия, но без учета пагинации */ $total_elements_current_selection = clone $elements; $total_elements_current_selection = (int) $total_elements_current_selection->count(); #Helper::tad($total_elements_current_selection); switch ($dic->sort_by) { case '': /* $elements = $elements ->orderBy($tbl_dicval.'.order', $sort_order) ->orderBy($tbl_dicval.'.name', $sort_order); */ $elements = $elements->orderBy(DB::raw('-' . $tbl_dicval . '.lft'), 'DESC')->orderBy($tbl_dicval . '.id', $sort_order); break; case 'name': $elements = $elements->orderBy($tbl_dicval . '.name', $sort_order); break; case 'slug': $elements = $elements->orderBy($tbl_dicval . '.slug', $sort_order); break; case 'created_at': $elements = $elements->orderBy($tbl_dicval . '.created_at', $sort_order); break; case 'updated_at': $elements = $elements->orderBy($tbl_dicval . '.updated_at', $sort_order); break; default: /** * ORDER BY по произвольному полю */ /* #Helper::dd($dic->sort_by); #$dic->sort_by .= '2'; $tbl_fields = (new DicFieldVal())->getTable(); $rand_tbl_alias = md5(rand(99999, 999999)); $elements = $elements ->leftJoin($tbl_fields . ' AS ' . $rand_tbl_alias, function ($join) use ($tbl_dicval, $tbl_fields, $rand_tbl_alias, $dic, $sort_order) { $join ->on($rand_tbl_alias . '.dicval_id', '=', $tbl_dicval . '.id') ; }) ### !!! WHERE должно быть именно здесь, а не внутри JOIN-а !!! ### ### !!! Иначе происходит неведомая хрень: dic_id = 'field' !!! ### ->where($rand_tbl_alias . '.key', '=', $dic->sort_by) ->addSelect($rand_tbl_alias . '.value AS ' . $dic->sort_by) #->orderBy($dic->sort_by, $sort_order) ->orderBy($rand_tbl_alias.'.value', $sort_order) ->orderBy($tbl_dicval.'.created_at', 'DESC') ## default ; */ $elements = $elements->order_by_field($dic->sort_by, $sort_order); break; } #Helper::tad($dic->pagination); ## Search $search_query = NULL; if (NULL !== ($search_query = Input::get('q'))) { $elements = $elements->where('name', 'LIKE', '%' . $search_query . '%')->orWhere('slug', 'LIKE', '%' . $search_query . '%'); } ## Dic settings $dic_settings = Config::get('dic/' . $dic->slug); #Helper::dd($dic_settings); ## Sortable settings $sortable = $dic->sortable && $dic->pagination == 0 && $dic->sort_by == null ? true : false; ## Disable sortable without needable filter options if ($sortable && isset($dic_settings['disable_ordering_without_filter']) && $dic_settings['disable_ordering_without_filter']) { $dic_settings['disable_ordering_without_filter'] = (array) $dic_settings['disable_ordering_without_filter']; #Helper::ta($dic_settings['disable_ordering_without_filter']); if (count($dic_settings['disable_ordering_without_filter'])) { foreach ($dic_settings['disable_ordering_without_filter'] as $condition) { if (!Input::get('filter.fields.' . $condition)) { $sortable = false; break; } } } } ## Disable listing without needable filter options $listing = true; if (isset($dic_settings['disable_listing_without_filter']) && $dic_settings['disable_listing_without_filter']) { $dic_settings['disable_listing_without_filter']['fields'] = (array) $dic_settings['disable_listing_without_filter']['fields']; #Helper::ta($dic_settings['disable_listing_without_filter']['fields']); if (count($dic_settings['disable_listing_without_filter']['fields'])) { foreach ($dic_settings['disable_listing_without_filter']['fields'] as $condition) { if (!Input::get('filter.fields.' . $condition)) { $listing = false; break; } } } } if (isset($dic_settings['sortable']) && is_callable($dic_settings['sortable'])) { $sortable = $dic_settings['sortable']($dic, $elements); } ## Pagination if ($dic->pagination > 0) { $elements = $elements->paginate($dic->pagination); } else { $elements = $elements->get(); } #Helper::tad($elements); #Helper::smartQueries(1); $elements_pagination = clone $elements; #Helper::tad($elements); DicLib::extracts($elements, null, true, true); #$elements = Dic::modifyKeys($elements, 'id'); if (Config::get('debug') == 1 || Input::get('debug') == 1) { Helper::smartQueries(1); Helper::tad($elements); } $actions_column = false; if (Allow::action($this->module['group'], 'dicval_edit') || Allow::action($this->module['group'], 'dicval_delete') || isset($dic_settings['actions']) && is_callable($dic_settings['actions'])) { $actions_column = true; } $total_elements = DicVal::where('dic_id', $dic->id)->where('version_of', '=', NULL)->count(); $this->callHook('before_index_view_create_edit', $dic, $elements); $this->callHook('before_index_view', $dic, $elements); $id_left_right = array(); if (count($elements)) { foreach ($elements as $element) { $id_left_right[$element->id] = array(); $id_left_right[$element->id]['left'] = $element->lft; $id_left_right[$element->id]['right'] = $element->rgt; } } $hierarchy = (new NestedSetModel())->get_hierarchy_from_id_left_right($id_left_right); #Helper::ta($dic); #Helper::tad($elements); #Helper::dd($hierarchy); #Helper::dd($dic_settings['actions']()); #return View::make(Helper::acclayout()); #return View::make($this->module['tpl'].'index_old', compact('elements', 'dic', 'dic_id', 'sortable', 'dic_settings', 'actions_column', 'total_elements', 'total_elements_current_selection')); return View::make($this->module['tpl'] . 'index', compact('elements', 'elements_pagination', 'hierarchy', 'dic', 'dic_id', 'sortable', 'dic_settings', 'actions_column', 'total_elements', 'total_elements_current_selection', 'search_query', 'listing')); }