Commit b5639b5902e17537defd8226903b7231b33c9086

Authored by Anastasia
1 parent 21346174

comment widget

views/artbox_comment_item.php
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 * @var mixed $key 9 * @var mixed $key
10 * @var int $index 10 * @var int $index
11 * @var ListView $widget 11 * @var ListView $widget
  12 + * @var string $display_name
12 */ 13 */
13 ?> 14 ?>
14 <div class="comments-wr"> 15 <div class="comments-wr">
@@ -27,8 +28,9 @@ @@ -27,8 +28,9 @@
27 </div> 28 </div>
28 <div class="user_name" itemprop="author"> 29 <div class="user_name" itemprop="author">
29 <?php 30 <?php
  31 + $nameField = $display_name;
30 if (!empty($model->customer)) { 32 if (!empty($model->customer)) {
31 - echo $model->customer->username; 33 + echo $model->customer->$nameField;
32 } else { 34 } else {
33 echo $model->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')'; 35 echo $model->username . ' (' . Yii::t('artbox-comment', 'Guest') . ')';
34 } 36 }
views/artbox_comment_list.php
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 * @var Model $model 15 * @var Model $model
16 * @var ActiveDataProvider $comments 16 * @var ActiveDataProvider $comments
17 * @var View $this 17 * @var View $this
  18 + * @var srring $display_name
18 */ 19 */
19 Pjax::begin(); 20 Pjax::begin();
20 if(( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != NULL) { 21 if(( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != NULL) {
@@ -25,6 +26,10 @@ @@ -25,6 +26,10 @@
25 'itemOptions' => $item_options, 26 'itemOptions' => $item_options,
26 'itemView' => $item_view, 27 'itemView' => $item_view,
27 'summary' => '', 28 'summary' => '',
  29 + 'viewParams' => [
  30 + 'display_name' => $display_name
  31 + ]
  32 +
28 ]); 33 ]);
29 Pjax::end(); 34 Pjax::end();
30 35
31 \ No newline at end of file 36 \ No newline at end of file
widgets/CommentWidget.php
@@ -24,6 +24,10 @@ @@ -24,6 +24,10 @@
24 */ 24 */
25 class CommentWidget extends Widget 25 class CommentWidget extends Widget
26 { 26 {
  27 + /**
  28 + * @var string what field is displayed in the user name
  29 + */
  30 + public $display_name = 'username';
27 31
28 /** 32 /**
29 * Model, to which comment attached 33 * Model, to which comment attached
@@ -400,6 +404,8 @@ @@ -400,6 +404,8 @@
400 'comments' => $comments, 404 'comments' => $comments,
401 'item_options' => $this->itemOptions, 405 'item_options' => $this->itemOptions,
402 'item_view' => $this->itemView, 406 'item_view' => $this->itemView,
  407 + 'display_name' => $this->display_name,
  408 +
403 ] 409 ]
404 ), 410 ),
405 $list_options 411 $list_options