Fix template and add preview image in CoContent

parent 81802671
...@@ -11,6 +11,7 @@ use common\modules\content\models\SearchCoContentData; ...@@ -11,6 +11,7 @@ use common\modules\content\models\SearchCoContentData;
use common\components\AdminController; use common\components\AdminController;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\UploadedFile;
/** /**
* ContentAdminController implements the CRUD actions for CoContent model. * ContentAdminController implements the CRUD actions for CoContent model.
...@@ -143,10 +144,28 @@ class ContentAdminController extends AdminController ...@@ -143,10 +144,28 @@ class ContentAdminController extends AdminController
$model->name, $model->name,
]; ];
} }
//die(print_r($model->metaTag));
if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->load(Yii::$app->request->post());
$model->image = UploadedFile::getInstance($model, 'image');
if (Yii::$app->request->isPost && $model->validate())
{
if($model->image)
{
if($model->preview)
{
$model->deletePreview();
}
$model->upload();
$model->image = null;
}
$model->save();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} else { }
$form = new \common\components\BaseForm('/common/modules/content/forms/ContentForm', $model); $form = new \common\components\BaseForm('/common/modules/content/forms/ContentForm', $model);
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
...@@ -154,7 +173,6 @@ class ContentAdminController extends AdminController ...@@ -154,7 +173,6 @@ class ContentAdminController extends AdminController
'form' => $form->out, 'form' => $form->out,
]); ]);
} }
}
public function actionUpdatecontent($content_id, $id = null) public function actionUpdatecontent($content_id, $id = null)
{ {
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use \common\modules\content\models\CoContent;
$blocks = \common\modules\content\models\CoBlocks::find()->all(); $blocks = \common\modules\content\models\CoBlocks::find()->all();
$block_hint = ''; $block_hint = '';
if(count($blocks)) { if(count($blocks)) {
...@@ -17,6 +19,9 @@ if(count($blocks)) { ...@@ -17,6 +19,9 @@ if(count($blocks)) {
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'controller-form', 'id' => 'controller-form',
'options' => [
'enctype' => 'multipart/form-data'
],
], ],
'elements' => [ 'elements' => [
'category_id' => [ 'category_id' => [
...@@ -42,6 +47,8 @@ return [ ...@@ -42,6 +47,8 @@ return [
'class' => 'form-control', 'class' => 'form-control',
'hint' => 'Заголовок страницы виден пользователю сайта и как правило оформляется в тег <h1>. Если дизайном страницы не предусмотрен вывод заголовка, то он не будет выводиться даже если был введен в данное поле.', 'hint' => 'Заголовок страницы виден пользователю сайта и как правило оформляется в тег <h1>. Если дизайном страницы не предусмотрен вывод заголовка, то он не будет выводиться даже если был введен в данное поле.',
], ],
($model->preview?Html::img(\Yii::$app->params['frontUrl'] . CoContent::PHOTO_FOLDER . $model->preview):''),
'image' => ['type' => 'file', 'class' => 'form-control',],
'text' => [ 'text' => [
'type' => 'textarea', 'type' => 'textarea',
'class' => 'form-control', 'class' => 'form-control',
......
...@@ -75,11 +75,6 @@ class CoBlocks extends \common\components\ActiveRecordModel ...@@ -75,11 +75,6 @@ class CoBlocks extends \common\components\ActiveRecordModel
public static function printStaticBlock($block, $addPath = false) public static function printStaticBlock($block, $addPath = false)
{ {
return \yii::$app->getView()->render( '@app/views/layouts/block/' . $block . '.php'); return \yii::$app->getView()->render( '@app/views/layouts/block/' . $block . '.php');
if ($addPath) {
return \yii::$app->getView()->render( '@app/views/layouts/block/' . $block . '.php');
}
else
return \yii::$app->getView()->render( '/block/'.$block);
} }
public function afterFind() { public function afterFind() {
......
...@@ -23,6 +23,10 @@ use yii\base\Controller; ...@@ -23,6 +23,10 @@ use yii\base\Controller;
*/ */
class CoContent extends \common\components\ActiveRecordModel class CoContent extends \common\components\ActiveRecordModel
{ {
public $image;
const PHOTO_FOLDER = '/uploads/content/';
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -57,6 +61,7 @@ class CoContent extends \common\components\ActiveRecordModel ...@@ -57,6 +61,7 @@ class CoContent extends \common\components\ActiveRecordModel
{ {
return [ return [
[['active', 'created_at', 'updated_at'], 'integer'], [['active', 'created_at', 'updated_at'], 'integer'],
[['image'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
[['url', 'name', 'text'], 'required'], [['url', 'name', 'text'], 'required'],
[['url', 'name', 'title'], 'string', 'max' => 250], [['url', 'name', 'title'], 'string', 'max' => 250],
[['category_id', 'text'], 'safe'] [['category_id', 'text'], 'safe']
...@@ -73,6 +78,7 @@ class CoContent extends \common\components\ActiveRecordModel ...@@ -73,6 +78,7 @@ class CoContent extends \common\components\ActiveRecordModel
'category_id' => Yii::t('content', 'Category ID'), 'category_id' => Yii::t('content', 'Category ID'),
'url' => Yii::t('content', 'Url'), 'url' => Yii::t('content', 'Url'),
'name' => Yii::t('content', 'Name'), 'name' => Yii::t('content', 'Name'),
'image' => 'Превью',
'title' => Yii::t('content', 'Title'), 'title' => Yii::t('content', 'Title'),
'text' => Yii::t('content', 'Content'), 'text' => Yii::t('content', 'Content'),
'active' => Yii::t('content', 'Active'), 'active' => Yii::t('content', 'Active'),
...@@ -127,6 +133,10 @@ class CoContent extends \common\components\ActiveRecordModel ...@@ -127,6 +133,10 @@ class CoContent extends \common\components\ActiveRecordModel
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('cases', true); $arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('cases', true);
$arrWhatReplaceNext[] = '[case-subscribe]'; $arrWhatReplaceNext[] = '[case-subscribe]';
$arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('case-subscribe', true); $arrReplaceNext[] = \common\modules\content\models\CoBlocks::printStaticBlock('case-subscribe', true);
$arrWhatReplaceNext[] = '[footer]';
$arrReplaceNext[] = \Yii::$app->getView()->render('@app/views/layouts/footer');
$arrWhatReplaceNext[] = '[footer-index]';
$arrReplaceNext[] = \Yii::$app->getView()->render('@app/views/layouts/footer-index');
return str_replace($arrWhatReplaceNext, $arrReplaceNext,str_replace($arrWhatReplace, $arrReplace, $content)); return str_replace($arrWhatReplaceNext, $arrReplaceNext,str_replace($arrWhatReplace, $arrReplace, $content));
} }
...@@ -135,4 +145,36 @@ class CoContent extends \common\components\ActiveRecordModel ...@@ -135,4 +145,36 @@ class CoContent extends \common\components\ActiveRecordModel
$this->text = str_replace("../../../source/","/source/",$this->text); $this->text = str_replace("../../../source/","/source/",$this->text);
return parent::beforeSave($insert); return parent::beforeSave($insert);
} }
private function getPath()
{
return Yii::getAlias('@frontend/web') . self::PHOTO_FOLDER;
}
public function upload()
{
if ($this->validate())
{
if(!file_exists($this->getPath()))
{
mkdir($this->getPath(), 0777, true);
}
$this->preview = date('dmYHis-') . uniqid() . '.' . $this->image->extension;
$this->image->saveAs($this->getPath() . $this->preview);
return true;
}
else
{
return false;
}
}
public function deletePreview()
{
if(file_exists($this->getPath() . $this->preview))
{
unlink($this->getPath() . $this->preview);
}
}
} }
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160127_070543_add_content_preview extends Migration
{
public function safeUp()
{
$this->addColumn('co_content', 'preview', Schema::TYPE_STRING . '(50) AFTER `active`');
}
public function safeDown()
{
$this->dropColumn('co_content', 'preview');
}
}
<div class="row"> <?php
use \common\modules\content\models\CoContent;
use yii\helpers\Html;
$models = CoContent::find()
->where(['category_id' => 4])
->orderBy('id DESC')
->all();
?>
<?php if($models) : ?>
<div class="row">
<?php foreach ($models as $model) : ?>
<div class="col-md-6 col-xs-6 col-sm-12"> <div class="col-md-6 col-xs-6 col-sm-12">
<div class="keys_block_small"> <div class="keys_block_small">
<img src="/images/keys_small1.jpg" height="338" width="455" alt=""> <?=Html::img([CoContent::PHOTO_FOLDER . $model->preview], ['height' => '338', 'width' => '455'])?>
<div class="keys_small_title">Он-лайн сервис по подбору аналогов оборудования</div> <div class="keys_small_title"><?=$model->title?></div>
<div class="keys_small_foot"> <div class="keys_small_foot">
<a href="/case/kns" class="keys_small_btn_more"><span>Подробнее</span></a> <?=Html::a('<span>Подробнее</span>', ['/'.$model->url], ['class' => 'keys_small_btn_more'])?>
<a href="#" class="keys_small_tags"># Big data</a> <!-- <a href="#" class="keys_small_tags"># Big data</a> -->
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-6 col-xs-6 col-sm-12"> <?php endforeach; ?>
<!-- <div class="col-md-6 col-xs-6 col-sm-12">
<div class="keys_block_small"> <div class="keys_block_small">
<img src="/images/keys_small2.jpg" height="338" width="455" alt=""> <img src="/images/keys_small2.jpg" height="338" width="455" alt="">
<div class="keys_small_title">Автоматизация освещения на АЗС</div> <div class="keys_small_title">Автоматизация освещения на АЗС</div>
...@@ -18,9 +31,9 @@ ...@@ -18,9 +31,9 @@
<a href="#" class="keys_small_tags"># Big data</a> <a href="#" class="keys_small_tags"># Big data</a>
</div> </div>
</div> </div>
</div> -->
</div> </div>
</div> <!-- <div class="row">
<div class="row">
<div class="col-md-12 col-xs-12 col-sm-12"> <div class="col-md-12 col-xs-12 col-sm-12">
<div class="keys_block_big"> <div class="keys_block_big">
<picture> <picture>
...@@ -34,4 +47,6 @@ ...@@ -34,4 +47,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div> -->
\ No newline at end of file
<?php endif; ?>
\ No newline at end of file
<footer>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="calk_form">
<span class="calk_form__title">Рассчитать проект</span>
<span class="calk_form_subtitle">Готовы обсудить любой проект. Есть идея или готовое ТЗ по проекту - отправьте его нам</span>
<form class="footer_form" id="form_foot">
<input type="text" placeholder="Ваше имя*" name="name" class="footer_form__input field-input required alphanumeric">
<input type="tel" placeholder="Телефон*" name="phone" class="footer_form__input field-input required alphanumeric">
<input type="email" placeholder="E-mail*" class="footer_form__input field-input required email">
<textarea placeholder="Опишите в двух словах ваш проект" class="footer_form__textarea"></textarea>
<div class="file-upload_block">
<div class="file_upload_bt">
<div class="file-upload">
<label>
<input type="file" name="file">
<span>Выбрать файл</span>
</label>
</div>
<input type="text" id="filename" class="filename" disabled>
<div class="file_drop">Перетащите файл в данную область<br/> или выберите файл с компьютера</div>
</div>
</div>
<button class="btn-default save-button">Рассчитать проект</button>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 col-xs-4 col-sm-12">
<a href="mailto:info@task-on.com" class="foot_mail">info@task-on.com</a>
</div>
<div class="col-md-4 col-xs-4 col-sm-12"><a href="#zvonok_form" class="zvonok_bt popup-form"><span>Заказать звонок</span></a></div>
<div class="col-md-4 col-xs-4 col-sm-12">
<div class="phone_hover_foot">Стоимость звонка 0 руб,<br/> в том числе с мобильного</div>
<span class="foot_phone"><?=\common\models\Settings::getValue('content-phone');?></span>
</div>
</div>
<div class="footbottom_line">
<div class="row">
<div class="col-md-3 col-xs-3 col-sm-12">
<div class="foot_logo">
<img src="images/foot_logo.png" height="51" width="192" alt="">
</div>
</div>
<div class="col-md-6 col-xs-6 col-sm-12">
<ul class="social_link">
<li><a href="#" class="soc_item"><i class="fa fa-vk"></i></a></li>
<li><a href="#" class="soc_item"><i class="fbicon"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-youtube"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-instagram"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-twitter"></i></a></li>
<li><a href="#" class="soc_item"><i class="gplusicon"></i></a></li>
</ul>
</div>
<div class="col-md-3 col-xs-3 col-sm-12">
<div class="taskon"><img src="images/taskon.png" height="31" width="100" alt=""></div>
<div class="copyring">Powered by Taskon <br /> Собственная разработка Арт Проект</div>
</div>
</div>
</div>
</div>
</footer>
<div class="hidden">
<div id="zvonok_form" class="popup">
<div class="txtbtnclose">Закрыть</div>
<span class="popup__title">Заказать звонок</span>
<span class="popup__subtittle">Чтобы мы могли вам перезвонить укажите свой номер телефона:</span>
<form class="valid_form">
<input type="text" class="input_st field-input required alphanumeric" placeholder="Ваше имя">
<input type="tel" class="input_st field-input required email" placeholder="Ваш телефон">
<button class="save-button popup_bt_send">Заказать звонок</button>
</form>
</div>
</div>
\ No newline at end of file
<footer style="padding-top:70px">
<div class="container">
<div class="row">
<div class="col-md-4 col-xs-4 col-sm-12">
<a href="mailto:info@task-on.com" class="foot_mail">info@task-on.com</a>
</div>
<div class="col-md-4 col-xs-4 col-sm-12"><a href="#zvonok_form" class="zvonok_bt popup-form"><span>Заказать звонок</span></a></div>
<div class="col-md-4 col-xs-4 col-sm-12">
<div class="phone_hover_foot">Стоимость звонка 0 руб,<br/> в том числе с мобильного</div>
<span class="foot_phone"><?=\common\models\Settings::getValue('content-phone');?></span>
</div>
</div>
<div class="footbottom_line">
<div class="row">
<div class="col-md-3 col-xs-3 col-sm-12">
<div class="foot_logo">
<img src="/images/foot_logo.png" height="51" width="192" alt="">
</div>
</div>
<div class="col-md-6 col-xs-6 col-sm-12">
<ul class="social_link">
<li><a href="#" class="soc_item"><i class="fa fa-vk"></i></a></li>
<li><a href="#" class="soc_item"><i class="fbicon"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-youtube"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-instagram"></i></a></li>
<li><a href="#" class="soc_item"><i class="fa fa-twitter"></i></a></li>
<li><a href="#" class="soc_item"><i class="gplusicon"></i></a></li>
</ul>
</div>
<div class="col-md-3 col-xs-3 col-sm-12">
<div class="taskon"><img src="/images/taskon.png" height="31" width="100" alt=""></div>
<div class="copyring">Powered by Taskon <br /> Собственная разработка Арт Проект</div>
</div>
</div>
</div>
</div>
</footer>
<div class="hidden">
<div id="zvonok_form" class="popup">
<div class="txtbtnclose">Закрыть</div>
<span class="popup__title">Заказать звонок</span>
<span class="popup__subtittle">Чтобы мы могли вам перезвонить укажите свой номер телефона:</span>
<form class="valid_form">
<input type="text" class="input_st field-input required alphanumeric" placeholder="Ваше имя">
<input type="tel" class="input_st field-input required email" placeholder="Ваш телефон">
<button class="save-button popup_bt_send">Заказать звонок</button>
</form>
</div>
</div>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment