Example #1
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public static function returnExtFormElements()
 {
     $mod_tpl = static::returnTpl();
     $class = __CLASS__;
     ##
     ## EXTFORM SEO
     ##
     ExtForm::add("seo", function ($name = 'seo', $value = '', $params = null) use($mod_tpl, $class) {
         if (!Allow::action('seo', 'edit', true)) {
             return false;
         }
         ## default template
         $tpl = "extform_seo";
         ## custom template
         if (@$params['tpl']) {
             $tpl = $params['tpl'];
             unset($params['tpl']);
         }
         #$value = $element_meta->seo;
         /*
                         ## Don't work with i18n versions
                         if ( $value === false || $value === null ) {
                             $val = Form::text($name);
                             Helper::dd($val);
                             preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches);
                             Helper::dd($matches);
                             $val = @$matches[1];
                             $array = json_decode($val, true);
                             if ($array)
                                 $value = $array;
                         }
                         #*/
         ## return view with form element
         return View::make($mod_tpl . $tpl, compact('name', 'value', 'params'));
     }, function ($params) use($mod_tpl, $class) {
         #Helper::dd($params);
         $module = isset($params['module']) ? $params['module'] : false;
         $unit_id = isset($params['unit_id']) ? $params['unit_id'] : false;
         $data = isset($params['data']) ? $params['data'] : false;
         $locale = isset($params['locale']) ? $params['locale'] : NULL;
         if (!$module || !$unit_id) {
             return false;
         }
         #Helper::dd($data);
         #$data['module'] = $module;
         #$data['unit_id'] = $unit_id;
         #Helper::dd($data);
         foreach ($data as $d => $dat) {
             if (!is_string($dat)) {
                 continue;
             }
             $data[$d] = trim($dat);
         }
         $seo = Seo::firstOrCreate(array('module' => $module, 'unit_id' => $unit_id, 'language' => $locale));
         $seo->update($data);
         return $seo;
     });
 }
 public static function returnExtFormElements()
 {
     $mod_tpl = static::returnTpl();
     $class = __CLASS__;
     ##
     ## EXTFORM GALLERY
     ##
     /*
     ################################################
     ## Process gallery
     ################################################
     if (Allow::action('admin_galleries', 'edit')) {
         ExtForm::process('gallery', array(
             'module'  => self::$name,
             'unit_id' => $id,
             'gallery' => Input::get('gallery'),
         ));
     }
     ################################################
     */
     ExtForm::add("gallery", function ($name = 'gallery', $value = '', $params = null) use($mod_tpl, $class) {
         ## default template
         $tpl = "extform_gallery";
         ## custom template
         if (@$params['tpl']) {
             $tpl = $params['tpl'];
             unset($params['tpl']);
         }
         #Helper::dd($value);
         #Helper::dd($params);
         if (!is_object($value)) {
             $gallery = NULL;
         }
         if ($value === false || $value === null) {
             $val = Form::text($name);
             preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches);
             #Helper::d($matches);
             $val = (int) @$matches[1];
             #Helper::tad($val);
             if ($val > 0) {
                 $gallery = Gallery::where('id', $val)->with('photos')->first();
                 #Helper::tad($gallery);
             }
         } elseif (is_numeric($value)) {
             $gallery = Gallery::where('id', $value)->with('photos')->first();
         }
         #Helper::tad($gallery);
         ## return view with form element
         return View::make($mod_tpl . $tpl, compact('name', 'value', 'gallery', 'params'))->render();
     }, function ($params) use($mod_tpl, $class) {
         #dd($params);
         $module = isset($params['module']) ? $params['module'] : false;
         $unit_id = isset($params['unit_id']) ? $params['unit_id'] : false;
         $gallery = isset($params['gallery']) ? $params['gallery'] : false;
         $gallery_id = isset($gallery['gallery_id']) ? $gallery['gallery_id'] : 0;
         $uploaded_images = isset($gallery['uploaded_images']) ? $gallery['uploaded_images'] : array();
         $module = (string) trim($module);
         $unit_id = (string) trim($unit_id);
         if (@$params['single']) {
             $gallery_id = $class::moveImagesToGallery($uploaded_images, $gallery_id);
             if ($gallery_id) {
                 $class::renameGallery($gallery_id, $module . " - " . $unit_id);
             }
         } else {
             ## Perform all actions for adding photos to the gallery & bind gallery to the unit_id of module
             $gallery_id = $class::imagesToUnit($uploaded_images, $module, $unit_id, $gallery_id);
         }
         #Helper::dd($gallery_id);
         return $gallery_id;
     });
     ##
     ## EXTFORM IMAGE
     ##
     /*
     ################################################
     ## Process image
     ################################################
     if (Allow::action('admin_galleries', 'edit')) {
         $input['image_id'] = ExtForm::process('image', array(
                                 'image' => Input::get('image'),
                                 'return' => 'id',
                             ));
     }
     ################################################
     */
     ExtForm::add("image", function ($name = 'image', $value = '', $params = null) use($mod_tpl, $class) {
         ## default template
         $tpl = "extform_image";
         ## custom template
         if (@$params['tpl']) {
             $tpl = $params['tpl'];
             unset($params['tpl']);
         }
         #dd($value);
         #Helper::dd($params);
         if (!is_object($value)) {
             $photo = NULL;
         }
         if ($value === false || $value === null) {
             $val = Form::text($name);
             preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches);
             #Helper::d($matches);
             $val = (int) @$matches[1];
             #Helper::tad($val);
             if ($val > 0) {
                 #$photo = Photo::firstOrNew(array('id' => $val));
                 $photo = Photo::find($val);
                 #Helper::tad($photo);
             }
         } elseif (is_numeric($value)) {
             $photo = Photo::find($value);
         }
         #Helper::tad($value);
         #Helper::tad($photo);
         ## return view with form element
         return View::make($mod_tpl . $tpl, compact('name', 'value', 'photo', 'params'));
     }, function ($params) use($mod_tpl, $class) {
         #Helper::dd($params);
         ## Array with POST-data
         $image = @$params['image'] ?: false;
         ## Return format
         $return = @$params['return'] ?: false;
         ## ID of uploaded image
         #$uploaded_image = isset($image['uploaded_image']) ? (int)$image['uploaded_image'] : false;
         $uploaded_image = $image;
         #Helper::dd($uploaded_image);
         if (!$uploaded_image) {
             return false;
         }
         ## Find photo by ID
         $photo = Photo::where('id', $uploaded_image)->first();
         ## If photo don't exists - return false
         if (is_null($photo)) {
             return false;
         }
         ## Mark photo as "single used image"
         $photo->gallery_id = 0;
         $photo->save();
         ## Return needable property or full object
         return $return ? @$photo->{$return} : $photo;
     });
 }
