public function actionElement($param) { //Если параметр текст - это каталог, если число - элемент $paramArr = explode("/", $param); $paramArr = array_pop($paramArr); if (is_numeric($paramArr)) { //Число - это элемент $model = Sale::model()->findByPk((int) $paramArr); //Смотрим, нужно ли вставить фотогалерею $model->description = $this->addPhotogalery($model->description); $render = 'view'; } else { //Список новостей категории $modelGroup = SaleGroup::model()->find('url LIKE "' . $paramArr . '"'); $model = array(); $model['group'] = array(); $model['no_group'] = Sale::model()->findAll(array("condition" => "status!=0 AND group_id = " . $modelGroup->id, "order" => "id DESC")); $render = 'index'; } if (empty($model)) { throw new CHttpException(404, 'The page can not be found.'); } $this->render($render, array('model' => $model)); }
$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', SaleGroup::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 = SaleGroup::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<div class="container news-all"> <?php $i = 0; ?> <?php foreach ($model['no_group'] as $data) { ?> <?php ++$i; ?> <?php if ($i % 2 != 0) { echo '<div class="press-line">'; } ?> <?php echo SaleGroup::model()->returnDesignElement($data); ?> <?php if ($i % 2 == 0) { echo '</div>'; } ?> <?php } ?> </div> </main> </div> </section>
<legend><?php echo Yii::t("Bootstrap", "LIST.SaleGroup"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = SaleGroup::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'sale-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("/sale/sale/index", array("Sale[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(SaleGroup::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' => 'Sale[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('/sale/sale/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('/sale/sale/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'))))); ?>
/** * @param $model - модель SaleGroup * Возращает сформированый дизайн списка групп в соответствии с $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/sale/rubrics/' . $model->id . '.' . $model->image . '">' : '', $return); $return = str_replace("%brieftext%", $model->brieftext, $return); $return = str_replace("%description%", $model->description, $return); $sale_element = ''; $i = 0; foreach (Sale::model()->findAll('group_id = ' . $model->id . ' AND status!=0 ORDER BY id DESC') as $dataSale) { ++$i; if ($i % 2 != 0) { $sale_element .= '<div class="press-line">'; } $sale_element .= SaleGroup::model()->returnDesignElement($dataSale); if ($i % 2 == 0) { $sale_element .= '</div>'; } } $return = str_replace("%sale_element%", $sale_element, $return); return $return; }