Ejemplo n.º 1
0
 /**
  * Редактирование материалов
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     $article = ArticleModel::find($id);
     if (empty($article)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Article']));
     }
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         $data = Arr::extract($this->getPostData(), ['slug', 'parentId', 'status', 'content']);
         $parent = ArticleModel::find($data['parentId']);
         // Транзакция для Записание данных в базу
         try {
             Event::fire('Admin.beforeArticleUpdate', $article);
             Capsule::connection()->transaction(function () use($data, $article, $parent) {
                 if ($parent) {
                     $article->makeChildOf($parent);
                 } else {
                     $article->makeRoot();
                 }
                 // Заодно обновляет и пункты меню привязанные к slug-у
                 (new \MenuItemModel())->whereSlug($article->slug)->update(['slug' => $data['slug']]);
                 $article->update(['slug' => $data['slug'], 'status' => $data['status']]);
                 foreach ($data['content'] as $iso => $item) {
                     $lang_id = Lang::instance()->getLang($iso)['id'];
                     if ((int) $item['id'] != 0) {
                         $content = ContentModel::find($item['id']);
                         $content->update(['title' => $item['title'], 'crumb' => $item['crumb'], 'desc' => $item['desc'], 'meta_title' => $item['metaTitle'], 'meta_desc' => $item['metaDesc'], 'meta_keys' => $item['metaKeys'], 'lang_id' => $lang_id]);
                     } else {
                         //todo: надо по тестить почему без ID каждий раз создаётся все записи а не обновляются
                         $content = ContentModel::create(['article_id' => $data['content']['ru']['id'], 'title' => $item['title'], 'crumb' => $item['crumb'], 'desc' => $item['desc'], 'meta_title' => $item['metaTitle'], 'meta_desc' => $item['metaDesc'], 'meta_keys' => $item['metaKeys'], 'lang_id' => $lang_id]);
                         $article->contents()->attach($content);
                     }
                     //                    $article->contents()->attach($content);
                 }
             });
             Event::fire('Admin.articleUpdate', $article);
         } catch (QueryException $e) {
             Message::instance()->warning('Article was don\'t edited');
         }
     }
     // Загрузка контента для каждово языка
     $contents = [];
     foreach (Lang::instance()->getLangs() as $iso => $lang) {
         $contents[$iso] = $article->contents()->where('lang_id', '=', $lang['id'])->first();
     }
     $this->layout->content = View::make('back/articles/edit')->with('node', $article::getNode())->with('article', $article)->with('contents', $contents);
 }
Ejemplo n.º 2
0
 /**
  *  Редактирование язика
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         //Редактирование данных в базе
         $data = Arr::extract($this->getPostData(), ['name', 'iso', 'status']);
         try {
             // Загрузка картинки
             $file = new UploadFile('image', new FileSystem('uploads/images'));
             // Optionally you can rename the file on upload
             $file->setName(uniqid());
             // Validate file upload
             $file->addValidations(array(new UploadMimeType(['image/png', 'image/jpg', 'image/gif']), new UploadSize('50M')));
             // Try to upload file
             try {
                 // Success!
                 $file->upload();
                 $data['flag'] = $file->getNameWithExtension();
             } catch (Exception $e) {
                 // Fail!
                 Message::instance()->warning($file->getErrors());
             }
             // здесь надо использовать QueryBuilder потому-что стадартни update исползует метод Baum-а
             Capsule::table('langs')->whereId($id)->update($data);
             Event::fire('Admin.languageUpdate');
         } catch (QueryException $e) {
             Message::instance()->warning('Language was not editing');
         }
     }
     $item = LangModel::find($id);
     if (empty($item)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Language']));
     }
     // отправка в шаблон
     $this->layout->content = View::make('back/languages/edit')->with('item', $item);
 }
Ejemplo n.º 3
0
 /**
  * Редактирование
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     $model = PlayerModel::find($id);
     $firstNameModel = $model->firstNameModel()->first();
     $lastNameModel = $model->lastNameModel()->first();
     if (empty($model)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Player']));
     }
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         $data = Arr::extract($this->getPostData(), ['slug', 'image', 'country', 'position', 'status', 'number', 'team', 'first_name', 'last_name', 'content']);
         // Транзакция для Записание данных в базу
         try {
             Capsule::connection()->transaction(function () use($data, $model, $firstNameModel, $lastNameModel) {
                 // Загрузка картинки
                 $file = new UploadFile('image', new FileSystem('uploads/images'));
                 // Optionally you can rename the file on upload
                 $file->setName(uniqid());
                 //                    // Validate file upload
                 //                    $file->addValidations(array(
                 //                        // Ensure file is of type image
                 //                        new UploadMimeType(['image/png','image/jpg','image/gif']),
                 //
                 //                        // Ensure file is no larger than 5M (use "B", "K", M", or "G")
                 //                        new UploadSize('50M')
                 //                    ));
                 // Try to upload file
                 try {
                     // Success!
                     $file->upload();
                     $image = '/' . static::IMAGE_PATH . '/' . $file->getNameWithExtension();
                 } catch (UploadException $e) {
                     // Fail!
                     $image = null;
                     Message::instance()->warning($file->getErrors());
                 } catch (Exception $e) {
                     // Fail!
                     $image = null;
                     Message::instance()->warning($file->getErrors());
                 }
                 $firstNameModel->updateOrCreate(['id' => $firstNameModel->id], ['text' => $data['first_name']]);
                 $lastNameModel->updateOrCreate(['id' => $lastNameModel->id], ['text' => $data['last_name']]);
                 foreach ($data['content'] as $iso => $d) {
                     $lang_id = Lang::instance()->getLang($iso)['id'];
                     EntityTranslationModel::updateOrCreate(['id' => $d['first_name_id']], ['text' => $d['first_name'], 'lang_id' => $lang_id, 'entity_id' => $firstNameModel->id]);
                     EntityTranslationModel::updateOrCreate(['id' => $d['last_name_id']], ['text' => $d['last_name'], 'lang_id' => $lang_id, 'entity_id' => $lastNameModel->id]);
                 }
                 Event::fire('Admin.entitiesUpdate');
                 // если нету нового изображения оставить прежний
                 if ($image) {
                     $imageId = PhotoModel::create(['path' => $image, 'is_bound' => 1])->id;
                     $model->update(['image_id' => $imageId]);
                 }
                 $model->update(['team_id' => $data['team'], 'slug' => $data['slug'], 'number' => $data['number'], 'status' => $data['status'], 'country_id' => $data['country'], 'position_id' => $data['position'], 'first_name_id' => $firstNameModel->id, 'last_name_id' => $lastNameModel->id]);
             });
             Message::instance()->success('Player was successfully saved');
         } catch (Exception $e) {
             Message::instance()->warning('Player was don\'t saved');
         }
     }
     $model = PlayerModel::find($id);
     $firstNameModel = $model->firstNameModel()->first();
     $lastNameModel = $model->lastNameModel()->first();
     // Загрузка контента для каждово языка
     $contents = [];
     foreach (Lang::instance()->getLangsExcept(Lang::DEFAULT_LANGUAGE) as $iso => $lang) {
         $contents[$iso]['firstName'] = $firstNameModel->translations()->whereLang_id($lang['id'])->first();
         $contents[$iso]['lastName'] = $lastNameModel->translations()->whereLang_id($lang['id'])->first();
     }
     //echo "<pre>";
     //print_r($contents);
     //die;
     $this->layout->content = View::make('back/players/edit')->with('item', $model)->with('contents', $contents);
 }
Ejemplo n.º 4
0
 /**
  * Редактирование пункта меню
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     $model = MenuItemModel::find($id);
     $entityModel = $model->entities()->first();
     if (empty($model)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Article']));
     }
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         $data = Arr::extract($this->getPostData(), ['slug', 'icon', 'parentId', 'status', 'entity', 'content']);
         $parent = MenuItemModel::find($data['parentId']);
         // Транзакция для Записание данных в базу
         try {
             Capsule::connection()->transaction(function () use($data, $model, $parent, $entityModel) {
                 // Загрузка картинки
                 $file = new UploadFile('image', new FileSystem('uploads/images'));
                 // Optionally you can rename the file on upload
                 $file->setName(uniqid());
                 // Validate file upload
                 $file->addValidations(array(new UploadMimeType(['image/png', 'image/jpg', 'image/gif']), new UploadSize('50M')));
                 // Try to upload file
                 try {
                     // Success!
                     $file->upload();
                     $data['icon'] = $file->getNameWithExtension();
                 } catch (Exception $e) {
                     // Fail!
                     Message::instance()->warning($file->getErrors());
                 }
                 $entityModel->update(['text' => $data['entity']]);
                 foreach ($data['content'] as $iso => $d) {
                     $langId = Lang::instance()->getLang($iso)['id'];
                     EntityTranslationModel::updateOrCreate(['id' => $d['id']], ['text' => $d['text'], 'lang_id' => $langId, 'entity_id' => $entityModel->id]);
                 }
                 Event::fire('Admin.entitiesUpdate');
                 // если нету нового изображения оставить прежний
                 $data['icon'] ?: $model->icon;
                 $model->update(['slug' => $data['slug'], 'status' => $data['status'], 'icon' => $data['icon']]);
                 if ($parent) {
                     $model->makeChildOf($parent);
                 } else {
                     $model->makeRoot($parent);
                 }
             });
             Message::instance()->success('Menu Item was successfully edited');
         } catch (Exception $e) {
             Message::instance()->warning('Menu Item was don\'t edited');
         }
     }
     $model = MenuItemModel::find($id);
     $entityModel = $model->entities()->first();
     // Загрузка контента для каждово языка
     $contents = [];
     foreach (Lang::instance()->getLangsExcept(Lang::DEFAULT_LANGUAGE) as $iso => $lang) {
         $contents[$iso] = $entityModel->translations()->where('lang_id', '=', $lang['id'])->first();
     }
     $this->layout->content = View::make('back/menus/edit')->with('node', $model::getNode())->with('item', $model)->with('contents', $contents);
 }