Example #4
0
 public static function formField($name, $array, $value = false, $element = false, $field_name = false)
 {
     if (!@$array || !is_array($array) || !@$name) {
         return false;
     }
     if (isset($array['content'])) {
         return $array['content'];
     }
     #Helper::d($array); return;
     $return = '';
     #$name = $array['name'];
     #if ($name_group != '')
     #    $name = $name_group . '[' . $name . ']';
     #var_dump($value);
     $value = isset($value) ? $value : @$array['default'];
     #echo (int)(isset($value) && $value !== NULL);
     #var_dump($value);
     if (is_object($element) && $element->id) {
         $element = $element->extract();
     }
     /*
     foreach ($element['fields'] as $f => $field) {
         $element['fields'][$field['key']] = $field;
         unset($element['fields'][$f]);
     }
     */
     #Helper::ta($element);
     if (@is_callable($array['value_modifier'])) {
         $value = $array['value_modifier']($value, $element);
     }
     #Helper::d($value);
     $others = array();
     $others_array = array();
     if (@count($array['others'])) {
         foreach ($array['others'] as $o => $other) {
             $others[] = $o . '="' . $other . '"';
             $others_array[$o] = $other;
         }
     }
     $others = ' ' . implode(' ', $others);
     #$others_string = self::arrayToAttributes($others_array);
     #Helper::dd($others_array);
     switch (@$array['type']) {
         case 'text':
             $return = Form::text($name, $value, $others_array);
             break;
         case 'textarea':
             $return = Form::textarea($name, $value, $others_array);
             break;
         case 'textarea_redactor':
             $others_array['class'] = trim(@$others_array['class'] . ' redactor redactor_150');
             $return = Form::textarea($name, $value, $others_array);
             break;
         case 'image':
             $return = ExtForm::image($name, $value, @$array['params']);
             break;
         case 'gallery':
             $return = ExtForm::gallery($name, $value, @$array['params']);
             break;
         case 'date':
             $others_array['class'] = trim(@$others_array['class'] . ' datepicker');
             $return = Form::text($name, $value, $others_array);
             break;
         case 'upload':
             $others_array['class'] = trim(@$others_array['class'] . ' file_upload');
             #Helper::dd($others_array);
             $return = ExtForm::upload($name, $value, $others_array);
             break;
         case 'video':
             $return = ExtForm::video($name, $value, $others_array);
             break;
         case 'select':
             #Helper::d($array);
             #Helper::dd($value);
             $values = $array['values'];
             $return = Form::select($name, $values, $value, $others_array);
             break;
         case 'select-multiple':
             $values = $array['values'];
             $others_array['class'] = trim(@$others_array['class'] . ' select-multiple select2');
             $others_array['multiple'] = 'multiple';
             $return = Form::select($name . '[]', $values, $value, $others_array);
             break;
         case 'checkbox':
             #Helper::d($name);
             #Helper::d($others_array);
             #Helper::d($array['title']);
             #Helper::d($array);
             #var_dump($value);
             #return;
             #Helper::d($array);
             #Helper::ta($element);
             $v = $value;
             #$v = @$element->{$field_name};
             return '<label class="checkbox">' . Form::checkbox($name, 1, $v, $others_array) . '<i></i>' . '<span>' . $array['title'] . '</span>' . '</label>';
             break;
         case 'checkboxes':
             $return = '';
             $style = '';
             $col_num = 12;
             if ($array['columns'] == 2) {
                 $style = ' col col-6';
             } elseif ($array['columns'] == 3) {
                 $style = ' col col-4';
             }
             foreach ($array['values'] as $key => $val) {
                 $checked = is_array($value) && isset($value[$key]);
                 $el = '<label class="checkbox' . $style . '">' . "\n" . Form::checkbox($name . '[]', $key, $checked, $others_array) . "\n" . '<i></i>' . "\n" . '<span>' . $val . '</span>' . "\n" . '</label>' . "\n\n";
                 $return .= $el;
             }
             $return = '<div class="clearfix">' . $return . '</div>';
             #Helper::d(htmlspecialchars($return));
             break;
         case 'hidden':
             $return = Form::hidden($name, $value, $others_array);
             break;
         case 'textline':
             if (!$value) {
                 if (@$array['default']) {
                     $return = $array['default'] . Form::hidden($name, $value);
                 } else {
                     $return = Form::text($name, null, $others_array);
                 }
             } else {
                 $return = (isset($array['view_text']) ? $array['view_text'] : $value) . Form::hidden($name, $value);
             }
             break;
         case 'custom':
             $return = @$array['content'];
             break;
     }
     return $return;
 }
 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));
 }
 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);
 }
Example #7
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 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);
 }
 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);
 }
Example #10
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);
 }
Example #11
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());
Example #12
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);
 }
Example #13
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));
    }));
});
 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);
 }