Наследование: extends Illuminate\Database\Eloquent\Model, use trait App\Traits\CanFilterByUser
Пример #1
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => auth()->user()->is_admin ? Setting::pluck('value', 'key')->all() : [], 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'currentUser' => auth()->user(), 'useLastfm' => Lastfm::used(), 'useYouTube' => YouTube::enabled(), 'allowDownload' => config('koel.download.allow'), 'cdnUrl' => app()->staticUrl(), 'currentVersion' => Application::VERSION, 'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION]);
 }
Пример #2
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => Setting::all()->lists('value', 'key'), 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'user' => auth()->user()]);
 }
Пример #3
0
 /**
  * Delete a playlist.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function destroy($id)
 {
     // This can't be put into a Request authorize(), due to Laravel(?)'s limitation.
     if (Playlist::findOrFail($id)->user_id !== auth()->user()->id) {
         abort(403);
     }
     Playlist::destroy($id);
     return response()->json();
 }
Пример #4
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => Setting::lists('value', 'key')->all(), 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'currentUser' => auth()->user(), 'useLastfm' => env('LASTFM_API_KEY') && env('LASTFM_API_SECRET'), 'currentVersion' => Application::VERSION, 'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION]);
 }
Пример #5
0
 public function testCreatePlaylist()
 {
     $user = factory(User::class)->create();
     // Let's create a playlist with 3 songs
     $songs = Song::orderBy('id')->take(3)->get();
     $this->postAsUser('api/playlist', ['name' => 'Foo Bar', 'songs' => $songs->pluck('id')->toArray()], $user);
     $this->seeInDatabase('playlists', ['user_id' => $user->id, 'name' => 'Foo Bar']);
     $playlist = Playlist::orderBy('id', 'desc')->first();
     foreach ($songs as $song) {
         $this->seeInDatabase('playlist_song', ['playlist_id' => $playlist->id, 'song_id' => $song->id]);
     }
     $this->getAsUser('api/playlist', $user)->seeJson(['id' => $playlist->id, 'name' => 'Foo Bar']);
 }
Пример #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPlaylist()
 {
     return $this->hasOne(Playlist::className(), ['id' => 'playlist_id']);
 }
Пример #7
0
 public function actionChoosePlaylist()
 {
     $playlists = Playlist::find();
     $dataProvider = new ActiveDataProvider(['query' => $playlists]);
     return $this->render('playlists', ['playlists' => $dataProvider]);
 }
Пример #8
0
 /**
  * Gets all playlists by the current user.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     return response()->json(Playlist::byCurrentUser()->orderBy('name')->with('songs')->get());
 }
Пример #9
0
    <?php 
//var_dump($pl); exit;
?>
    <?php 
echo GridView::widget(['dataProvider' => $items, 'filterModel' => $searchModel, 'columns' => ['id', 'title', 'tags', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete} {update} ', 'buttons' => ['delete' => function ($url, $model) {
    return Html::a('<span class="glyphicon glyphicon-minus"></span>', Url::toRoute(['pl-remove', 'id' => $model->id]), ['title' => Yii::t('yii', 'Удалить плейлиста'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0']);
}, 'update' => function ($url, $model) use($pl) {
    //var_dump(\Yii::$app->controller); exit;
    return Html::a('<span class="glyphicon glyphicon-plus"></span>', Url::toRoute(['pl-add', 'id' => $model->id, 'pl' => $pl]), ['title' => Yii::t('yii', 'Добавить в плейлист'), 'data-method' => 'post', 'data-pjax' => '0']);
}]]]]);
?>

</div>

<div class="col-sm-6 col-md-6 ">
    <h1 class="page-header"><?php 
echo Html::a(\app\models\Playlist::find()->where(['id' => $pl])->one()->name, Url::toRoute(['pl-sort', 'id' => $pl]), ['title' => 'Создать очередь']);
?>
</h1>
    <?php 
//var_dump($pl); exit;
?>
    <?php 
echo GridView::widget(['dataProvider' => $new_items, 'columns' => ['id', 'title', 'tags', ['attribute' => 'radio_que', 'value' => function ($model, $key, $index, $column) {
    //  var_dump($model); var_dump($key); exit;
    return Html::input('text', 'radio_que', $model->radio_que, ['id' => 'que' . '_' . $model->id, 'class' => 'form-control']) . Html::button('Изменить', ['id' => 'change-que' . '_' . $model->id, 'onClick' => "changeQue({$model->id})", 'class' => 'btn btn-primary']) . Html::tag('p', $model->id, ['style' => 'display: none', 'id' => 'req' . '_' . $model->id]);
}, 'format' => 'raw'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}  ', 'buttons' => ['delete' => function ($url, $model) use($pl) {
    return Html::a('<span class="glyphicon glyphicon-minus"></span>', Url::toRoute(['pl-remove', 'id' => $model->id, 'pl' => $pl]), ['title' => Yii::t('yii', 'Удалить из плейлиста'), 'data-method' => 'post', 'data-pjax' => '0']);
}]]]]);
?>
</div>