public function actionElement($param) { //Если параметр текст - это каталог, если число - элемент $paramArr = explode("/", $param); $paramArr = array_pop($paramArr); if (is_numeric($paramArr)) { //Число - это элемент $model = Press::model()->findByPk((int) $paramArr); if (empty($model)) { throw new CHttpException(404, 'The page can not be found.'); } //Смотрим, нужно ли вставить фотогалерею $model->description = $this->addPhotogalery($model->description); $param = null; $render = 'view'; } else { //Список новостей категории $paramArr = str_replace("press-", "", $paramArr); $model = array(); //получаем новости в группах $model['group'] = PressGroup::model()->findAll(array("condition" => "status!=0", "order" => "id ASC")); $model_tmp = PressGroup::model()->find(array("condition" => "status!=0 AND url LIKE '" . $paramArr . "'", "order" => "id ASC")); //получаем новости без групп $model['first_group'] = Press::model()->findAll(array("condition" => "status!=0 AND group_id=" . $model_tmp->id, "order" => "id ASC")); $param = $model_tmp->id; $render = 'index'; } if (empty($model)) { throw new CHttpException(404, 'The page can not be found.'); } $this->render($render, array('model' => $model, 'param' => $param)); }
<legend><?php echo Yii::t("Bootstrap", "LIST.PressGroup"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = PressGroup::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'press-group-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' => $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('header' => $labels["created_at"], 'name' => "created_at"), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{link}', 'buttons' => array('link' => array('label' => 'Список записей группы', 'options' => array('target' => '_blank'), 'url' => 'Yii::app()->createUrl("/press/press/index", array("Press[group_id]"=>$data->id))')), 'htmlOptions' => array('style' => 'width: 80px')), 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'))))); ?> <a href="/admin/<?php echo Yii::app()->controller->module->id; ?> /<?php echo Yii::app()->controller->id; ?> /create" class="btn">Добавить группу</a> <script> //Меняем статус $(document).on('click', '.on-off-product', function(){ $.ajax({ type: 'POST',
<!-- Fields with <span class="required">*</span> are required. --> <!--<p class="help-block"><?php echo Yii::t("Bootstrap", "PHRASE.FIELDS_REQUIRED"); ?> </p>--> <?php echo $form->errorSummary($model); ?> <?php echo $form->textFieldRow($model, 'name', array('class' => 'span5', 'maxlength' => 150)); ?> <?php echo $form->dropDownListRow($model, "group_id", CHtml::listData(PressGroup::model()->findAll(), "id", "name"), array('class' => 'span5', "empty" => "Нет группы")); ?> <?php //echo '<label class="control-label required">Главные новости</label> <div class="controls">' . $form->dropDownList($model,'primary', array('0'=>'Нет','1'=>'Да'), array('name' => 'Press[primary]', 'title' => 'Главные новости')) . '</div>'; ?> <?php Yii::import('ext.imperavi-redactor-widget-master.ImperaviRedactorWidget'); echo $form->label($model, 'brieftext'); $this->widget('ImperaviRedactorWidget', array('model' => $model, 'attribute' => 'brieftext', 'options' => array('lang' => 'ru', 'imageUpload' => Yii::app()->createAbsoluteUrl('/press/press/imageUpload')), 'plugins' => array('fullscreen' => array('js' => array('fullscreen.js')), 'video' => array('js' => array('video.js')), 'table' => array('js' => array('table.js')), 'fontcolor' => array('js' => array('fontcolor.js')), 'fontfamily' => array('js' => array('fontfamily.js')), 'fontsize' => array('js' => array('fontsize.js'))))); echo '<HR>'; echo $form->label($model, 'description'); $this->widget('ImperaviRedactorWidget', array('model' => $model, 'attribute' => 'description', 'options' => array('lang' => 'ru', 'imageUpload' => Yii::app()->createAbsoluteUrl('/press/press/imageUpload')), 'plugins' => array('fullscreen' => array('js' => array('fullscreen.js')), 'video' => array('js' => array('video.js')), 'table' => array('js' => array('table.js')), 'fontcolor' => array('js' => array('fontcolor.js')), 'fontfamily' => array('js' => array('fontfamily.js')), 'fontsize' => array('js' => array('fontsize.js')), 'myphotogalery' => array('js' => array('myphotogalery.js'))))); ?>
$url_img = "/images/nophoto_100_100.jpg"; if (file_exists(YiiBase::getPathOfAlias('webroot') . $base_url_img . $model->id . '.' . $model->image)) { $url_img = $base_url_img . 'small-' . $model->id . '.' . $model->image; } echo '<a href="' . $base_url_img . $model->id . '.' . $model->image . '" target="_blank"><img src="' . $url_img . '"></a>'; } ?> <br> <?php echo CHtml::activeFileField($model, 'imagefile', array('style' => 'cursor: pointer;')); ?> </div> </div> <?php echo $form->dropDownListRow($model, 'status', PressGroup::model()->getStatuslist(), array('class' => 'span5')); ?> <div class="form-actions"> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'htmlOptions' => array('style' => 'margin-right: 20px'), 'label' => $model->isNewRecord ? Yii::t('Bootstrap', 'PHRASE.BUTTON.CREATE') : Yii::t('Bootstrap', 'PHRASE.BUTTON.SAVE'))); ?> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'link', 'label' => Yii::t('Bootstrap', 'PHRASE.BUTTON.RETURN'), 'url' => $this->listUrl('index'))); ?> </div>
/** * 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 = PressGroup::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * @param $model - модель pressGroup * Возращает сформированый дизайн списка групп в соответствии с $model группы */ public function returnDesignGroup($model) { //Серый $template_gray = ' <section class="shadow mg-top-15"> <div class="bg-gray pd-bottom-40 bottom-shadow"> <main class="all" role="main"> <div class="container"> <h1 class="caption-big">%name%</h1> <a href="' . Yii::app()->request->requestUri . '/' . $model->url . '"> <figure class="main-pic" style="cursor: pointer;" > %image% <figcaption> %brieftext% </figcaption> </figure> </a> </div> </main> </div> </section> '; //Белый $template_white = ' <section class="metro pd-top-30 mg-bottom-30"> <main class="all" role="main"> <div class="container"> <h2 class="main-caption">%name%</h2> <a href="' . Yii::app()->request->requestUri . '/' . $model->url . '"> <figure class="main-pic" style="cursor: pointer;"> %image% <figcaption> %brieftext% </figcaption> </figure> </a> </div> </main> </section> '; $return = $template_white; if ($model->param_design == 2) { $return = $template_gray; } $return = str_replace("%name%", $model->name, $return); $return = str_replace("%image%", !empty($model->image) ? '<img src="/uploads/filestorage/press/rubrics/' . $model->id . '.' . $model->image . '">' : '', $return); $return = str_replace("%brieftext%", $model->brieftext, $return); $return = str_replace("%description%", $model->description, $return); $press_element = ''; $i = 0; foreach (Press::model()->findAll('group_id = ' . $model->id . ' AND status!=0 ORDER BY id DESC') as $dataPress) { ++$i; if ($i % 2 != 0) { $press_element .= '<div class="press-line">'; } $press_element .= PressGroup::model()->returnDesignElement($dataPress); if ($i % 2 == 0) { $press_element .= '</div>'; } } $return = str_replace("%press_element%", $press_element, $return); return $return; }