Blame view

common/modules/calendar/Calendar.php 1.73 KB
d1f8bd40   Alexey Boroda   first commit
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
65
66
67
68
69
70
71
72
73
74
75
76
  <?php
  
  namespace common\modules\calendar;
  
  use Yii;
  use thread\app\base\models\ActiveRecord;
  //
  use thread\app\base\module\abstracts\Module as aModule;
  
  /**
   * Class Calendar
   *
   * @package thread\modules\calendar
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class Calendar extends aModule
  {
      public $name = 'calendar';
      public $translationsBasePath = __DIR__ . '/messages';
      public $configPath = __DIR__ . '/config.php';
  
      /**
       * @return null|object
       * @throws \yii\base\InvalidConfigException
       */
      public static function getDb()
      {
          return Yii::$app->get('db-core');
      }
  
      /**
       * @return mixed
       */
      public function getFormatDate()
      {
          return $this->params['format']['date'];
      }
  
      /**
       * @param $key
       * @param ActiveRecord $model
       * @return string
       */
      public function getBaseUploadPath($key, ActiveRecord $model)
      {
          $item = [
              'article' => Yii::getAlias('@uploads') . '/calendar/articles/',
              'group' => Yii::getAlias('@uploads') . '/calendar/groups/',
          ];
          return $item[$key] . $this->getBaseDirSuffix($model);
      }
  
      /**
       * @param $key
       * @param ActiveRecord $model
       * @return string
       */
      public function getBaseUploadUrl($key, ActiveRecord $model)
      {
          $item = [
              'article' => '/uploads/calendar/articles/',
              'group' => '/uploads/calendar/groups/',
          ];
          return $item[$key] . $this->getBaseDirSuffix($model);
      }
  
      /**
       * @param ActiveRecord $model
       * @return string
       */
      public function getBaseDirSuffix(ActiveRecord $model)
      {
          return date('Y/m/d', $model['created_at']) . '/' . $model['id'];
      }
  }