* @copyright (c), Thread */ class News extends aModule { public $name = 'news'; 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') . '/news/articles/', 'group' => Yii::getAlias('@uploads') . '/news/groups/', ]; return $item[$key] . $this->getBaseDirSuffix($model); } /** * @param $key * @param ActiveRecord $model * @return string */ public function getBaseUploadUrl($key, ActiveRecord $model) { $item = [ 'article' => '/uploads/news/articles/', 'group' => '/uploads/news/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']; } }