Пример #1
0
 public function actionEdit()
 {
     if ($this->validatePermission('smartslider_edit')) {
         $generatorId = N2Request::getInt('generator_id');
         $generatorModel = new N2SmartsliderGeneratorModel();
         $generator = $generatorModel->get($generatorId);
         if ($this->validateDatabase($generator)) {
             $slidesModel = new N2SmartsliderSlidesModel();
             $slides = $slidesModel->getAll(-1, 'OR generator_id = ' . $generator['id'] . '');
             if (count($slides) > 0) {
                 $slide = $slides[0];
                 if (N2Request::getInt('save')) {
                     $request = new N2Data(N2Request::getVar('generator'));
                     $slideParams = new N2Data($slide['params'], true);
                     $slideParams->set('record-slides', $request->get('record-slides', 1));
                     $slidesModel->updateParams($slide['id'], $slideParams->toArray());
                     $request->un_set('record-slides');
                     $generatorModel->save($generatorId, $request->toArray());
                     N2SmartsliderSlidesModel::markChanged($slide['slider']);
                     N2Message::success(n2_('Generator updated and cache cleared.'));
                     $this->redirect(array("generator/edit", array("generator_id" => $generatorId)), 302, true);
                 }
                 N2Request::set('sliderid', $slide['slider']);
                 $this->addView("../../inline/_sliders", array("appObj" => $this), "sidebar");
                 $this->addView("edit", array("generatorModel" => $generatorModel, "generator" => $generator, "slide" => $slide));
                 $this->render();
             } else {
                 $this->redirect(array("sliders/index"), 302, true);
             }
         } else {
             $this->redirect(array("sliders/index"), 302, true);
         }
     }
 }