public function actionUpload() { Yii::$app->response->format = Response::FORMAT_JSON; $result = []; $files = UploadedFile::getInstances(new File(), 'uploadedFiles'); foreach ($files as $index => $file) { $model = new File(); $model->uploadedFiles = [$file]; $model->user_id = Yii::$app->user->id; $model->storage = File::STORAGE_OS; $model->extension = $file->extension; $model->type = File::defineType($model->extension); if ($model->upload()) { $item = ['id' => $model->id, 'url' => $model->getUrl(), 'type' => $model->getMimeType()]; if ($releaseId = Yii::$app->request->get('rid')) { $release = Release::findOne($releaseId); if ($release && $release->artist->user_id == Yii::$app->user->id) { if ($model->type == $model::TYPE_IMAGE) { $cover = new Cover(['release_id' => $release->id, 'file_id' => $model->id, 'is_main' => false]); $cover->save(); $item['image_id'] = $cover->id; } elseif ($model->type == $model::TYPE_AUDIO) { $track = new Track(['release_id' => $release->id, 'original_name' => $file->baseName, 'number' => $release->getTracks()->count() + 1, 'file_id' => $model->id]); $track->save(); $item['track_id'] = $track->id; $item['comname'] = $track->getComname(); $item['number'] = $track->number; } } } if ($artistId = Yii::$app->request->get('aid')) { $photo = new Photo(['artist_id' => (string) $artistId, 'file_id' => $model->id, 'is_main' => false]); $artist = Artist::findOne($artistId); if ($artist && $artist->user_id == Yii::$app->user->id) { $photo->save(); $item['image_id'] = $photo->id; } } // if ($model->type == $model::TYPE_AUDIO) { // $getID3 = new getID3(); // $tags = $getID3->analyze($model->getPath(true))['tags']['id3v2']; // $item['meta'] = [ // 'title' => $tags['title'][0], // 'number' => explode('/', $tags['track_number'][0])[0], // 'disc' => explode('/', $tags['part_of_a_set'][0])[0], // 'lyric' => $tags['unsynchronised_lyric'][0], // 'info' => $tags['comment'][0], // ]; // } if ($model->type == $model::TYPE_AUDIO) { $item['meta'] = ['title' => $file->baseName, 'number' => $index + 1, 'disc' => '', 'lyric' => '', 'info' => '']; } $result[] = $item; } } return $result; }
/** * Lists all Release models. * @return mixed */ public function actionIndex() { $params = Yii::$app->request->queryParams; $artistId = $params['id']; $artist = Artist::findOne($artistId); if (!$artist) { throw new NotFoundHttpException(); } $params['ReleaseSearch']['artist_id'] = $artistId; $searchModel = new ReleaseSearch(); $dataProvider = $searchModel->search($params); $dataProvider->pagination->pageSize = 100; return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'artist' => $artist]); }
public function actionArtist() { $model = Artist::findOne(Yii::$app->request->post('pk', '')); $ownerId = $model->user_id; if (Yii::$app->request->post('name', '') == 'artist-tags') { $artistTags = (new \yii\db\Query())->select('tag_id')->from('artist_tag')->where(['artist_id' => $model->id])->column(); $requestTags = Yii::$app->request->post('value', []); foreach ($requestTags as $tagId) { if (!in_array($tagId, $artistTags)) { $tag = Tag::findOne($tagId); if ($tag) { $model->link('tags', $tag); } } } foreach ($artistTags as $tagId) { if (!in_array($tagId, $requestTags)) { Yii::$app->db->createCommand()->delete('artist_tag', ['artist_id' => $model->id, 'tag_id' => $tagId])->execute(); } } return null; } return self::update($model, $ownerId); }
/** * Finds the Artist model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Artist the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Artist::findOne($id)) !== null) { if ($model->user_id != Yii::$app->user->id) { throw new ForbiddenHttpException(); } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }