Exemplo n.º 1
0
 public function store()
 {
     Allow::permission($this->module['group'], 'create');
     #Helper::dd(Input::all());
     #Helper::d(Input::file('files'));
     #Helper::d(Input::hasFile('files.files'));
     #Helper::dd($_FILES);
     if (Input::hasFile('files.files')) {
         #Helper::d(Input::file('files'));
         $result = ExtForm::process('uploads', Input::file('files'));
         #Helper::dd($result);
     }
     return Redirect::to(URL::previous());
     #return Redirect::to(URL::route('uploads.index', $array));
 }
Exemplo n.º 2
0
<?php

return array('fields' => function ($dicval = NULL) {
    return array('photo' => array('title' => 'Изображение', 'type' => 'upload', 'accept' => '*', 'label_class' => 'input-file', 'handler' => function ($value, $element = false) {
        if (@is_object($element) && @is_array($value)) {
            $value['module'] = 'DicVal';
            $value['unit_id'] = $element->id;
        }
        return ExtForm::process('upload', $value);
    }), 'longitude' => array('title' => 'Долгота', 'type' => 'text'), 'latitude' => array('title' => 'Широта', 'type' => 'text'), 'content' => array('title' => 'Описание', 'type' => 'textarea'), 'item_back_class' => array('title' => 'Класс', 'type' => 'text'));
}, 'menus' => function ($dic, $dicval = NULL) {
    $menus = array();
    return $menus;
}, 'actions' => function ($dic, $dicval) {
}, 'hooks' => array('before_all' => function ($dic) {
}, 'before_index' => function ($dic) {
}, 'before_index_view' => function ($dic, $dicvals) {
}, 'before_create_edit' => function ($dic) {
}, 'before_create' => function ($dic) {
}, 'before_edit' => function ($dic, $dicval) {
}, 'before_store_update' => function ($dic) {
}, 'before_store' => function ($dic) {
}, 'after_store' => function ($dic, $dicval) {
}, 'before_update' => function ($dic, $dicval) {
}, 'after_update' => function ($dic, $dicval) {
}, 'before_destroy' => function ($dic, $dicval) {
}, 'after_destroy' => function ($dic, $dicval) {
}), 'seo' => false, 'versions' => 0);
 public function postSave($dic_id, $id = false)
 {
     if (!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, @$id ? 'dicval_edit' : 'dicval_create');
     $element = new DicVal();
     if ($id) {
         $element = DicVal::find($id);
     }
     if (!is_object($element)) {
         $element = new DicVal();
     }
     $this->callHook('before_all', $dic);
     $this->callHook('before_store_update', $dic);
     #Helper::tad($dic);
     $versions = Config::get('dic/' . $dic->slug . '.versions');
     $input = Input::all();
     #dd($input);
     $locales = Input::get('locales');
     $fields = Helper::withdraw($input, 'fields');
     #Input::get('fields');
     #$fields_i18n = Input::get('fields_i18n');
     $fields_i18n = @$input['fields_i18n'];
     #dd($fields_i18n);
     $seo = Input::get('seo');
     /*
     if (!@$input['slug'] && $dic->make_slug_from_name)
         $input['slug'] = Helper::translit($input['name']);
     */
     if (!isset($input['name']) || !mb_strlen($input['name'])) {
         $input['name'] = '';
     }
     $input['name'] = trim($input['name']);
     /**
      * Генерация системного имени в зависимости от настроек словаря
      */
     switch ((int) $dic->make_slug_from_name) {
         case 1:
             $input['slug'] = Helper::translit($input['name']);
             break;
         case 2:
             if (!$dic->hide_slug && !@$input['slug']) {
                 $input['slug'] = Helper::translit($input['name']);
             }
             break;
         case 3:
             if ($dic->hide_slug && $element->slug == '') {
                 $input['slug'] = Helper::translit($input['name']);
             }
             break;
         case 4:
             $input['slug'] = Helper::translit($input['name'], false);
             break;
         case 5:
             if (!$dic->hide_slug && !@$input['slug']) {
                 $input['slug'] = Helper::translit($input['name'], false);
             }
             break;
         case 6:
             if ($dic->hide_slug && $element->slug == '') {
                 $input['slug'] = Helper::translit($input['name'], false);
             }
             break;
         case 7:
             $input['slug'] = $input['name'];
             break;
         case 8:
             if (!$dic->hide_slug && !@$input['slug']) {
                 $input['slug'] = $input['name'];
             }
             break;
         case 9:
             if ($dic->hide_slug && $element->slug == '') {
                 $input['slug'] = $input['name'];
             }
             break;
     }
     if (isset($input['slug'])) {
         $input['slug'] = @Helper::translit($input['slug'], false);
     }
     #Helper::dd($input['slug']);
     #$json_request['responseText'] = "<pre>" . print_r(Input::get('seo'), 1) . "</pre>";
     $json_request['responseText'] = "<pre>" . print_r(Input::all(), 1) . "</pre>";
     #return Response::json($json_request,200);
     #dd(Input::all());
     #Helper::dd(Input::all());
     #Helper::dd($input);
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     $validator = Validator::make($input, array());
     if ($validator->passes()) {
         $redirect = false;
         #Helper::d($id);
         $mode = '';
         if (isset($element) && is_object($element) && $element->id) {
             $mode = 'update';
             $this->callHook('before_update', $dic, $element);
             /**
              * Версионность
              * Если в конфиге задано кол-во хранимых резервных копий > 0
              */
             if ($versions > 0) {
                 $this->create_backup($element->id, true);
             }
             ## UPDATE DICVAL
             $element->update($input);
             $element->touch();
             ## Важно! Для версионности
         } else {
             $mode = 'store';
             $this->callHook('before_store', $dic);
             if (@(!$input['dic_id'])) {
                 $input['dic_id'] = $dic->id;
             }
             #$json_request['responseText'] = "<pre>" . print_r($input, 1) . "</pre>";
             #return Response::json($json_request,200);
             /**
              * Ставим элемент в конец списка
              */
             $temp = DicVal::selectRaw('max(rgt) AS max_rgt')->where('dic_id', $dic->id)->first();
             $input['lft'] = $temp->max_rgt + 1;
             $input['rgt'] = $temp->max_rgt + 2;
             ## CREATE DICVAL
             $element = new DicVal();
             #$element = DicVal::insert($input);
             $element->save();
             $element->update($input);
             $id = $element->id;
             $redirect = true;
         }
         /**
          * Доп. поля, не зависящие от языка
          */
         $element_fields = Config::get('dic/' . $dic->slug . '.fields');
         if (isset($element_fields) && is_callable($element_fields)) {
             $element_fields = $element_fields($element);
         }
         #Helper::dd($element_fields);
         ## FIELDS
         if (isset($element_fields) && is_array($element_fields) && count($element_fields)) {
             #Helper::d($fields);
             foreach ($element_fields as $key => $_value) {
                 if (is_numeric($key) || !@$_value['type']) {
                     continue;
                 }
                 #Helper::dd($key . ' - ' . $_value['type']);
                 $value = @$fields[$key];
                 #Helper::d($key);
                 #Helper::d($value);
                 #continue;
                 ## If handler of field is defined
                 if (is_callable($handler = @$element_fields[$key]['handler'])) {
                     #Helper::d($handler);
                     $value = $handler($value, $element);
                 }
                 #Helper::d($key . ' => ' . print_r($value, 1));
                 if ($value === false) {
                     continue;
                 }
                 $field_model = in_array(@$_value['type'], array('textarea', 'textarea_redactor')) ? new DicTextFieldVal() : new DicFieldVal();
                 $field = $field_model->firstOrNew(array('dicval_id' => $id, 'key' => $key, 'language' => NULL));
                 $field->value = $value;
                 $field->save();
                 unset($field);
             }
         }
         /**
          * Доп. поля, имеющие версии для каждого языка
          */
         $element_fields_i18n = Config::get('dic/' . $dic->slug . '.fields_i18n');
         if (isset($element_fields_i18n) && is_callable($element_fields_i18n)) {
             $element_fields_i18n = $element_fields_i18n($element);
         }
         #Helper::d($element_fields_i18n);
         #Helper::dd($fields_i18n);
         ## FIELDS I18N
         #if (@is_array($fields_i18n) && count($fields_i18n)) {
         if (isset($element_fields_i18n) && is_array($element_fields_i18n) && count($element_fields_i18n) && is_array($fields_i18n) && count($fields_i18n)) {
             #Helper::d('Перебираем все $element_fields_i18n...');
             #Helper::dd($fields_i18n);
             #Helper::dd($element_fields_i18n);
             /**
              * Перебираем все доп. поля из конфига
              */
             foreach ($element_fields_i18n as $field_name => $field_params) {
                 #Helper::d($field_name);
                 #Helper::d($field_params);
                 #Helper::dd($fields_i18n);
                 #continue;
                 /**
                  * Перебираем все локали, и выбираем значение текущего доп. поля для каждого языка
                  */
                 foreach ($fields_i18n as $locale_sign => $values) {
                     #dd($values);
                     #Helper::d($field_name . ' => ' . @$values[$field_name]);
                     #var_dump(@$values[$field_name]);
                     #if (!isset($values[$field_name]))
                     #    continue;
                     $value = @$values[$field_name];
                     #Helper::d($field_name . ' => ' . $value);
                     #Helper::d($field_name);
                     #Helper::d($value);
                     ## If handler of field is defined
                     if (is_callable($handler = @$element_fields_i18n[$field_name]['handler'])) {
                         #Helper::dd($handler);
                         $value = $handler($value, $element);
                     }
                     #Helper::d($field_name . ' => ' . $value);
                     if ($value === false) {
                         continue;
                     }
                     $field_model = in_array(@$field_params['type'], array('textarea', 'textarea_redactor')) ? new DicTextFieldVal() : new DicFieldVal();
                     $field = $field_model->firstOrNew(array('dicval_id' => $id, 'key' => $field_name, 'language' => $locale_sign));
                     $field->value = $value;
                     $field->save();
                     #Helper::ta($field);
                     unset($field);
                 }
             }
         }
         /**
          * DicValMeta
          */
         ## LOCALES
         #Helper::dd($locales);
         if (@is_array($locales) && count($locales)) {
             foreach ($locales as $locale_sign => $array) {
                 $element_meta = DicValMeta::firstOrNew(array('dicval_id' => $id, 'language' => $locale_sign));
                 $element_meta->update($array);
                 $element_meta->save();
                 #Helper::tad($element_meta);
                 unset($element_meta);
             }
         }
         ## SEO
         if (@is_array($seo) && count($seo)) {
             #Helper::ta($element);
             #Helper::d($seo);
             foreach ($seo as $locale_sign => $seo_array) {
                 ## SEO
                 if (is_array($seo_array) && count($seo_array)) {
                     ###############################
                     ## Process SEO
                     ###############################
                     $seo_result = ExtForm::process('seo', array('module' => 'DicVal', 'unit_id' => $element->id, 'data' => $seo_array, 'locale' => $locale_sign));
                     #Helper::tad($seo_result);
                     ###############################
                 }
             }
         }
         $element->load('metas', 'allfields', 'seos');
         $element = $element->extract(1);
         $this->callHook('after_store_update', $dic, $element);
         if ($mode == 'update') {
             $this->callHook('after_update', $dic, $element);
         } elseif ($mode == 'store') {
             $this->callHook('after_store', $dic, $element);
         }
         $this->callHook('after_store_update_destroy', $dic, $element);
         $this->callHook('after_store_update_destroy_order', $dic, $element);
         $json_request['responseText'] = 'Сохранено';
         if ($redirect) {
             $redirect_url = NULL;
             if (@$dic_settings['new_element_redirect'] == 'list') {
                 #$redirect_url = URL::route(is_numeric($dic_id) ? 'dicval.index' : 'entity.index', array('dic_id' => $dic_id)) . (Request::getQueryString() ? '?' . Request::getQueryString() : '');
                 $redirect_url = Input::get('redirect');
             } elseif (@is_array($dic_settings['new_element_redirect']) && isset($dic_settings['new_element_redirect']['route_name'])) {
                 $redirect_url = URL::route($dic_settings['new_element_redirect']['route_name'], (array) @$dic_settings['new_element_redirect']['route_params']) . (@$dic_settings['new_element_redirect']['add_query_string'] && Input::get('query_string') ? Input::get('query_string') : '');
                 #} elseif (@$dic_settings['new_element_redirect'] == 'new' || !@$dic_settings['new_element_redirect']) {
             } else {
                 $redirect_url = URL::route(is_numeric($dic_id) ? 'dicval.edit' : 'entity.edit', array('dic_id' => $dic_id, 'id' => $element->id)) . (Input::get('query_string') ? Input::get('query_string') : '');
             }
         }
         if ($redirect && $redirect_url) {
             $json_request['redirect'] = $redirect_url;
         }
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = $validator->messages()->all();
     }
     return Response::json($json_request, 200);
 }
 public function postSave($id = FALSE)
 {
     Allow::permission($this->module['group'], 'create');
     if (!Request::ajax()) {
         App::abort(404);
     }
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     $input = Input::all();
     #Helper::tad($input);
     $locales = Helper::withdraw($input, 'locales');
     $blocks = Helper::withdraw($input, 'blocks');
     $blocks_new = Helper::withdraw($input, 'blocks_new');
     #$seo = Helper::withdraw($input, 'seo');
     $fields_all = @$input['fields'];
     $element_fields = Config::get('pages.fields');
     $element_fields = is_callable($element_fields) ? $element_fields() : [];
     $input['template'] = @$input['template'] ? $input['template'] : NULL;
     $input['start_page'] = @$input['start_page'] ? 1 : NULL;
     $input['slug'] = @$input['slug'] ? $input['slug'] : ($input['start_page'] ? '' : $input['name']);
     $input['slug'] = $this->getPageSlug($input['slug']);
     $input['parametrized'] = is_int(strpos($input['slug'], '{')) ? 1 : 0;
     $input['sysname'] = @$input['sysname'] ? $input['sysname'] : ($input['start_page'] ? '' : $input['name']);
     $input['sysname'] = Helper::translit($input['sysname']);
     #Helper::tad($input);
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE, 'pageSlug' => $input['slug']);
     $validator = Validator::make($input, $this->essence->rules());
     if ($validator->passes()) {
         $redirect = FALSE;
         if (Allow::action('pages', 'advanced', true, false)) {
             $input['settings']['new_block'] = isset($input['settings']['new_block']) ? 1 : 0;
         }
         ## PAGES
         if ($id != FALSE && $id > 0 && NULL != ($element = $this->essence->find($id))) {
             /**
              * Создаем резервную копию страницы со всеми данными
              */
             $this->create_backup($id);
             if (@$input['settings']) {
                 $input['settings'] = json_encode(array_merge(@(array) json_decode($element['settings']), $input['settings']));
             }
             #$element = $this->essence->find($id);
             $element->update($input);
             ## PAGES_BLOCKS - update
             if (count($blocks)) {
                 foreach ($blocks as $block_id => $block_data) {
                     if (Allow::action('pages', 'advanced', true, false)) {
                         if (isset($block_data['slug'])) {
                             $block_data['slug'] = trim($block_data['slug']) != '' ? $block_data['slug'] : $block_data['name'];
                             $block_data['slug'] = Helper::translit($block_data['slug']);
                         }
                     }
                     #$block_data['settings'] = json_encode($block_data['settings']);
                     $block = $this->pages_blocks->find($block_id);
                     if (is_object($block)) {
                         $block->update($block_data);
                     }
                 }
             }
         } else {
             if (@$input['settings']) {
                 $input['settings'] = json_encode($input['settings']);
             }
             $element = $this->essence->create($input);
             $id = $element->id;
             $redirect = URL::route($this->module['entity'] . '.edit', array('page_id' => $id));
         }
         if (!is_null($element->start_page)) {
             $this->essence->where('start_page', 1)->where('id', '!=', $element->id)->update(array('start_page' => NULL));
         }
         ## PAGES_META
         if (count($locales)) {
             foreach ($locales as $locale_sign => $locale_settings) {
                 $seo = Helper::withdraw($locale_settings, 'seo');
                 $page_meta = $this->pages_meta->where('page_id', $element->id)->where('language', $locale_sign)->first();
                 ## Сохраняем доп. поля
                 ## Сыровато, требует доработки - нужно сделать по аналогии со словарями
                 #Helper::tad($fields_all);
                 $fields = (array) $fields_all[$locale_sign];
                 if (count($fields)) {
                     foreach ($fields as $field_name => $field) {
                         if (is_callable($handler = @$element_fields[$field_name]['handler'])) {
                             #Helper::d($handler);
                             $field = $handler($field, $element);
                             $fields[$field_name] = $field;
                         }
                     }
                 }
                 $settings = is_object($page_meta) ? @json_decode($page_meta->settings, true) : [];
                 $settings['fields'] = $fields;
                 $locale_settings['settings'] = json_encode($settings);
                 $locale_settings['template'] = @$locale_settings['template'] ? $locale_settings['template'] : NULL;
                 if (is_object($page_meta)) {
                     $page_meta->update($locale_settings);
                 } else {
                     $locale_settings['page_id'] = $id;
                     $locale_settings['language'] = $locale_sign;
                     $page_meta = $this->pages_meta->create($locale_settings);
                 }
                 ## PAGES META SEO
                 #if (isset($seo[$locale_sign])) {
                 if (isset($seo)) {
                     ###############################
                     ## Process SEO
                     ###############################
                     $seo_result = ExtForm::process('seo', array('module' => 'Page', 'unit_id' => $element->id, 'locale' => $locale_sign, 'data' => $seo));
                     #Helper::tad($seo_result);
                     ###############################
                 }
             }
         }
         ## PAGES_BLOCKS - create
         if (count($blocks_new)) {
             foreach ($blocks_new as $null => $block_data) {
                 $block_data['page_id'] = $id;
                 if (Allow::action('pages', 'advanced', true, false)) {
                     if (isset($block_data['slug'])) {
                         $block_data['slug'] = trim($block_data['slug']) != '' ? $block_data['slug'] : $block_data['name'];
                         $block_data['slug'] = Helper::translit($block_data['slug']);
                     }
                 }
                 $this->pages_blocks->create($block_data);
             }
         }
         #$json_request['responseText'] = Helper::d($redirect);
         #return Response::json($json_request,200);
         ## Clear & reload pages cache
         Page::drop_cache();
         Page::preload();
         $json_request['responseText'] = 'Сохранено';
         if ($redirect) {
             $json_request['redirect'] = $redirect;
         }
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = $validator->messages()->all();
     }
     return Response::json($json_request, 200);
 }
Exemplo n.º 5
0
 public function update($badge_id)
 {
     $validator = Validator::make(Input::all(), Layout_homes::$rules);
     if ($validator->passes()) {
         $build = Layout_homes::where('id', $badge_id)->first();
         $build->title = Input::get('title');
         $build->contractor_title = Input::get('contractor_title');
         $build->contractor_link = Input::get('contractor_link');
         $build->construction_period = Input::get('construction_period');
         $build->area = Input::get('area');
         $build->material = Input::get('material');
         $build->price = Input::get('price');
         $build->land_id = Input::get('land_id');
         $build->photo_id = (int) Input::get('photo_id');
         $build->save();
         $build->gallery_id = ExtForm::process('gallery', array('module' => 'Готовый дом', 'unit_id' => $build->id, 'gallery' => Input::get('gallery'), 'single' => TRUE));
         $build->save();
         $json_request['responseText'] = "Проект сохранен";
         $json_request['redirect'] = URL::route('layouts_homes.index');
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = implode($validator->messages()->all(), '<br />');
     }
     return Response::json($json_request, 200);
 }
Exemplo n.º 6
0
 public function update($land_id)
 {
     $validator = Validator::make(Input::all(), Land::$rules);
     if ($validator->passes()) {
         $land = Land::where('id', $land_id)->first();
         $land->turn = Input::get('turn');
         $land->status = Input::get('status');
         $land->description = Input::get('description');
         $land->number = Input::get('number');
         $land->area = Input::get('area');
         $land->price = Input::get('price');
         $land->price_house = Input::get('price_house');
         $land->coordinate_x = (int) Input::get('coordinate_x');
         $land->coordinate_y = (int) Input::get('coordinate_y');
         $land->photo_id = (int) Input::get('photo_id');
         $land->sold = Input::has('sold') ? 1 : 0;
         $land->save();
         $land->gallery_id = ExtForm::process('gallery', array('module' => 'Участок', 'unit_id' => $land->id, 'gallery' => Input::get('gallery'), 'single' => TRUE));
         $land->save();
         if (Input::has('recommended_lands')) {
             $land->recommended_lands()->sync(Input::get('recommended_lands'));
         } else {
             $land->recommended_lands()->detach();
         }
         $json_request['responseText'] = "Участок сохранен";
         $json_request['redirect'] = URL::route('land.index');
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = implode($validator->messages()->all(), '<br />');
     }
     return Response::json($json_request, 200);
 }
