Beispiel #1
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $galleryId = Param::post('gallery-id')->asInteger(true, 'Недопустимое значние номера галереи.');
     $galleryItemId = Param::post('gallery-item-edit-id', false)->asInteger(false);
     $name = Param::post('gallery-item-edit-name')->noEmpty('Поле "Название" должно быть заполнено.')->asString();
     $description = Param::post('gallery-item-edit-description')->asString();
     $path = Param::post('gallery-item-edit-path')->noEmpty('Недопустимое значение пути к изображению.')->asString();
     $position = Param::post('gallery-item-edit-position')->noEmpty('Недопустимое значение позиции элемента.')->asInteger();
     /** @var Gallery $oGallery */
     $oGallery = DataSource::factory(Gallery::cls(), $galleryId);
     if ($oGallery->isNew()) {
         SCMSNotificationLog::instance()->pushError("Попытка добавить элемент в несуществующую галерею.");
     }
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         /** @var GalleryItem $oGalleryItem */
         $oGalleryItem = DataSource::factory(GalleryItem::cls(), $galleryItemId == 0 ? null : $galleryItemId);
         $oGalleryItem->name = $name;
         $oGalleryItem->description = $description;
         $oGalleryItem->path = $path;
         $oGalleryItem->gallery_id = $oGallery->id;
         $oGalleryItem->position = $position;
         $oGalleryItem->commit();
         SCMSNotificationLog::instance()->pushMessage("Элемент \"{$oGalleryItem->name}\" успешно " . ($galleryItemId == 0 ? "добавлен в галерею \"{$oGalleryItem->getGallery()->name}\"" : 'отредактирован') . '.');
         $redirect = '';
         if (Param::post('gallery-item-edit-accept', false)->exists()) {
             $redirect = "/admin/modules/gallery/item/?gallery_id={$oGalleryItem->gallery_id}";
         } elseif ($galleryItemId == 0) {
             $redirect = "/admin/modules/gallery/item/edit/?id={$oGalleryItem->getPrimaryKey()}";
         }
         $this->Response->send($redirect);
     } else {
         $this->Response->send();
     }
 }
Beispiel #2
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $galleryItemId = Param::get('id', false)->asInteger(false);
     $galleryId = Param::get('gallery_id')->asInteger(true, 'Недопустимое значение номера галереи.');
     /** @var GalleryItem $oGalleryItem */
     $oGalleryItem = DataSource::factory(GalleryItem::cls(), $galleryItemId);
     /** @var Gallery $oGallery */
     $oGallery = DataSource::factory(Gallery::cls(), $galleryId);
     if ($oGalleryItem->isNew() && $oGallery->isNew()) {
         SCMSNotificationLog::instance()->pushError('Недопустимое значение параметра!');
         $this->Frame->render();
         return;
     }
     $view = new ViewEditForm();
     $view->GalleryItem = $oGalleryItem;
     $view->Gallery = $oGallery;
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Галереи', '/modules/gallery'), new Breadcrumb("Галерея \"{$oGallery->name}\"", "/item/?gallery_id={$oGallery->id}")];
     if ($oGalleryItem->id !== null) {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oGalleryItem->name}\"", '');
     } else {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb('Добавление нового элемента галереи', '');
     }
     $view->backUrl = CoreFunctions::buildUrlByBreadcrumbs($viewBreadcrumbs->Breadcrumbs, 1);
     $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs);
     $this->Frame->bindView('content', $view);
     $this->Frame->render();
 }
Beispiel #3
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $galleryItemId = Param::get('id')->noEmpty('Не задан обязательный параметр.')->asInteger(true, 'Параметр должен быть числом.');
     /** @var GalleryItem $oGalleryItem */
     $oGalleryItem = DataSource::factory(GalleryItem::cls(), $galleryItemId);
     if (is_null($oGalleryItem) || !$oGalleryItem->getPrimaryKey()) {
         SCMSNotificationLog::instance()->pushError('Элемент галереи не найден.');
     } else {
         SCMSNotificationLog::instance()->pushMessage("Элемент \"{$oGalleryItem->name}\" галереи {$oGalleryItem->getGallery()->name} успешно удален.");
         $oGalleryItem->delete();
     }
     $this->Response->send();
 }
Beispiel #4
0
 public function getGalleryItems($orderFieldName = 'id', $order = 'asc')
 {
     /** @var GalleryItem[] $aGalleryItems */
     $aGalleryItems = $this->findRelationCache($this->getPrimaryKeyName(), GalleryItem::cls());
     if (empty($aGalleryItems)) {
         /** @var GalleryItem $oGalleryItems */
         $oGalleryItems = DataSource::factory(GalleryItem::cls());
         $oGalleryItems->builder()->where("gallery_id={$this->getPrimaryKey()}")->order($orderFieldName, $order);
         $aGalleryItems = $oGalleryItems->findAll();
         foreach ($aGalleryItems as $oGalleryItem) {
             $this->addRelationCache($this->getPrimaryKeyName(), $oGalleryItem);
             $oGalleryItem->addRelationCache('gallery_id', $this);
         }
     }
     return $aGalleryItems;
 }