public function postAjaxNestedSetModel() { #$input = Input::all(); $data = Input::get('data'); $data = json_decode($data, 1); #Helper::dd($data); $dic_id = NULL; $dic = NULL; if (count($data)) { $id_left_right = (new NestedSetModel())->get_id_left_right($data); if (count($id_left_right)) { $dicvals = DicVal::whereIn('id', array_keys($id_left_right))->get(); if (count($dicvals)) { foreach ($dicvals as $dicval) { if (!$dic_id) { $dic_id = $dicval->dic_id; } $dicval->lft = $id_left_right[$dicval->id]['left']; $dicval->rgt = $id_left_right[$dicval->id]['right']; $dicval->save(); } if ($dic_id) { $dic = Dic::by_id($dic_id); } } } } $this->callHook('after_order', $dic); $this->callHook('after_store_update_destroy_order', $dic); return Response::make('1'); }
public static function returnShortCodes() { $tpl = static::returnTpl(); shortcode::add("news", function ($params = null) use($tpl) { #print_r($params); die; if (!Allow::module('news')) { return false; } ## Параметры по-умолчанию $default = array('tpl' => Config::get('app-default.news_template', 'default'), 'limit' => Config::get('app-default.news_count_on_page', 3), 'order' => Helper::stringToArray(News::$order_by), 'pagination' => 1, 'type' => false, 'exclude_type' => false, 'include' => false, 'exclude' => false); ## Применяем переданные настройки $params = $params + $default; #dd($params); #echo $tpl.$params['tpl']; if (empty($params['tpl']) || !View::exists($tpl . $params['tpl'])) { throw new Exception('Template [' . $tpl . $params['tpl'] . '] not found.'); } $news = News::orderBy('news.published_at', 'desc')->with('meta.photo', 'meta.gallery.photos', 'meta.seo'); /* ## Получаем новости, делаем LEFT JOIN с news_meta, с проверкой языка и тайтла $selected_news = News::where('news.publication', 1) ->leftJoin('news_meta', 'news_meta.news_id', '=', 'news.id') ->where('news_meta.language', Config::get('app.locale')) ->where('news_meta.title', '!=', '') ->select('*', 'news.id AS original_id', 'news.published_at AS created_at') ->orderBy('news.published_at', 'desc'); #$selected_news = $selected_news->where('news_meta.wtitle', '!=', ''); ## Получаем новости с учетом пагинации #echo $selected_news->toSql(); die; #var_dump($params['limit']); $news = $selected_news->paginate($params['limit']); ## news list with pagination #$news = $selected_news->get(); ## all news, without pagination */ /** * Показываем новости только определенных типов */ if (@$params['type']) { $params['types'] = (array) explode(',', $params['type']); #Helper::d($params); if (isset($params['types']) && is_array($params['types']) && count($params['types']) && Allow::module('dictionaries') && class_exists('DicVal')) { $types = DicVal::whereIn('slug', $params['types'])->get(); #Helper::tad($types); if ($types->count()) { $types = $types->lists('id'); #Helper::tad($types); if (count($types)) { $news = $news->whereIn('type_id', $types); } } } } /** * Исключаем новости определенных типов */ if (@$params['exclude_type']) { $params['exclude_types'] = (array) explode(',', $params['exclude_type']); #Helper::d($params); if (isset($params['exclude_types']) && is_array($params['exclude_types']) && count($params['exclude_types']) && Allow::module('dictionaries') && class_exists('DicVal')) { $types = DicVal::whereIn('slug', $params['exclude_types'])->get(); #Helper::tad($types); if ($types->count()) { $types = $types->lists('id'); #Helper::tad($types); if (count($types)) { $news = $news->whereNotIn('type_id', $types); } } } } /** * Будем выводить только новости, ID которых указаны */ if (@$params['include']) { $params['includes'] = (array) explode(',', $params['include']); if (isset($params['includes']) && is_array($params['includes']) && count($params['includes'])) { $news = $news->whereIn('id', $params['includes']); } } /** * Исключаем новости с заданными ID */ if (@$params['exclude']) { $params['excludes'] = (array) explode(',', $params['exclude']); if (isset($params['excludes']) && is_array($params['excludes']) && count($params['excludes'])) { $news = $news->whereNotIn('id', $params['excludes']); } } $news = $news->paginate($params['limit']); #Helper::tad($news); /* foreach ($news as $n => $new) { #print_r($new); die; $gall = Rel_mod_gallery::where('module', 'news')->where('unit_id', $new->original_id)->first(); #foreach ($gall->photos as $photo) { # print_r($photo->path()); #} #print_r($gall->photos); die; $new->gall = @$gall; $new->image = is_object(@$gall->photos[0]) ? @$gall->photos[0]->path() : ""; $news[$n]->$new; } */ #echo $news->count(); die; if (!$news->count()) { return false; } return View::make($tpl . $params['tpl'], compact('news')); }); }