Blame view

common/modules/comment/readme 2.41 KB
7253a9a0   Yarik   Export fix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  1. Запускаем миграцию:
  php yii migrate --migrationPath=common/modules/comment/migrations
  2. Добавляем модуль в конфиг модуль:
  'modules' => [
      ...
      'artbox-comment' => [
          'class' => 'common\modules\comment\Module',
      ],
  ],
  3. Добавляем в конфиг переводы:
  'i18n' => [
      'translations' => [
          ...
          'artbox-comment' => [
              'class' => 'yii\i18n\PhpMessageSource',
              'basePath' => '@common/modules/comment/messages',
          ],
      ],
  ],
  4. Для управления добавляем в конфиги админки карту контроллера:
  'controllerMap' => [
      ...
      'artbox-comments' => [
          'class' => 'common\modules\comment\controllers\ManageController',
          'viewPath' => '@common/modules/comment/views/manage',
      ],
  ],
  5. В конфиге админке поменять пользователя на покупателя:
  'modules' => [
      ...
      'artbox-comment' => [
          'class' => 'common\modules\comment\Module',
          'userIdentityClass' => 'common\models\Customer',
      ],
  ],
  6. Вывод виджета:
  echo CommentWidget::widget([
      'model' => $product,
  ]);
  7. Добавляем в нужную модель методы:
  public function getComments() {
      return $this->hasMany(CommentModel::className(), ['entity_id' => 'product_id'])->where(['artbox_comment.entity' => self::className(), 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, 'artbox_comment.artbox_comment_pid' => NULL]);
  }
  /** Не обязательно для рейтинга  PG ONLY **/
      public function recalculateRating() {
          $average = $this->getComments()->joinWith('rating')->select(['average' => 'avg(artbox_comment_rating.value)::float'])->scalar();
          if(!$average) {
              $average = 0;
          }
          $averageRating = $this->averageRating;
          if(!empty($averageRating)) {
              $averageRating->value = $average;
          } else {
              $averageRating = new ProductToRating(['product_id' => $this->product_id, 'value' => $average]); // Заменить модель
          }
          if($averageRating->save()) {
              return true;
          } else {
              return false;
          }
      }
      public function getAverageRating() {
          return $this->hasOne(ProductToRating::className(), ['product_id' => 'product_id']); // Заменить модель
      }