Пример #1
0
 public function init()
 {
     parent::init();
     $this->_texts = Data::cache(TextModel::CACHE_KEY, 3600, function () {
         $models = TextModel::find()->where(['status' => TextModel::STATUS_PUBLISHED])->all();
         $return = [];
         foreach ($models as $k => $model) {
             $return[$model->slug . '_' . \Yii::$app->language][$model->id] = $model;
         }
         return $return;
     });
 }
Пример #2
0
 public function setAttributesByPost($postData = array())
 {
     $postData = Yii::app()->getRequest()->getPost($this->_getPostKey());
     if ($postData) {
         $this->items->clear();
         foreach ($postData as $n => $data) {
             $item = $this->createItem();
             $item->setAttributes(DataHelper::trimRecursive($data));
             // Важно сохранить номер, чтобы правильно сработала ajax валидация
             $this->items[$n] = $item;
         }
     }
 }
Пример #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param UserRequest|Request $request
  * @param $id
  * @return \Illuminate\Http\Response
  */
 public function update(UserRequest $request, $id)
 {
     $data = $request->all();
     Data::checkIsSet($data, 'confirm');
     if (Hash::check($data['confirm'], auth()->user()->getAuthPassword())) {
         // todo: flash success
         $user = \App\User::find($id);
         $user->update($data);
         return redirect()->route('admin.user.index');
     }
     dd(auth()->user()->getAuthPassword());
     // todo: flash wrong password
     return redirect()->route('admin.user.edit')->withInput($data);
 }
Пример #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $node_id)
 {
     $data = $request->all();
     $rules = $this->provider->rules($data['module']);
     $validator = Validator::make($data, $rules);
     //TODO
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $data = Data::checkActive($data);
     $data = Data::renameField($data, 'module', 'module_id');
     //        dd($data);
     // Create Module
     $module = $this->provider->store($data);
     $data = Data::addField($data, 'row', $module['id']);
     //Create Element
     $element = \App\Element::create($data);
     $element->save();
     $data = Data::addField($data, 'node_id', $node_id);
     $data = Data::addField($data, 'element_id', $element->id);
     $content = \App\Content::create($data)->save();
     //todo: flash message
     return redirect()->route('admin.element.index', ['node' => $node_id]);
 }
Пример #5
0
 public function setAttribute($name, $value)
 {
     parent::setAttribute(DataHelper::camelToSnake($name), $value);
 }
Пример #6
0
 /**
  * @param string $code
  */
 public static function change($code)
 {
     Data::save('currency', $code);
 }
Пример #7
0
 public function fixCssName($name)
 {
     return strtr(DataHelper::camelToSnake($name), '_', '-');
 }
Пример #8
0
 public function setAttributesByPost($postData = array())
 {
     $postKey = CHtml::modelName($this);
     $postData = $postData ?: $_POST;
     $data = array();
     if (!empty($postData[$postKey])) {
         $data = $postData[$postKey];
     }
     $this->setAttributes(DataHelper::trimRecursive($data));
 }
Пример #9
0
 /**
  * Saves wish list
  */
 public function save()
 {
     Data::save('wish_list', $this);
 }
Пример #10
0
 /**
  * @return Country[]
  */
 public function api_countries()
 {
     return Data::cache($this->makeCacheKey(), function () {
         return Country::find()->all();
     });
 }
Пример #11
0
 /**
  * Saves order address
  */
 public function save()
 {
     Data::save('order_address', $this);
 }
Пример #12
0
 /**
  * Saves cart
  */
 public function save()
 {
     Data::save('shopping_cart', $this);
 }