Esempio n. 1
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();
 }
Esempio n. 2
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX()) {
         if (!$this->EmployeeAuthentication->authenticated()) {
             SCMSNotificationLog::instance()->pushError('Нет доступа.');
             $this->Response->send();
             return;
         }
     } else {
         $this->needAuthenticate();
     }
     $siteuserId = Param::get('id')->noEmpty('Параметр обязателен для заполнения.')->asInteger(true, "Неверно задан параметр.");
     /** @var Siteuser $oSiteuser */
     $oSiteuser = DataSource::factory(Siteuser::cls(), $siteuserId);
     if ($oSiteuser->id) {
         $oSiteuser->deleted = true;
         try {
             $oSiteuser->commit();
             SCMSNotificationLog::instance()->pushMessage("Пользователь \"{$oSiteuser->name}\" успешно удалён.");
         } catch (Exception $e) {
             SCMSNotificationLog::instance()->pushError($e->getMessage());
         }
     } else {
         SCMSNotificationLog::instance()->pushError("Пользователь с ID {$siteuserId} не найден");
     }
     $this->Response->send();
 }
Esempio n. 3
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $isCategory = Param::get('is_category')->asInteger(true, "Недопустимое значение параметра.");
     $id = Param::get('id', false)->asInteger(false);
     $parentId = Param::get('parent_pk', false)->asInteger(false);
     /** @var Category $oCategories */
     $oCategories = DataSource::factory(Category::cls());
     $oCategories->builder()->where('deleted=0');
     /** @var Category[] $aCategories */
     $aCategories = $oCategories->findAll();
     if ($isCategory == 1) {
         $viewCatalogueEdit = new ViewCategoryEdit();
         /** @var Category $oCategory */
         $oCategory = DataSource::factory(Category::cls(), $id);
         $viewCatalogueEdit->oCategory = $oCategory;
         $viewCatalogueEdit->aCategories = $aCategories;
         $viewCatalogueEdit->parentId = $oCategory->isNew() ? $parentId : $oCategory->category_id;
     } else {
         $viewCatalogueEdit = new ViewItemEdit();
         /** @var Item $oItem */
         $oItem = DataSource::factory(Item::cls(), $id);
         $viewCatalogueEdit->oItem = $oItem;
         $viewCatalogueEdit->aCategories = $aCategories;
         $viewCatalogueEdit->parentId = $oItem->isNew() ? $parentId : $oItem->category_id;
     }
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Каталог', '/modules/catalogue')];
     if ($parentId) {
         $breadcrumbsParentPK = $parentId;
     } elseif ($isCategory == 1 && isset($oCategory)) {
         $breadcrumbsParentPK = $oCategory->category_id;
     } elseif (!$isCategory && isset($oItem)) {
         $breadcrumbsParentPK = $oItem->category_id;
     } else {
         $breadcrumbsParentPK = 0;
     }
     $catalogueEditBreadcrumbs = [];
     while ($breadcrumbsParentPK) {
         /** @var Category $oParentCategory */
         $oParentCategory = DataSource::factory(Category::cls(), $breadcrumbsParentPK);
         $catalogueEditBreadcrumbs[] = new Breadcrumb($oParentCategory->name, "?parent_pk={$oParentCategory->getPrimaryKey()}", true);
         $breadcrumbsParentPK = $oParentCategory->category_id;
     }
     $viewBreadcrumbs->Breadcrumbs = array_merge($viewBreadcrumbs->Breadcrumbs, array_reverse($catalogueEditBreadcrumbs));
     if ($id && isset($oCategory)) {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oCategory->name}\"", '');
     } elseif ($id && isset($oItem)) {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oItem->name}\"", '');
     } else {
         $lastBreadcrumb = 'Добавление новой ' . ($isCategory == 1 ? 'категории' : 'позиции');
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb($lastBreadcrumb, '');
     }
     $viewCatalogueEdit->backUrl = CoreFunctions::buildUrlByBreadcrumbs($viewBreadcrumbs->Breadcrumbs, 1);
     $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs);
     $this->Frame->bindView('content', $viewCatalogueEdit);
     $this->Frame->render();
 }
Esempio n. 4
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX()) {
         $this->executeModule($this->getStructure());
     } else {
         ob_start();
         $this->executeModule($this->getStructure());
         $content = ob_get_contents();
         ob_end_clean();
         $frame = $this->getActiveFrame($this->getStructure());
         $frame->bindData('content', $content);
         $frame->render();
     }
 }
Esempio n. 5
0
 public function actionItem()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $categoryId = Param::post('catalogue-item-id', false)->asInteger(false);
     $name = Param::post('catalogue-item-name')->noEmpty('Заполните поле "Наименование"')->asString();
     $description = Param::post('catalogue-item-description')->asString();
     $parentCategoryId = Param::post('catalogue-item-parent_id')->asInteger(true, 'Поле "Родительская категория" заполнено неверно.');
     $price = Param::post('catalogue-item-price', true)->asNumber(true, "Поле \"Цена\" заполнено неверно.");
     $count = Param::post('catalogue-item-count', true)->asInteger(true, "Поле \"Количество\" заполнено неверно.");
     $thumbnail = Param::post('catalogue-item-thumbnail', false)->asString();
     $priority = Param::post('catalogue-item-priority', false)->asString();
     $active = (int) Param::post('catalogue-item-active', false)->exists();
     $accept = Param::post('catalogue-item-accept', false);
     if (CoreFunctions::isAJAX() && SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     /** @var Item $oItem */
     $oItem = DataSource::factory(Item::cls(), $categoryId == 0 ? null : $categoryId);
     $oItem->name = $name;
     $oItem->description = $description;
     $oItem->category_id = $parentCategoryId;
     $oItem->price = $price;
     $oItem->count = $count;
     $oItem->thumbnail = $thumbnail;
     $oItem->priority = $priority;
     $oItem->active = $active;
     if ($oItem->isNew()) {
         $oItem->deleted = false;
     }
     $oItem->commit();
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Позиция \"{$oItem->name}\" успешно " . ($categoryId == 0 ? 'добавлена' : 'отредактирована') . ".");
     }
     $redirect = "/admin/modules/catalogue/edit/?id={$oItem->getPrimaryKey()}";
     if ($accept->exists()) {
         $redirect = '/admin/modules/catalogue/' . ($oItem->category_id == 0 ? '' : "?parent_pk={$oItem->category_id}");
     } elseif ($categoryId != 0) {
         $redirect = '';
     }
     $this->Response->send($redirect);
 }
Esempio n. 6
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $frame = $this->Frame;
     $frame->addCss('/public/assets/js/bower_components/markitup/markitup/skins/markitup/style.css');
     $frame->addCss('/public/assets/js/bower_components/markitup/markitup/sets/default/style.css');
     $frameName = Param::get('name', false)->asString(false);
     $view = new ViewEditForm();
     $view->frameName = $frameName;
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Фреймы', '/modules/frames'), new Breadcrumb($frameName ? "Редактирование фрейма \"{$frameName}\"" : 'Создание нового фрейма', '')];
     $view->backUrl = CoreFunctions::buildUrlByBreadcrumbs($viewBreadcrumbs->Breadcrumbs, 1);
     $frame->bindView('breadcrumbs', $viewBreadcrumbs);
     $frame->bindView('content', $view);
     $frame->render();
 }
Esempio n. 7
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $frameName = Param::get('name', true)->asString(true, 'Недопустимое имя фрейма!');
     $FrameFile = new File(SFW_MODULES_FRAMES . $frameName);
     if (!$FrameFile->exists()) {
         SCMSNotificationLog::instance()->pushError("Фрейм с именем \"{$frameName}\" не найден!");
     }
     if (SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     $oStructures = DataSource::factory(Structure::cls());
     $oStructures->builder()->where('deleted=0')->whereAnd()->where("frame='{$frameName}'");
     /** @var Structure[] $aStructures */
     $aStructures = $oStructures->findAll();
     if (sizeof($aStructures) > 0) {
         $structureNames = [];
         foreach ($aStructures as $oStructure) {
             $structureNames[] = $oStructure->name;
         }
         SCMSNotificationLog::instance()->pushError("Фрейм \"{$frameName}\" нельзя удалять, пока он используется в структуре сайта. На данный момент фрейм назначен разделам: \"" . implode('", "', $structureNames) . '"');
     }
     if (SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     try {
         $FrameFile->delete();
     } catch (Exception $e) {
         SCMSNotificationLog::instance()->pushError('При удалении фрейма произошла ошибка.');
     }
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Фрейм \"{$frameName}\" успешно удалён.");
     }
     $this->Response->send();
 }
Esempio n. 8
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $siteuserId = Param::get('id', false)->asInteger(false);
     /** @var Siteuser $oSiteuser */
     $oSiteuser = is_null($siteuserId) ? null : DataSource::factory(Siteuser::cls(), $siteuserId);
     $view = new ViewSiteuserEditForm();
     $view->oSiteuser = $oSiteuser;
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Пользователи', '/modules/siteusers')];
     if ($oSiteuser !== null) {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oSiteuser->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();
 }
Esempio n. 9
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $galleryId = Param::get('id', false)->asInteger(false);
     /** @var Gallery $oGallery */
     $oGallery = DataSource::factory(Gallery::cls(), $galleryId);
     $view = new ViewEditForm();
     $view->gallery = $oGallery;
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Галереи', '/modules/gallery')];
     if ($oGallery->id !== null) {
         $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oGallery->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();
 }
Esempio n. 10
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $frameName = Param::post('frame-name')->asString();
     $frameContent = Param::post('frame-content')->asString();
     $FrameFile = new File(SFW_MODULES_FRAMES . $frameName);
     $isNew = !$FrameFile->exists();
     $FrameFile->setContent($frameContent);
     if (Param::post('frame-accept', false)->exists()) {
         $redirect = '/admin/modules/frames/';
     } else {
         $redirect = $isNew ? "/admin/modules/frames/edit/?name={$frameName}" : '';
     }
     SCMSNotificationLog::instance()->pushMessage("Фрейм \"{$frameName}\" успешно " . ($isNew ? 'создан' : 'отредактирован') . '!');
     $this->Response->send($redirect);
 }
Esempio n. 11
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $isCategory = Param::get('is_category')->asInteger(true, "Недопустимое значение параметра.");
     $id = Param::get('id')->asInteger();
     if ($isCategory) {
         /** @var Category $oCategory */
         $oCategory = DataSource::factory(Category::cls(), $id);
         $this->categoryDeepDelete($oCategory);
         SCMSNotificationLog::instance()->pushMessage("Категория \"{$oCategory->name}\" успешно удалена.");
     } else {
         /** @var Item $oItem */
         $oItem = DataSource::factory(Item::cls(), $id);
         $oItem->deleted = true;
         $oItem->commit();
         SCMSNotificationLog::instance()->pushMessage("Позиция \"{$oItem->name}\" успешно удалена.");
     }
     $this->Response->send();
 }
Esempio n. 12
0
    public function currentRender()
    {
        $pagerView = new ViewPagination();
        $pagerView->formName = $this->dataGrid->getName();
        $menuView = new ViewMenu();
        $this->dataGrid->preparePager();
        $this->dataGrid->fillPager($pagerView);
        $menuView->menu = $this->dataGrid->getMenu();
        $menuView->render();
        ?>
        <hr/>
        <div class="table-responsive">
            <form action="<?php 
        echo $this->dataGrid->getAction();
        ?>
" class="form-inline s-datagrid" name="<?php 
        echo $this->dataGrid->getName();
        ?>
" id="<?php 
        echo $this->dataGrid->getName();
        ?>
">
                <fieldset>
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <?php 
        if ($this->dataGrid->hasGroupActions()) {
            ?>
                                <th style="width: 30px;">
                                    <span class="glyphicon glyphicon-check"></span>
                                </th>
                            <?php 
        }
        ?>
                            <?php 
        foreach ($this->dataGrid->getHeaders() as $header) {
            ?>
                                <th <?php 
            echo $header->buildAttributes();
            ?>
>
                                    <?php 
            echo $header->getDisplayName();
            ?>
                                </th>
                            <?php 
        }
        ?>
                            <?php 
        if (sizeof($this->dataGrid->getActions()) > 0) {
            ?>
                            <th class="text-center">
                                <span class="glyphicon glyphicon-menu-hamburger" title="Действия"></span>
                            </th>
                            <?php 
        }
        ?>
                        </tr>
                        <?php 
        if ($this->dataGrid->hasFiltered()) {
            ?>
                            <tr class="warning top">
                                <?php 
            if ($this->dataGrid->hasGroupActions()) {
                ?>
                                    <th></th>
                                <?php 
            }
            ?>
                                <?php 
            foreach ($this->dataGrid->getHeaders() as $header) {
                ?>
                                    <th>
                                        <?php 
                if ($header->isFiltered()) {
                    ?>
                                        <input class="form-control input-sm" style="width: 100%;" name="<?php 
                    echo $this->dataGrid->getName();
                    ?>
-filter-<?php 
                    echo $header->getKey();
                    ?>
" id="<?php 
                    echo $this->dataGrid->getName();
                    ?>
-filter-<?php 
                    echo $header->getKey();
                    ?>
" type="text" placeholder="" value="<?php 
                    echo $header->getFilterValue();
                    ?>
">
                                        <?php 
                }
                ?>
                                    </th>
                                <?php 
            }
            ?>
                                <th style="width: 40px;">
                                    <button name="<?php 
            echo $this->dataGrid->getName();
            ?>
-filter" type="submit" class="btn btn-info btn-sm" formmethod="get" title="Фильтровать"><span class="glyphicon glyphicon-filter"></span></button>
                                </th>
                            </tr>
                        <?php 
        }
        ?>
                        </thead>
                        <tbody>
                        <?php 
        foreach ($this->dataGrid->getData() as $row) {
            ?>
                            <tr>
                                <?php 
            if ($this->dataGrid->hasGroupActions()) {
                ?>
                                    <th>
                                        <input name="<?php 
                echo $this->dataGrid->getName();
                ?>
-checked-row-flag-<?php 
                echo $row[$this->dataGrid->getKey()];
                ?>
" type="checkbox" />
                                    </th>
                                <?php 
            }
            ?>
                                <?php 
            foreach ($this->dataGrid->getHeaders() as $header) {
                ?>
                                    <td<?php 
                echo ' ' . $header->buildValueAttributes();
                ?>
><?php 
                echo $header->decorate($row[$header->getKey()], $row);
                ?>
</td>
                                <?php 
            }
            ?>
                                <td>
                                    <?php 
            foreach ($this->dataGrid->getActions() as $action) {
                ?>
                                        <?php 
                $actionURI = $action->getURI();
                foreach ($action->getAdditionalParameters() as $additionalParameter) {
                    $actionURI = CoreFunctions::addGETParamToURI($actionURI, $additionalParameter, $row[$additionalParameter]);
                }
                $actionURI = CoreFunctions::addGETParamToURI($actionURI, $action->getParamName(), $row[$this->dataGrid->getKey()]);
                ?>
                                        <a name="<?php 
                echo $this->dataGrid->getName();
                ?>
-action-<?php 
                echo $action->getName();
                ?>
-<?php 
                echo $this->dataGrid->getKey();
                ?>
" href="<?php 
                echo $actionURI;
                ?>
"><span <?php 
                echo $action->buildAttributes();
                ?>
 title="<?php 
                echo $action->getTitle();
                ?>
"><?php 
                echo $action->getDisplayName();
                ?>
</span></a>
                                    <?php 
            }
            ?>
                                </td>
                            </tr>
                        <?php 
        }
        ?>
                        </tbody>
                        <tfoot>
                        <?php 
        if ($this->dataGrid->hasGroupActions()) {
            ?>
                        <tr>
                            <td>
                                <input type="checkbox" id="<?php 
            echo $this->dataGrid->getName();
            ?>
-group-action-all-check" name="<?php 
            echo $this->dataGrid->getName();
            ?>
-group-action-all-check""/>
                            </td>
                            <td colspan="<?php 
            echo count($this->dataGrid->getHeaders()) + 1;
            ?>
">
                                Групповые операции:&nbsp;
                                <?php 
            foreach ($this->dataGrid->getGroupActions() as $action) {
                ?>
                                    <button name="<?php 
                echo $this->dataGrid->getName();
                ?>
-action-group-<?php 
                echo $action->getName();
                ?>
" id="<?php 
                echo $this->dataGrid->getName();
                ?>
-group-action-<?php 
                echo $action->getName();
                ?>
" formmethod="post" type="submit" formaction="<?php 
                echo $action->buildGroupURI();
                ?>
" title="<?php 
                echo $action->getTitle();
                ?>
">
                                        <span <?php 
                echo $action->buildAttributes();
                ?>
><?php 
                echo $action->getDisplayName();
                ?>
</span>
                                    </button>
                                <?php 
            }
            ?>
                            </td>
                        </tr>
                        <?php 
        }
        ?>
                        <tr>
                            <td colspan="<?php 
        echo count($this->dataGrid->getHeaders()) + ($this->dataGrid->hasGroupActions() ? 2 : 1);
        ?>
" class="text-left">
                                <div class="form-group">
                                    <select name="<?php 
        echo $this->dataGrid->getName();
        ?>
-items-per-page" id="<?php 
        echo $this->dataGrid->getName();
        ?>
-items-per-page" class="form-control input-sm" style="width: 80px;">
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 5 ? ' selected="selected"' : '';
        ?>
>5</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 10 ? ' selected="selected"' : '';
        ?>
>10</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 20 ? ' selected="selected"' : '';
        ?>
>20</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 50 ? ' selected="selected"' : '';
        ?>
>50</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 100 ? ' selected="selected"' : '';
        ?>
>100</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 500 ? ' selected="selected"' : '';
        ?>
>500</option>
                                        <option<?php 
        echo $this->dataGrid->getItemsPerPage() == 1000 ? ' selected="selected"' : '';
        ?>
>1000</option>
                                    </select>
                                    <button name="<?php 
        echo $this->dataGrid->getName();
        ?>
-set-items-per-page-button" type="submit" class="btn btn-info btn-sm" title="Отобразить" formmethod="get"><span class="glyphicon glyphicon-ok"></span></button>
                                </div>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </fieldset>
                <?php 
        foreach ($this->dataGrid->getHiddenFields() as $name => $value) {
            ?>
                    <input type="hidden" name="<?php 
            echo $name;
            ?>
" value="<?php 
            echo $value;
            ?>
"/>
                <?php 
        }
        ?>
            </form>
        </div>
        <?php 
        $pagerView->render();
    }
Esempio n. 13
0
    public function actionIndex()
    {
        $action = Param::request('action', false)->asString(false);
        $categoryId = 0;
        switch ($action) {
            case 'show-item':
                $itemId = Param::get('item_id', false)->asInteger(false);
                /** @var Item $oItem */
                $oItem = DataSource::factory(Item::cls(), $itemId);
                $view = new ViewItem();
                if (!$oItem->isNew()) {
                    $categoryId = $oItem->category_id;
                    $view->oItem = $oItem;
                } else {
                    SCMSNotificationLog::instance()->pushError("Товар не найден.");
                }
                break;
            case 'add-to-cart':
                $id = Param::get('id', true)->noEmpty('Товар не найден.')->asInteger(true, 'Неизвестный товар.');
                $count = Param::get('count', true)->noEmpty('Количество должно быть указано.')->asInteger(true, 'Не указано количество товара.');
                /** @var Item $oItem */
                $oItem = DataSource::factory(Item::cls(), $id);
                if (!$oItem) {
                    SCMSNotificationLog::instance()->pushError('Товар, который Вы пытаетесь добавить в корзину не существует.');
                }
                if (!$count) {
                    SCMSNotificationLog::instance()->pushError('Количество товара должно быть больше нуля.');
                }
                if (SCMSNotificationLog::instance()->hasProblems()) {
                    $this->Response->send();
                    return;
                }
                $this->cart->addItem($id, $count);
                SCMSNotificationLog::instance()->pushMessage("Товар \"{$oItem->name}\" в количестве {$count} (шт.) успешно добавлен в корзину. Теперь Вы можете перейти к оформлению заказа или продолжить покупки.");
                $this->Response->send('', ['totalCount' => $this->cart->getTotalCount()]);
                return;
                break;
            case 'show-cart':
                $view = new ViewCart();
                $cart = $this->cart;
                $DataGrid = new DataGrid();
                $aItemsInCart = $this->cart->getItems();
                $DataGrid->setCaption(empty($aItemsInCart) ? 'В Вашей корзине ещё нет ни одного товара' : 'Список товаров')->setAttributes(['class' => 'table table-condensed'])->addColumn((new Column())->setDisplayName('№')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->switchOnCounter())->addColumn((new Column())->setDisplayName('Наименование')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setValueName('name'))->addColumn((new Column())->setDisplayName('Цена')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-success'])->setCallback(function (Item $oItem) {
                    echo $oItem->price, '<span class="glyphicon glyphicon-ruble"></span>';
                })->setFooterCallback(function (array $aItems) {
                    ?>
Итого:<?php 
                }))->addColumn((new Column())->setDisplayName('Количество')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-danger'])->setCallback(function (Item $oItem) use($cart) {
                    ?>
<input type="number" min="1" class="form-control input-sm text-center catalogue-item-count" value="<?php 
                    echo $cart->getCountById($oItem->getPrimaryKey());
                    ?>
" /><?php 
                })->setFooterCallback(function (array $aItems) use($cart) {
                    echo $cart->getTotalCount();
                }))->addColumn((new Column())->setDisplayName('Сумма')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-danger'])->setCallback(function (Item $oItem) use($cart) {
                    echo $cart->getCountById($oItem->getPrimaryKey()) * $oItem->price, '<span class="glyphicon glyphicon-ruble"></span>';
                })->setFooterCallback(function (array $aItems) use($cart) {
                    /** @var Item[] $aItems */
                    $totalPrice = 0;
                    foreach ($aItems as $oItem) {
                        $totalPrice += $cart->getCountById($oItem->getPrimaryKey()) * $oItem->price;
                    }
                    echo $totalPrice, '<span class="glyphicon glyphicon-ruble"></span>';
                }))->addColumn((new Column())->setDisplayName('<span class="glyphicon glyphicon-option-horizontal"></span>')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setCallback(function (Item $oItem) {
                    echo '<a href="/catalogue?action=remove-from-cart?id=' . $oItem->getPrimaryKey() . '" class="btn btn-danger btn-xs catalogue-cart-remove" title="Удалить товар из конзины"><span class="glyphicon glyphicon-remove"></span></a>';
                }))->setDataSet($aItemsInCart);
                $view->DataGrid = $DataGrid;
                $view->goodCount = $cart->getTotalCount();
                $view->render();
                return;
                break;
            case 'set-cart-items':
                $items = Param::get('items')->asArray();
                foreach ($items as $itemId => $count) {
                    $this->cart->setItemCount($itemId, $count);
                }
                $this->Response->send('', ['totalCount' => $this->cart->getTotalCount()]);
                return;
                break;
            case 'order':
                break;
            default:
                $categoryId = Param::get('category_id', false)->asInteger(false);
                if (!$categoryId) {
                    $categoryId = 0;
                }
                $oCategories = DataSource::factory(Category::cls());
                $oCategories->builder()->where('deleted=0')->whereAnd()->where('active=1')->whereAnd()->where("category_id={$categoryId}");
                $aCategories = $oCategories->findAll();
                $oItems = DataSource::factory(Item::cls());
                $oItems->builder()->where('deleted=0')->whereAnd()->where('active=1')->whereAnd()->where("category_id={$categoryId}");
                $aItems = $oItems->findAll();
                $view = new ViewCatalogue();
                $view->categoriesPerRow = 4;
                $view->itemsPerRow = 4;
                $view->aCategories = $aCategories;
                $view->aItems = $aItems;
        }
        // Подготовка хлебных крошек
        $breadcrumbsParentPK = $categoryId;
        $categoryBreadcrumbs = [];
        while ($breadcrumbsParentPK) {
            /** @var Category $oParentCategory */
            $oParentCategory = DataSource::factory(Category::cls(), $breadcrumbsParentPK);
            $categoryBreadcrumbs[] = new Breadcrumb($oParentCategory->name, "?category_id={$oParentCategory->getPrimaryKey()}", true);
            $breadcrumbsParentPK = $oParentCategory->category_id;
        }
        $this->BreadcrumbsView->Breadcrumbs = array_merge($this->BreadcrumbsView->Breadcrumbs, array_reverse($categoryBreadcrumbs));
        if (isset($oItem)) {
            $this->BreadcrumbsView->Breadcrumbs[] = new Breadcrumb($oItem->name, '');
        }
        $view->backUrl = CoreFunctions::buildUrlByBreadcrumbs($this->BreadcrumbsView->Breadcrumbs, 1);
        $this->Frame->bindView('breadcrumbs', $this->BreadcrumbsView);
        $view->render();
    }
Esempio n. 14
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $siteuserAuthorizator = new Authorizator();
     $siteuserId = Param::post('siteuser-edit-id', false)->asInteger(false);
     $name = Param::post('siteuser-edit-name')->noEmpty('Заполните поле "Имя"')->asString();
     $surname = Param::post('siteuser-edit-surname')->noEmpty('Заполните поле "Фамилия"')->asString();
     $patronymic = Param::post('siteuser-edit-patronymic')->noEmpty('Заполните поле "Отчество"')->asString();
     $email = Param::post('siteuser-edit-email')->noEmpty('Заполните поле "E-mail"')->asEmail(true, 'Вы ввели некорректный email.');
     $phone = Param::post('siteuser-edit-phone')->noEmpty('Заполните поле "Телефон"')->asString();
     $postcode = Param::post('siteuser-edit-postcode')->noEmpty('Заполните поле "Индекс"')->asString();
     $address = Param::post('siteuser-edit-address', false)->noEmpty('Заполните поле "Адрес"')->asString();
     $type = Param::post('siteuser-edit-type', false)->noEmpty('Необходимо указать тип пользователя')->asInteger(true, 'Недопустимое значение поля "Тип"');
     $status = Param::post('siteuser-edit-status', false)->noEmpty('Необходимо указать статус пользователя')->asInteger(true, 'Недопустимое значение поля "Статус"');
     $active = (bool) Param::post('siteuser-edit-active')->exists();
     $accept = Param::post('siteuser-edit-accept', false);
     if (!in_array($type, [Siteuser::TYPE_USER, Siteuser::TYPE_CONTRACTOR])) {
         SCMSNotificationLog::instance()->pushError('Недопустимое значение поля "Тип".');
     }
     if (!in_array($status, [Siteuser::STATUS_UNCONFIRMED, Siteuser::STATUS_CONFIRMED, Siteuser::STATUS_DENIED])) {
         SCMSNotificationLog::instance()->pushError('Недопустимое значение поля "Статус".');
     }
     $oSiteusers = DataSource::factory(Siteuser::cls());
     $oSiteusers->builder()->where("deleted=0")->whereAnd()->whereBracketOpen()->where("email='{$email}'")->whereOr()->where("phone='{$phone}'")->whereBracketClose();
     /** @var Siteuser[] $aSiteusers */
     $aSiteusers = $oSiteusers->findAll();
     if (!empty($aSiteusers)) {
         $oSiteuser = $aSiteusers[0];
         if ($oSiteuser->email == $email) {
             SCMSNotificationLog::instance()->pushError('Пользователь с таким Email уже зарегистрирован в системе.');
         }
         if ($oSiteuser->phone == $phone) {
             SCMSNotificationLog::instance()->pushError('Пользователь с таким телефоном уже зарегистрирован в системе.');
         }
     }
     if (CoreFunctions::isAJAX() && SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     /** @var Siteuser $oSiteuser */
     $oSiteuser = DataSource::factory(Siteuser::cls(), $siteuserId);
     $oSiteuser->name = $name;
     $oSiteuser->surname = $surname;
     $oSiteuser->patronymic = $patronymic;
     $oSiteuser->email = $email;
     $oSiteuser->phone = $phone;
     $oSiteuser->postcode = $postcode;
     $oSiteuser->mail_address = $address;
     $oSiteuser->password = $siteuserAuthorizator->defaultPassword();
     $oSiteuser->type = $type;
     $oSiteuser->status = $status;
     $oSiteuser->active = $active;
     if ($oSiteuser->isNew()) {
         $oSiteuser->deleted = false;
     }
     try {
         $oSiteuser->commit();
     } catch (Exception $e) {
         SCMSNotificationLog::instance()->pushError($e->getMessage());
     }
     $redirect = '';
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Пользователь \"{$oSiteuser->email}\" успешно " . ($siteuserId == 0 ? 'добавлен' : 'отредактирован') . ".");
         $redirect = "/admin/modules/siteusers/edit/?id={$oSiteuser->getPrimaryKey()}";
         if ($accept->exists()) {
             $redirect = '/admin/modules/siteusers/';
         }
     }
     $this->Response->send($redirect);
 }