Exemplo n.º 7
0
 }, 'value_modifier' => function ($value) {
     return $value ? date('d.m.Y', strtotime($value)) : date('d.m.Y');
 }), 'photo' => array('title' => 'Поле для загрузки изображения', 'type' => 'image', 'params' => array('maxFilesize' => 1)), 'gallery' => array('title' => 'Галерея изображений', 'type' => 'gallery', 'params' => array('maxfilesize' => 1), 'handler' => function ($array, $element) {
     return ExtForm::process('gallery', array('module' => 'DicValMeta', 'unit_id' => $element->id, 'gallery' => $array, 'single' => true));
 }), 'link_to_file' => array('title' => 'Поле для загрузки файла', 'type' => 'upload', 'accept' => '*', 'label_class' => 'input-file', 'handler' => function ($value, $element = false) {
     if (@is_object($element) && @is_array($value)) {
         $value['module'] = 'DicVal';
         $value['unit_id'] = $element->id;
     }
     return ExtForm::process('upload', $value);
 }), 'video' => array('title' => 'Поле для вставки EMBED-кода видео + картинка для предпросмотра', 'type' => 'video', 'handler' => function ($value, $element = false) {
     if (@is_object($element) && @is_array($value)) {
         $value['module'] = 'DicVal';
         $value['unit_id'] = $element->id;
     }
     return ExtForm::process('video', $value);
 }), 'product_type_id' => array('title' => 'Выпадающий список для выбора одного значения', 'type' => 'select', 'values' => array('Выберите..') + $lists['product_type'], 'default' => Input::get('filter.fields.product_type') ?: null), 'scope_id' => array('title' => 'Выпадающий список со множественным выбором', 'type' => 'select-multiple', 'values' => $lists['scope'], 'handler' => function ($value, $element) {
     /**
      * Тут нужно проверить работу с новым форматом данных в 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());
Exemplo n.º 8
0
 public function postSave($id = false)
 {
     Allow::permission($this->module['group'], 'create');
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     $input = Input::all();
     $locales = Helper::withdraw($input, 'locales');
     $seo = Helper::withdraw($input, 'seo');
     $input['template'] = @$input['template'] ? $input['template'] : NULL;
     $input['slug'] = @$input['slug'] ? $input['slug'] : @$locales[Config::get('app.locale')]['title'];
     $input['slug'] = Helper::translit($input['slug']);
     $input['published_at'] = @$input['published_at'] ? date('Y-m-d', strtotime($input['published_at'])) : NULL;
     $json_request['responseText'] = "<pre>" . print_r(Input::all(), 1) . "</pre>";
     #$json_request['responseText'] = "<pre>" . print_r($input, 1) . print_r($locales, 1) . print_r($seo, 1) . "</pre>";
     #return Response::json($json_request,200);
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     $validator = Validator::make($input, $this->essence->rules());
     if ($validator->passes()) {
         $redirect = false;
         ## NEWS
         if ($id != false && $id > 0 && $this->essence->find($id)->exists()) {
             $element = $this->essence->find($id);
             $element->update($input);
         } else {
             $element = $this->essence->create($input);
             $id = $element->id;
             $redirect = URL::route($this->module['entity'] . '.edit', array('news_id' => $id));
         }
         ## NEWS_META
         if (count($locales)) {
             foreach ($locales as $locale_sign => $locale_settings) {
                 ## Withdraw gallery_id
                 $gallery_data = Helper::withdraw($locale_settings, 'gallery_id');
                 #$locale_settings['template'] = $locale_settings['template'] ? $locale_settings['template'] : NULL;
                 $news_meta = $this->news_meta->where('news_id', $element->id)->where('language', $locale_sign)->first();
                 if (is_object($news_meta)) {
                     $news_meta->update($locale_settings);
                 } else {
                     $locale_settings['news_id'] = $id;
                     $locale_settings['language'] = $locale_sign;
                     $news_meta = $this->news_meta->create($locale_settings);
                 }
                 ## NEWS_META GALLERY
                 if (isset($gallery_data)) {
                     ###############################
                     ## Process GALLERY
                     ###############################
                     $gallery_id = ExtForm::process('gallery', array('module' => 'news_meta', 'unit_id' => $news_meta->id, 'gallery' => $gallery_data, 'single' => true));
                     ###############################
                     $locale_settings['gallery_id'] = $gallery_id;
                     $news_meta->update($locale_settings);
                 }
                 ## NEWS_META SEO
                 if (isset($seo[$locale_sign])) {
                     ###############################
                     ## Process SEO
                     ###############################
                     $seo_result = ExtForm::process('seo', array('module' => 'news_meta', 'unit_id' => $news_meta->id, 'data' => $seo[$locale_sign]));
                     #Helper::tad($seo_result);
                     ###############################
                 }
             }
         }
         $json_request['responseText'] = 'Сохранено';
         if (@$redirect) {
             $json_request['redirect'] = $redirect;
         }
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = $validator->messages()->all();
     }
     return Response::json($json_request, 200);
 }
Exemplo n.º 9
0
<?php

return array('fields' => function () {
    return array('gallery' => array('title' => 'Галерея изображений', 'type' => 'gallery', 'params' => array('maxfilesize' => 2), 'handler' => function ($array, $element) {
        return ExtForm::process('gallery', array('module' => 'DicValMeta', 'unit_id' => $element->id, 'gallery' => $array, 'single' => true));
    }));
});
Exemplo n.º 10
0
 public function update($badge_id)
 {
     $validator = Validator::make(Input::all(), Buildings::$rules);
     if ($validator->passes()) {
         $build = Buildings::where('id', $badge_id)->first();
         $build->title = Input::get('title');
         $build->description = Input::get('description');
         $build->number = Input::get('number');
         $build->land_area = Input::get('land_area');
         $build->area = Input::get('area');
         $build->material = Input::get('material');
         $build->communication = Input::get('communication');
         $build->price = Input::get('price');
         $build->land_id = Input::get('land_id');
         $build->photo_id = (int) Input::get('photo_id');
         $build->sold = 0;
         $build->save();
         $build->gallery_id = ExtForm::process('gallery', array('module' => 'Готовый дом', 'unit_id' => $build->id, 'gallery' => Input::get('gallery'), 'single' => TRUE));
         $build->save();
         $json_request['responseText'] = "Дом сохранен";
         $json_request['redirect'] = URL::route('buildings.index');
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = implode($validator->messages()->all(), '<br />');
     }
     return Response::json($json_request, 200);
 }