amic před 1 rokem
rodič
revize
0157486035

+ 12 - 0
controllers/InquirerController.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace app\controllers;
+
+class InquirerController extends \yii\web\Controller
+{
+    public function actionIndex()
+    {
+        return $this->render('index');
+    }
+
+}

+ 38 - 0
migrations/m230918_092622_inquirer_question.php

@@ -0,0 +1,38 @@
+<?php
+
+use yii\db\Schema;
+use yii\db\Migration;
+
+class m230918_092622_inquirer_question extends Migration
+{
+
+    public function init()
+    {
+        $this->db = 'db';
+        parent::init();
+    }
+
+    public function safeUp()
+    {
+        $tableOptions = 'ENGINE=InnoDB';
+
+        $this->createTable(
+            '{{%inquirer_question}}',
+            [
+                'id'=> $this->primaryKey()->unsigned(),
+                'text'=> $this->text()->notNull(),
+                'active'=> "enum('Y', 'N') NOT NULL DEFAULT 'Y' COMMENT 'доступна'",
+                'show'=> "enum('Y', 'N') NOT NULL DEFAULT 'Y' COMMENT 'показывать на главной'",
+                'dt_cr'=> $this->datetime()->notNull()->defaultExpression("CURRENT_TIMESTAMP"),
+                'dt_pub'=> $this->datetime()->notNull()->defaultExpression("CURRENT_TIMESTAMP"),
+                'dt_end'=> $this->datetime()->notNull()->defaultExpression("CURRENT_TIMESTAMP"),
+            ],$tableOptions
+        );
+
+    }
+
+    public function safeDown()
+    {
+        $this->dropTable('{{%inquirer_question}}');
+    }
+}

+ 38 - 0
migrations/m230918_092658_inquirer_answer.php

@@ -0,0 +1,38 @@
+<?php
+
+use yii\db\Schema;
+use yii\db\Migration;
+
+class m230918_092658_inquirer_answer extends Migration
+{
+
+    public function init()
+    {
+        $this->db = 'db';
+        parent::init();
+    }
+
+    public function safeUp()
+    {
+        $tableOptions = 'ENGINE=InnoDB';
+
+        $this->createTable(
+            '{{%inquirer_answer}}',
+            [
+                'id'=> $this->primaryKey()->unsigned(),
+                'idq'=> $this->integer()->unsigned()->notNull()->comment('id вопроса'),
+                'text'=> $this->text()->notNull(),
+                'type'=> $this->string(64)->notNull()->defaultValue('simple'),
+                'count'=> $this->integer()->unsigned()->notNull()->defaultValue(0)->comment('счётчик'),
+            ],$tableOptions
+        );
+        $this->createIndex('idq','{{%inquirer_answer}}',['idq'],false);
+
+    }
+
+    public function safeDown()
+    {
+        $this->dropIndex('idq', '{{%inquirer_answer}}');
+        $this->dropTable('{{%inquirer_answer}}');
+    }
+}

+ 37 - 0
migrations/m230918_092723_inquirer_log.php

@@ -0,0 +1,37 @@
+<?php
+
+use yii\db\Schema;
+use yii\db\Migration;
+
+class m230918_092723_inquirer_log extends Migration
+{
+
+    public function init()
+    {
+        $this->db = 'db';
+        parent::init();
+    }
+
+    public function safeUp()
+    {
+        $tableOptions = 'ENGINE=InnoDB';
+
+        $this->createTable(
+            '{{%inquirer_log}}',
+            [
+                'id'=> $this->primaryKey()->unsigned(),
+                'idq'=> $this->integer()->unsigned()->notNull(),
+                'hash'=> $this->string(64)->notNull(),
+                'dt'=> $this->timestamp()->notNull()->defaultExpression("CURRENT_TIMESTAMP"),
+            ],$tableOptions
+        );
+        $this->createIndex('idq','{{%inquirer_log}}',['idq'],false);
+
+    }
+
+    public function safeDown()
+    {
+        $this->dropIndex('idq', '{{%inquirer_log}}');
+        $this->dropTable('{{%inquirer_log}}');
+    }
+}

+ 61 - 0
models/Inquirer.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\models;
+use app\models\InquirerAnswer;
+use Yii;
+
+/**
+ * This is the model class for table "inquirer_question".
+ *
+ * @property int $id
+ * @property string $text
+ * @property string $active доступна
+ * @property string $show показывать на главной
+ * @property string $dt_cr
+ * @property string $dt_pub
+ * @property string $dt_end
+ */
+class Inquirer extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'inquirer_question';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['text'], 'required'],
+            [['text', 'active', 'show'], 'string'],
+            [['dt_cr', 'dt_pub', 'dt_end'], 'safe'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'text' => 'Вопрос',
+            'active' => 'Доступна',
+            'show' => 'Показывать на главной',
+            'dt_cr' => 'Дата создания',
+            'dt_pub' => 'Дата публикации',
+            'dt_end' => 'Дата окончания опроса',
+        ];
+    }
+
+    public function getAnswers()
+    {
+        return InquirerAnswer::findAll(['idq'=>$this->id]);
+    }
+
+}

+ 53 - 0
models/InquirerAnswer.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "inquirer_question".
+ *
+ * @property int $id
+ * @property string $text
+ * @property string $active доступна
+ * @property string $show показывать на главной
+ * @property string $dt_cr
+ * @property string $dt_pub
+ * @property string $dt_end
+ */
+class InquirerAnswer extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'inquirer_answer';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['text'], 'required'],
+            [['text', 'type'], 'string'],
+            [['count'], 'integer'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'idq' => 'ID Вопроса',
+            'text' => 'Ответ',
+            'type' => 'тип ответа',
+            'count' => 'счётчик',
+        ];
+    }
+}

+ 50 - 0
models/InquirerLog.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "inquirer_log".
+ *
+ * @property int $id
+ * @property int $idq
+ * @property string $hash
+ * @property string $dt
+ */
+class InquirerLog extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'inquirer_log';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['idq', 'hash'], 'required'],
+            [['idq'], 'integer'],
+            [['dt'], 'safe'],
+            [['hash'], 'string', 'max' => 64],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'idq' => 'id вопроса',
+            'hash' => 'Hash',
+            'dt' => 'дата голоса',
+        ];
+    }
+}

+ 82 - 0
modules/manager/controllers/InquirerController.php

@@ -0,0 +1,82 @@
+<?php
+namespace manager\controllers;
+use app\models\Inquirer;
+use app\models\InquirerAnswer;
+use  Yii;
+
+class InquirerController extends \yii\web\Controller
+{
+    public function actionIndex()
+    {
+        return $this->render('index');
+    }
+    public function actionUpdate($id)
+    {
+		$model = $this->findModel($id);
+		if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
+			if( $model->load($post, 'Inquirer') && $model->save() ){
+				if( isset($post['Inquirer']['text_answer']) ){
+					$answer_do = InquirerAnswer::findAll(['idq'=>$id]);
+					$a = array();
+					foreach( $answer_do as $item ){
+						$a[$item->id] = $item->id;
+					}
+					foreach( $post['Inquirer']['text_answer'] as $key => $item ){
+						if( isset( $a[$key] ) ){ unset($a[$key]); }
+						$answer = InquirerAnswer::findOne(['id'=>$key]);
+						if( $answer ){
+							$answer->text = $item;
+							$answer->idq = $id;
+							$answer->save();
+						}
+					}
+					foreach( $a as $item ){
+						$answer = InquirerAnswer::findOne(['id'=>$item]);
+						$answer->delete();
+					}
+				}
+				if( isset($post['Inquirer']['text_new']) ){
+					foreach( $post['Inquirer']['text_new'] as $item ){
+						$answer = new InquirerAnswer();
+						$answer->text = $item;
+						$answer->idq = $id;
+						$answer->save();
+					}
+				}
+			}
+		}else{
+			return $this->render('Update', ['model'=>$model]);
+		}
+		return  $this->redirect('index');
+    }
+
+    public function actionCreate()
+    {
+		$model = new Inquirer();
+		if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
+			if( $model->load($post, 'Inquirer') && $model->save() ){
+				if( isset($post['Inquirer']['text_new']) ){
+					foreach( $post['Inquirer']['text_new'] as $item ){
+						$answer = new InquirerAnswer();
+						$answer->text = $item;
+						$answer->idq = $model->id;
+						$answer->save();
+					}
+				}
+			}
+		}else{
+			return $this->render('Create', ['model'=>$model]);
+		}
+		return  $this->redirect('index');
+    }
+
+    protected function findModel($id)
+    {
+        if (($model = Inquirer::findOne($id)) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('Ой! рубрика не найдена.');
+        return false;
+    }
+}

+ 4 - 2
modules/manager/views/default/newsUpdate.php

@@ -11,8 +11,10 @@
 		$id = $request->get('id');
 	}
 	if( !isset($model) ){
-		$model = new \app\models\News();
-		$model = News::findOne($id);;
+		$model = News::findOne($id);
+		if( !$model ){
+			$model = new \app\models\News();
+		}
 	}
 	if( !(isset($model->uid) && $model->uid && Uuid::isvalid($model->uid)) )
 	{

+ 10 - 0
modules/manager/views/inquirer/Create.php

@@ -0,0 +1,10 @@
+<?php
+
+$this->title = 'Добавить новый опрос';
+$this->params['breadcrumbs'][] = ['label' => 'Опросы', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+    <?= $this->render('form', [
+        'model' => $model,
+    ]) ?>
+

+ 12 - 0
modules/manager/views/inquirer/Update.php

@@ -0,0 +1,12 @@
+<?php
+
+$this->title = 'Обновить опрос';
+$this->params['breadcrumbs'][] = ['label' => 'опросы', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<blockquote class="quote-info">
+<h5 id="tip">Id</h5>
+<p><code class="language-plaintext highlighter-rouge"><?=$model->id?></code></p>
+</blockquote>
+
+<?= $this->render('form', [ 'model' => $model ]) ?>

+ 117 - 0
modules/manager/views/inquirer/form.php

@@ -0,0 +1,117 @@
+<?php
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+use kartik\datetime\DateTimePicker;
+use app\widgets\CropperjsWidget;
+
+$form = ActiveForm::begin([
+    'id' => 'inquirer-form',
+    'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
+
+?>
+<input type="hidden" name="inquirer[id]" value="<?=$model->id?>">
+
+<div class="container-fluid">
+<div class="row">
+	<div class="col">
+<?
+echo $form->field($model, 'text')->textInput([
+                    'maxlength' => true,
+                    'class' => 'form-control js-word-count-input',
+					'placeholder' => 'Вопрос',
+//					'id' => 'js-news-content'
+                ])->label('Вопрос');
+?>
+<div class="card">
+<div class="card-header">
+<h3 class="card-title">Варианты ответов</h3>
+</div>
+<div class="card-body">
+<?
+$answers = $model->getAnswers();
+foreach($answers as $item){
+?>
+<div class="info-box answer">
+<span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i><br><span class="info-box-number-cnt"><?=$item->count?></span></span>
+<div class="info-box-content">
+<div class="input-group">
+	<input type="text" class="form-control" value="<?=$item->text?>" name="Inquirer[text_answer][<?=$item->id?>]">
+		<div class="input-group-append">
+			<span class="btn btn-dark btn-flat"  onclick="remove(this)"><b>-</b></span>
+		</div>
+</div>
+</div>
+</div>
+<?
+}
+?>
+
+</div>
+
+<div class="card-footer">
+<div class="card-tools">
+<button type="button" class="btn btn-outline-primary" onclick="addanswer()"><b>+</b></button>
+</div>
+</div>
+
+</div>
+<div class="form-group form-check">
+<?
+
+                //($model->show == 'Y')?true:false,
+echo $form->field($model, 'show')->checkbox([
+                    'class' => 'form-check-input',
+					'label' => 'Показывать на главной',
+					'uncheck' => 'N',
+					'value' => 'Y',
+					'checked' => ($model->show == 'Y')?true:false
+                ]);
+echo $form->field($model, 'active')->checkbox([
+                    'class' => 'form-check-input',
+					'label' => 'Активный',
+					'uncheck' => 'N',
+					'value' => 'Y',
+					'checked' => ($model->active == 'Y')?true:false
+                ]);
+
+?>
+</div>
+<div class="form-group">
+<?
+	echo Html::submitButton('Сохранить', ['class' => 'btn btn-success']);
+?>
+</div>
+</div>
+</div>
+</div>
+<script id="template-answer" type="text/template">
+<div class="info-box answer">
+<span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i></span>
+<div class="info-box-content">
+<div class="input-group">
+	<input type="text" class="form-control" value="" name="Inquirer[text_new][]">
+		<div class="input-group-append">
+			<span class="btn btn-dark btn-flat" onclick="remove(this)"><b>-</b></span>
+		</div>
+</div>
+</div>
+</div>
+</script>
+<script>
+	function addanswer(){
+		el = document.getElementById('template-answer').innerHTML,
+		$(el).appendTo($('.card-body'));
+	}
+	function remove(el){
+		$(el).parent().closest('.answer').remove();
+	}
+</script>
+<style>
+.info-box-number-cnt{
+	position: absolute;
+	bottom: 6px;
+	font-size: 17px;
+}
+</style>
+<?
+ActiveForm::end();

+ 88 - 0
modules/manager/views/inquirer/index.php

@@ -0,0 +1,88 @@
+<?php
+use app\models\Inquirer;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+use yii\widgets\LinkPager;
+use yii\data\Pagination;
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Опросник';
+$this->params['breadcrumbs'][] = $this->title;
+$query = Inquirer::find()->orderBy([ 'id' => SORT_DESC]);
+$count = $query->count();
+$newsDataProvider = new \yii\data\ActiveDataProvider(
+    [
+        "query"=>$query,
+            "pagination" => [ 'pageSize' => 50 ]
+    ]
+);
+?>
+<div class="table-responsive-sm custom-range-badge">
+<table class="table table-hover table-Light">
+  <thead class="bg-gray table-sm">
+    <tr>
+      <th scope="col" class="col-md-1 col-sm-2 col-xs-5">#</th>
+      <th scope="col">заголовок</th>
+      <th scope="col">статусы</th>
+      <th scope="col">управление</th>
+    </tr>
+  </thead>
+  <tbody>
+<?
+	$key = 'Inquirer_list';
+//	if ($this->beginCache($key, ['duration' => 60*1])) {
+	foreach( $newsDataProvider->getModels() as $item ){
+//		print_r($item);
+//return;
+		$strbage = '';
+		$mark = '';
+		if( $item->show == 'Y' ){
+//			$mark = ' class="table-dark"';
+			$strbage .= '<span class="badge badge-cyan">на главной</span><br>';
+		}
+		if( $item->active == 'N' ){
+			$mark = ' class="table-secondary"';
+			$strbage .= '<span class="badge badge-secondary">не видно никому</span><br>';
+		}
+?>
+    <tr<?=$mark?>>
+      <th scope="row" class="text-nowrap"><?=$item->id?></th>
+      <td><?=$item->text?><br></td>
+      <td><?=$strbage?></td>
+      <td><div class="btn-group btn-group-toggle" data-toggle="a" role="group">
+      <a href="/manager/inquirer/update?id=<?=$item->id?>" title="Править" role="button" class="btn btn-secondary btn-sm"><i class="far fa-edit"></i></a>
+      <a href="/manager/inquirer/show?id=<?=$item->id?>" title="на главной" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->show == 'N')?'fa-eye-slash':'fa fa-eye'?>"></i></a>
+      <a href="/manager/inquirer/active?id=<?=$item->id?>" title="не видно ни кому" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->active)?'fa-play':'fa fa-stop'?>"></i></a>
+      </div></td>
+    </tr>
+<?
+//	<pre>
+//	print_r($item);
+//	</pre>
+?>
+<?
+	}
+//	$this->endCache();
+//	}
+?>
+  </tbody>
+</table>
+</div>
+<?php
+$pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => 50]);
+echo "<nav>";
+echo LinkPager::widget([
+      'pagination' => $pagination,
+//	  'class' => 'yii\bootstrap4\LinkPager',
+      'pageCssClass' => 'page-item',
+	  'linkOptions' => [ 'class'=>'page-link'],
+	  'prevPageCssClass' => 'page-item',
+	  'disabledListItemSubTagOptions' => ['tag' => 'a', 'class' => 'page-link'],
+   ]);
+//print_r($newsDataProvider->getModels());
+echo "</nav>";
+
+

+ 10 - 3
modules/manager/views/layouts/sidebar.php

@@ -93,22 +93,29 @@ $profile = Yii::$app->user->identity->profile;
                         ]
                     ],
                     ['label' => 'Тэги', 'icon' => 'th', 'url' => ['/manager/tags/index'],
-						'badge' => '<span class="right badge badge-danger">New</span>',
                         'items' => [
                             ['label' => 'Список', 'url' => ['/manager/tags/index'], 'iconStyle' => 'far'],
                             ['label' => 'Создать', 'url' => ['/manager/tags/create'], 'iconStyle' => 'far'],
                             ['label' => 'Меню', 'url' => ['/manager/tagsfilter/index'], 'iconStyle' => 'far', 'iconClass'=>'nav-icon fas fa-th-list']
                         ]
                     ],
+                    ['label' => 'Опросы', 'icon' => 'th', 'url' => ['/manager/inquirer/'],
+						'badge' => '<span class="right badge badge-danger">New</span>',
+                        'items' => [
+                            ['label' => 'Список опросов', 'url' => ['/manager/inquirer/index'], 'iconStyle' => 'far'],
+                            ['label' => 'Создать', 'url' => ['/manager/inquirer/create'], 'iconStyle' => 'far'],
+                        ]
+                    ],
+
                     ['label' => 'Статистика', 'icon' => 'th', 'url' => ['/manager/stats/index'],
                         'items' => [
                             ['label' => 'доска', 'url' => ['/manager/stats/index'], 'iconStyle' => 'far'],
                             ['label' => 'Авторы', 'url' => ['/manager/stats/authors'], 'iconStyle' => 'far']
                         ]
                     ],
-                    ['label' => 'Персоны','icon' => 'user', 'url' => ['/manager/person/'],'badge' => '<span class="right badge badge-danger">New</span>',
+                    ['label' => 'Персоны','icon' => 'user', 'url' => ['/manager/person/']
 					],
-                    ['label' => 'Авторы','icon' => 'user', 'url' => ['/manager/authors/']
+                    ['label' => 'Авторы','icon' => 'user', 'url' => ['/manager/authors/'],'badge' => '<span class="right badge badge-danger">New</span>'
 					],
                     ['label' => 'пользователи', 'icon' => 'user', 'url' => ['/user/admin/index'], 'visible' => Yii::$app->user->can('view_manage_users_page'),
 						'items' => [

+ 9 - 0
views/inquirer/index.php

@@ -0,0 +1,9 @@
+<?php
+/** @var yii\web\View $this */
+?>
+<h1>inquirer/index</h1>
+
+<p>
+    You may change the content of this page by modifying
+    the file <code><?= __FILE__; ?></code>.
+</p>

+ 1 - 1
views/news/view.php

@@ -131,7 +131,7 @@ $GLOBALS['type_long'] = ($model->type == 6); //лонгрид
             <?=$this->render("/layouts/breadcrumbs")?>
             <h1><?=$model->title?></h1>
             <p class="lead"><?=$model->lid?></p>
-            <p class="published_at"><?=$model->getPublishedNorm()?>, <?=$authorName?> <?= ($model->mark!="" && !is_null($model->mark)) ? \yii\helpers\Html::tag('span', $model->mark,['class'=>'float-right']) : ""?></p>
+            <p class="published_at"><?=$model->getPublishedNorm()?>, <?=$authorName?> <?= ($model->mark!="" && !is_null($model->mark)) ? \yii\helpers\Html::tag('span', 'erid: '.$model->mark,['class'=>'float-right']) : ""?></p>
             <p class="share_and_comment">
                 <a href="#comments" class="comments_btn">Комментировать</a>
                 <a onclick="Share.vkontakte('<?=Yii::$app->og->og_url?>','<?=addslashes(Yii::$app->og->og_title)?>','<?=Yii::$app->og->og_image?>','<?=str_replace( '"',"&quot; ",Yii::$app->og->og_description)?>')" href="#">