Blame view

common/models/SitemapStatic.php 2.4 KB
a42025b8   Yarik   Sitemap and slugb...
1
2
3
4
5
6
7
8
9
10
11
12
13
  <?php
      namespace common\models;
      
      use Yii;
      use yii\helpers\ArrayHelper;
      use yii2tech\filedb\ActiveRecord;
      
      /**
       * Class SitemapStatic
       *
       * @property int    $id
       * @property string $url
       * @property float  $priority
9af79e71   Yarik   Sitemap and slugb...
14
       * @property string $frequency
a42025b8   Yarik   Sitemap and slugb...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
       */
      class SitemapStatic extends ActiveRecord
      {
          /**
           * @inheritdoc
           */
          public static function getDb()
          {
              return \Yii::$app->get('sitemapdb');
          }
          
          /**
           * @inheritdoc
           */
          public function attributes()
          {
              return [
                  'id',
                  'url',
                  'priority',
9af79e71   Yarik   Sitemap and slugb...
35
                  'frequency',
a42025b8   Yarik   Sitemap and slugb...
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
65
66
67
68
69
70
              ];
          }
          
          /**
           * @inheritdoc
           */
          public static function primaryKey()
          {
              return [ 'id' ];
          }
          
          /**
           * @inheritdoc
           */
          public function rules()
          {
              return [
                  [
                      [
                          'url',
                          'priority',
                      ],
                      'required',
                  ],
                  [
                      [
                          'priority',
                      ],
                      'double',
                      'min' => 0,
                      'max' => 1,
                  ],
                  [
                      [
                          'url',
9af79e71   Yarik   Sitemap and slugb...
71
                          'frequency',
a42025b8   Yarik   Sitemap and slugb...
72
73
74
75
76
77
78
79
80
81
82
83
                      ],
                      'string',
                  ],
              ];
          }
          
          /**
           * @inheritdoc
           */
          public function attributeLabels()
          {
              return [
9af79e71   Yarik   Sitemap and slugb...
84
85
86
87
                  'id'        => Yii::t('core', 'ID'),
                  'url'       => Yii::t('core', 'Url'),
                  'priority'  => Yii::t('core', 'Priority'),
                  'frequency' => Yii::t('core', 'Frequency'),
a42025b8   Yarik   Sitemap and slugb...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
              ];
          }
          
          /**
           * 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);
              }
          }
      }