123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- use app\models\base\Comments;
- use app\helpers\Tree;
- /**
- * @var $model \app\models\News
- */
- if($model->comments!="Y") return "";
- $query = $model->getCommentsAll()->orderBy(['created_at'=>SORT_ASC])->andWhere(['visible'=>'Y']);
- ?>
- <h2 class="comments-title">
- Комментарии <sup><small><?=$query->count()?></small></sup>
- </h2>
- <div class="comments-list">
- <?
- $rows = $query->all();
- $items = [];
- $islike = Comments::getUserLike($model->id);
- if( is_array($islike) ){
- $islike = array_flip($islike);
- }else{
- $islike = array();
- }
- foreach( $rows as $item ){
- $citem = [];
- $citem['id'] = $item->id;
- if( isset($items[$item->parent_id]) ){
- $citem['parent_id'] = $item->parent_id;
- }else{
- // потеряный предок перенести в корень но можно и убить
- $citem['parent_id'] = 0;
- }
- $citem['children'] = 0;
- $item->islike = isset($islike[$item->id]);
- $citem['item'] = $item;
- $items[$item->id] = $citem;
- }
- // yii\helpers\VarDumper::dump($items,2);;
- $otree = new Tree();
- $tree = $otree->buildTree($items);
- $otree->drawTree($tree, $this);
- /*
- foreach( $rows as $item ){
- echo $this->render('_item', [
- 'model' => $item,
- ]);
- }
- */
- /*
- \yii\widgets\ListView::widget([
- "dataProvider" => new \yii\data\ActiveDataProvider([
- "query"=>$query,
- "pagination" =>[
- "pageSize"=>0
- ],
- ]),
- 'options' => [
- 'tag' => "ul",
- 'class' => 'list-wrapper',
- 'id' => 'list-wrapper',
- ],
- "itemOptions"=>[
- "tag"=>"li"
- ],
- "itemView" => function ($model, $key, $index, $widget) {
- return $this->render('_item', [
- 'model' => $model,
- 'key' => $key,
- 'index' => $index,
- 'widget' => $widget,
- ]);},
- "layout" => "{items}"
- ]);*/
- ?>
- </div>
- <?
- if( (new Comments())::$conf->isActive() ){
- ?>
- <div class="comments-form" id="commentsForm">
- <?=\app\widgets\Alert::widget()?>
- <form method="post">
- <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
- <input type="hidden" name="parent_id" value="0" id="commentParentId">
- <div class="form-group">
- <div class="row">
- <label for="fakename" class="control-label ml-4">Имя</label>
- <div class="col-sm mb-3"><input type="text" class="form-control" name="fakename" id="fakename" value="<?=Yii::$app->request->post("fakename")?>" maxlength="30"></div>
- </div>
- <textarea class="form-control" name="message" id="commentFormTextarea" cols="30" rows="5" aria-label="Сообщение"><?=Yii::$app->request->post("message")?></textarea>
- </div>
- <div class="form-group">
- <div class="">
- <?php
- $a = rand(1,9);
- $b = rand(1,9);
- $answer = $a + $b;
- Yii::$app->session->setFlash('capcha_a',$a);
- Yii::$app->session->setFlash('capcha_b',$b);
- ?>
- <label for="capcha">Решите пример: <i style="opacity: 0;">1</i><?=$a?><i style="opacity: 0;">0</i>+<i style="opacity: 0;">2</i><?=$b?><i style="opacity: 0;">0</i>=</label>
- <input type="text" name="capcha" style="outline: none;border: 1px solid #212529;width: 25px;" aria-label="capcha">
- </div>
- <button type="submit" class="btn btn-primary">Отправить</button>
- </div>
- </form>
- </div>
- <script>
- window.answer = function (elem){
- const author = elem.parentNode.parentNode.parentNode.dataset.author;
- const time = elem.parentNode.parentNode.parentNode.dataset.time;
- const parentId = elem.parentNode.parentNode.parentNode.dataset.id;
- const message = $(elem.parentNode.parentNode).find('p:not(.text-muted)').html().replace(/<span>.*<\/span>\n?/m, '').substring(0,60);
- let text = '[[' + author + " ("+ time +") " + message + "... ]]\n";
- $("#commentFormTextarea").html(text).focus()[0].setSelectionRange(text.length + 2, text.length+ 2);
- $("#commentParentId").val(parentId);
- }
- window.clike = function (g,id,el){
- $('#comment-'+id+' .btnlike').addClass('disabled').attr('aria-disabled',true);
- t = Number( $( '#cnt_'+id ).text() );
- $( '#cnt_'+id ).text(t+g);
- $.post( "clike", { id:id, grd:g, <?=Yii::$app->request->csrfParam?>:'<?=Yii::$app->request->csrfToken?>', nid:<?=$model->id?>}, function( data ) {
- console.log(data);
- });
- }
- </script>
- <?
- }
|