コード例 #1
0
 public function actionIndex($id)
 {
     $model = Pages::model()->findByPk($id);
     if (!$model || $model->status == 0) {
         throw new CHttpException(404, 'The page can not be found.');
     }
     //Титл и SEO
     $this->setSEO($model->url, mb_convert_case($model->title, MB_CASE_UPPER, "UTF-8"));
     $this->layout = '//layouts/' . $model->main_template;
     $modelCatalog = null;
     $modelNews = null;
     //Если главная - добавляю товары помеченые как на главную и новости
     if ($model->main_page == 1) {
         $modelCatalog = CatalogElements::model()->findAll('`status` = 1 AND `primary` = 1');
         $modelNews = NewsElements::gatPrimaryNews();
     }
     //Проверка прав доступа
     if ($model->access_lvl > 0) {
         if (Yii::app()->user->isGuest) {
             $this->redirect('/login');
         }
     }
     //Проверяем есть ли фотогалерея, если есть - меняем содержимое страницы
     $model->content = $this->addPhotogalery($model->content);
     //Проверяем есть ли форма, если есть - меняем содержимое страницы
     $model->content = $this->addForm($model->content);
     //Получаем вкладки если есть;
     $modelTabs = PagesTabs::model()->getTabsContent($id);
     $this->render('index', array('model' => $model, 'modelTabs' => $modelTabs, 'modelCatalog' => $modelCatalog, 'modelNews' => $modelNews));
 }
コード例 #2
0
 public function actionElement($param)
 {
     $paramArr = explode("/", $param);
     $paramArr = array_pop($paramArr);
     $paramArr = strtolower($paramArr);
     if (is_numeric($paramArr)) {
         $modelElements = NewsElements::model()->findByPk($paramArr);
         $model = NewsRubrics::model()->findByPk($modelElements->parent_id);
         if (!$modelElements) {
             throw new CHttpException(404, 'The page can not be found.');
         }
         $this->setSEOData($modelElements);
         $pageArray = array();
         $i = 0;
         foreach ($model->ancestors()->findAll() as $data) {
             if ($data->level == 1) {
                 continue;
             }
             $pageArray[$i]['url'] = $data->url;
             $pageArray[$i]['name'] = $data->name;
             ++$i;
         }
         $pageArray[$i]['url'] = $model->url;
         $pageArray[$i]['name'] = $model->name;
         if (count($pageArray) > 1) {
             rsort($pageArray);
         }
         $model = $model->descendants(1)->findAll($model->id);
         $render = 'view';
     } else {
         if ($modelPage = Pages::model()->find('url LIKE "' . $param . '"')) {
             if ($modelTabs = PagesTabs::model()->find('pages_id=' . $modelPage->id)) {
                 $module_id = array_diff(explode("|", $modelTabs->site_module_value), array(''));
                 if ($tmpParam = NewsRubrics::model()->find('id in (' . current($module_id) . ') AND `status` = 1')) {
                     $paramArr = $tmpParam->url;
                 }
             }
         }
         $model = NewsRubrics::model()->find('url LIKE "' . $paramArr . '"');
         if (!$model) {
             throw new CHttpException(404, 'The page can not be found.');
         }
         $this->setSEO(Yii::app()->request->requestUri, 'Статьи', $model);
         $pageArray = array();
         $pageArray[0]['name'] = ' / ' . $model->name;
         $pageArray[0]['url'] = null;
         $i = 1;
         foreach ($model->ancestors()->findAll('level>1') as $data) {
             $pageArray[$i]['name'] = ' / ' . $data->name;
             $pageArray[$i]['url'] = 'news/' . $data->url;
             ++$i;
         }
         rsort($pageArray);
         if (count($pageArray) > 1) {
             rsort($pageArray);
         }
         $modelElements = NewsElements::model()->findAll('parent_id = ' . $model->id . ' AND `status`=1 ORDER BY `primary` DESC');
         $model = $model->descendants(1)->findAll($model->id);
         $render = 'index';
     }
     $this->render($render, array('model' => $model, 'modelElements' => $modelElements, 'pageArray' => $pageArray));
 }
コード例 #3
0
 public function actionAjax()
 {
     if (isset($_POST)) {
         switch ((int) $_POST['type']) {
             case 1:
                 //Смена статуса
                 $model = $this->loadModel((int) $_POST['id']);
                 $model->status = $model->status == 1 ? 0 : 1;
                 $model->save();
                 //Меняем статус для вопросов
                 foreach (NewsElements::model()->findAll('parent_id = ' . $model->id) as $data) {
                     $data->status = $model->status;
                     $data->save();
                 }
                 break;
         }
         echo CJavaScript::jsonEncode('ok');
     }
     Yii::app()->end();
 }
コード例 #4
0
ファイル: list.php プロジェクト: Diakonrus/fastweb-yii
<legend><?php 
echo Yii::t("Bootstrap", "LIST.NewsElements");
?>
</legend>

<?php 
$assetsDir = Yii::app()->basePath;
$labels = NewsElements::model()->attributeLabels();
$this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'news-elements-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->search(), 'filter' => null, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => 'Картинка', 'name' => "image", 'type' => 'raw', 'value' => function ($dataProvider) {
    $url_img = '/images/nophoto_100_100.jpg';
    if (file_exists(YiiBase::getPathOfAlias('webroot') . '/../uploads/filestorage/news/elements/admin-' . $dataProvider->id . '.' . $dataProvider->image)) {
        $url_img = '/../uploads/filestorage/news/elements/admin-' . $dataProvider->id . '.' . $dataProvider->image;
    }
    return '<img src="' . $url_img . '" style="width:80px" />';
}, 'filter' => ''), array('header' => $labels["parent_id"], 'name' => "parent_id", 'type' => 'raw', 'value' => function ($data) {
    $parent_name = $data->parent->name;
    if ($data->parent->level == 1) {
        $parent_name = '/';
    }
    return $parent_name;
}, 'filter' => ''), array('header' => $labels["name"], 'name' => "name"), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) {
    return '
                    <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '">
                        <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div>
                    </a>
                ';
}, 'filter' => ''), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update}  {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));
?>

<div class="buttons">
コード例 #5
0
 public function getCountElements($parent_id)
 {
     return (int) NewsElements::model()->count("parent_id=:field AND `status`=1", array("field" => $parent_id));
 }
コード例 #6
0
ファイル: NewsRubrics.php プロジェクト: Diakonrus/fastweb-yii
 public static function getCountElement($parent_id)
 {
     return NewsElements::model()->count("parent_id=:field", array("field" => $parent_id));
 }
コード例 #7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = NewsElements::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }