Пример #1
0
 public function actionIndex($id)
 {
     $model = File::findOne($id);
     if ($model) {
         $model->updateCounters(['downloads' => 1]);
         Yii::$app->response->sendFile(Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . $model->file);
     } else {
         throw new \yii\web\NotFoundHttpException(Yii::t('easyii/file/api', 'File not found'));
     }
 }
Пример #2
0
 public function dbInstall()
 {
     $db = Yii::$app->db;
     $tableOptions = null;
     if ($db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM';
     }
     $db->createCommand()->createTable(File::tableName(), ['file_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'file' => Schema::TYPE_STRING . '(255) NOT NULL', 'size' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'downloads' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER], $tableOptions)->execute();
     $db->createCommand()->createIndex('slug', File::tableName(), 'slug', true)->execute();
 }
Пример #3
0
 private function findFile($id_slug)
 {
     //aslinya $file = FileModel::find()->where(['or', 'file_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one();
     if (is_integer($id_slug)) {
         $file = FileModel::find()->where('file_id=:id_slug', [':id_slug' => $id_slug])->one();
     } else {
         $file = FileModel::find()->where('slug=:id_slug', [':id_slug' => $id_slug])->one();
     }
     return $file ? new FileObject($file) : null;
 }
 public function insertFiles()
 {
     if (File::find()->count()) {
         return '`<b>' . File::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . File::tableName() . '`')->query();
     (new File(['title' => 'Price list', 'file' => '/uploads/files/example.csv', 'size' => 104]))->save();
     return 'File data inserted.';
 }
Пример #5
0
 public function down()
 {
     $this->dropTable(models\Admin::tableName());
     $this->dropTable(models\LoginForm::tableName());
     $this->dropTable(models\Module::tableName());
     $this->dropTable(models\Photo::tableName());
     $this->dropTable(models\Setting::tableName());
     $this->dropTable(Carousel::tableName());
     $this->dropTable(catalog\models\Category::tableName());
     $this->dropTable(catalog\models\Item::tableName());
     $this->dropTable(article\models\Category::tableName());
     $this->dropTable(article\models\Item::tableName());
     $this->dropTable(Feedback::tableName());
     $this->dropTable(File::tableName());
     $this->dropTable(gallery\models\Category::tableName());
     $this->dropTable(Guestbook::tableName());
     $this->dropTable(News::tableName());
     $this->dropTable(Page::tableName());
     $this->dropTable(Subscriber::tableName());
     $this->dropTable(History::tableName());
     $this->dropTable(Text::tableName());
 }
Пример #6
0
 public function actionDelete($id)
 {
     if ($model = File::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/file', 'File deleted'));
 }
Пример #7
0
 private function findFile($id_slug)
 {
     $file = FileModel::find()->where(['or', 'file_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one();
     return $file ? new FileObject($file) : null;
 }