public function destroy($dic_id, $id, $check_ajax = true)
 {
     if ($check_ajax && !Request::ajax()) {
         App::abort(404);
     }
     $dic = Dictionary::where(is_numeric($dic_id) ? 'id' : 'slug', $dic_id)->first();
     if (!$this->checkDicPermission($dic)) {
         App::abort(404);
     }
     $this->dicval_permission($dic, 'dicval_delete');
     $json_request = array('status' => FALSE, 'responseText' => '');
     $element = DicVal::where('id', $id)->with('allfields', 'alltextfields', 'metas', 'seos', 'related_dicvals')->first();
     $this->callHook('before_all', $dic);
     $this->callHook('before_destroy', $dic, $element);
     if (is_object($element)) {
         #Helper::dd("UPDATE " . (new DicVal())->getTable() . " SET lft = lft - 1, rgt = rgt - 1 WHERE dic_id = '" . $element->dic_id . "' AND lft > " . $element->rgt . "");
         #Helper::tad($element);
         if (@count($element->allfields)) {
             #foreach ($element->allfields as $el)
             #    $el->delete();
             $temp_ids = Dic::makeLists($element->allfields, false, 'id');
             DicFieldVal::whereIn('id', $temp_ids)->delete();
         }
         if (@count($element->alltextfields)) {
             $temp_ids = Dic::makeLists($element->alltextfields, false, 'id');
             DicTextFieldVal::whereIn('id', $temp_ids)->delete();
         }
         if (@count($element->metas)) {
             #foreach ($element->metas as $el)
             #    $el->delete();
             $temp_ids = Dic::makeLists($element->metas, false, 'id');
             DicValMeta::whereIn('id', $temp_ids)->delete();
         }
         if (@count($element->seos)) {
             $temp_ids = Dic::makeLists($element->seos, false, 'id');
             Seo::whereIn('id', $temp_ids)->delete();
         }
         if (@count($element->related_dicvals)) {
             foreach ($element->related_dicvals as $el) {
                 if (is_object($el) && isset($el->pivot) && is_object($el->pivot)) {
                     $el->pivot->delete();
                 }
             }
         }
         if ((int) $element->rgt > 0) {
             DB::update(DB::raw("UPDATE " . (new DicVal())->getTable() . " SET lft = lft - 2, rgt = rgt - 2 WHERE dic_id = '" . $element->dic_id . "' AND lft > " . $element->rgt . ""));
         }
         $element->delete();
     }
     $this->callHook('after_destroy', $dic, $element);
     $this->callHook('after_store_update_destroy', $dic, $element);
     $this->callHook('after_store_update_destroy_order', $dic, $element);
     $json_request['responseText'] = 'Удалено';
     $json_request['status'] = TRUE;
     return Response::json($json_request, 200);
 }
Beispiel #2
0
<?php

return array('fields' => function () {
    /**
     * Предзагружаем нужные словари с данными, по системному имени словаря, для дальнейшего использования.
     * Делается это одним SQL-запросом, для снижения нагрузки на сервер БД.
     */
    $dics_slugs = array('city', 'course');
    $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);
    return array('company' => array('title' => 'Компания', 'type' => 'text'), 'position' => array('title' => 'Должность', 'type' => 'text'), 'quote' => array('title' => 'Цитата в шапке', 'type' => 'textarea'), 'header_img' => array('title' => 'Изображение в шапке', 'type' => 'image', 'params' => array('maxFilesize' => 4)), 'avatar' => array('title' => 'Аватар', 'type' => 'image', 'params' => array('maxFilesize' => 4)), 'gender' => array('title' => 'Пол', 'type' => 'select', 'values' => Config::get('site.genders')), 'short' => array('title' => 'Короткий текст', 'type' => 'textarea'), 'full' => array('title' => 'Полный текст', 'type' => 'textarea_redactor'), 'city_id' => array('title' => 'Город', 'type' => 'select', 'values' => $lists['city'], 'default' => Input::get('filter.fields.city_id') ?: null), 'course_id' => array('title' => 'Обучался на курсе', 'type' => 'select', 'values' => array('Выберите..') + $lists['course'], 'default' => Input::get('filter.fields.course_id') ?: null), '-' => array('type' => 'custom', 'content' => '<br/><strong>ИЛИ</strong><br/><br/>'), 'course_text' => array('title' => 'Название курса', 'type' => 'text'), 'fb_link' => array('title' => 'Facebook', 'type' => 'text', 'others' => ['placeholder' => 'http://']), 'vk_link' => array('title' => 'VKontakte', 'type' => 'text', 'others' => ['placeholder' => 'http://']), 'ig_link' => array('title' => 'Instagram', 'type' => 'text', 'others' => ['placeholder' => 'http://']), 'tw_link' => array('title' => 'Twitter', 'type' => 'text', 'others' => ['placeholder' => 'http://']), 'yt_link' => array('title' => 'YouTube', 'type' => 'text', 'others' => ['placeholder' => 'http://']), 'mainpage' => array('no_label' => true, 'title' => 'Показывать на главной', 'type' => 'checkbox', 'label_class' => 'normal_checkbox'));
}, 'hooks' => array('after_store_update_destroy_order' => function ($dic = NULL, $dicval = NULL) {
    Cache::forget('dic_' . $dic->slug);
}));
Beispiel #3
0
    #Helper::tad($dics);
    Config::set('temp.index_dics', $dics);
    ## Получаем список с нужными индексами
    $cities = Dic::makeLists($dics['city']['values_no_conditions'], null, 'name', 'id');
    #Helper::ta($cities);
    Config::set('temp.cities', $cities);
    ## Получаем список с нужными индексами
    $types = Dic::makeLists($dics['type']['values_no_conditions'], null, 'name', 'id');
    #Helper::ta($types);
    Config::set('temp.types', $types);
    /**
     * Создаем списки из полученных данных
     */
    $dic_ids = Dic::makeLists($dics, false, 'id');
    #Helper::d($dic_ids);
    $dicval_ids = Dic::makeLists($dicvals, false, 'id');
    #Helper::d($dicval_ids);
    /**
     * Получаем количество необходимых нам данных, одним SQL-запросом.
     * Сохраняем данные в конфиг - для дальнейшего использования в функции-замыкании actions (см. выше).
     */
    $counts = array();
    if (count($dic_ids) && count($dicval_ids)) {
        $counts = DicVal::counts_by_fields($dic_ids, array('course_id' => $dicval_ids));
    }
    #Helper::dd($counts);
    Config::set('temp.index_counts', $counts);
}, 'after_store_update_destroy_order' => function ($dic = NULL, $dicval = NULL) {
    Cache::forget('dic_' . $dic->slug);
}), 'second_line_modifier' => function ($line, $dic, $dicval) {
    #Helper::ta($dicval);