Blame view

common/models/SitemapDynamic.php 2.82 KB
a42025b8   Yarik   Sitemap and slugb...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <?php
      namespace common\models;
      
      use Yii;
      use yii\helpers\ArrayHelper;
      use yii2tech\filedb\ActiveRecord;
      
      /**
       * Class SitemapDynamic
       *
       * @property int    $id
       * @property string $entity
       * @property bool   $status
       * @property float  $priority
9af79e71   Yarik   Sitemap and slugb...
15
       * @property string $frequency
a42025b8   Yarik   Sitemap and slugb...
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
       */
      class SitemapDynamic extends ActiveRecord
      {
          
          const STATUS_ENABLED = 1;
          const STATUS_DISABLED = 0;
          
          /**
           * @inheritdoc
           */
          public static function getDb()
          {
              return \Yii::$app->get('sitemapdb');
          }
          
          /**
           * @inheritdoc
           */
          public function attributes()
          {
              return [
                  'id',
                  'entity',
                  'status',
                  'priority',
9af79e71   Yarik   Sitemap and slugb...
41
                  'frequency',
a42025b8   Yarik   Sitemap and slugb...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
              ];
          }
          
          /**
           * @inheritdoc
           */
          public static function primaryKey()
          {
              return [ 'id' ];
          }
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'entity',
                          'status',
                          'priority',
9af79e71   Yarik   Sitemap and slugb...
64
                          'frequency',
a42025b8   Yarik   Sitemap and slugb...
65
66
67
68
69
70
71
72
73
74
75
76
                      ],
                      'required',
                  ],
                  [
                      [
                          'status',
                      ],
                      'boolean',
                  ],
                  [
                      [
                          'entity',
9af79e71   Yarik   Sitemap and slugb...
77
                          'frequency',
a42025b8   Yarik   Sitemap and slugb...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                      ],
                      'string',
                  ],
                  [
                      [
                          'priority',
                      ],
                      'double',
                      'min' => 0,
                      'max' => 1,
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
9af79e71   Yarik   Sitemap and slugb...
98
99
100
101
102
                  'id'        => Yii::t('core', 'ID'),
                  'entity'    => Yii::t('core', 'Model'),
                  'status'    => Yii::t('core', 'Status'),
                  'priority'  => Yii::t('core', 'Priority'),
                  'frequency' => Yii::t('core', 'Frequency'),
a42025b8   Yarik   Sitemap and slugb...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
              ];
          }
          
          /**
           * Find maximum ID value from SitemapStatic models
           */
          public static function max(): int
          {
              $models = self::find()
                            ->all();
              $array = ArrayHelper::getColumn($models, self::primaryKey()[ 0 ], false);
              if (empty( $array )) {
                  return 0;
              } else {
                  return max($array);
              }
          }
      }