/** * 个人歌单 * @param $userId * @return array */ public function personalSongKingdomByUserId($userId) { $query = SongKingdom::find()->andWhere(['created_by' => $userId]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return ['models' => $models, 'pages' => $pages, 'userCreadedBy' => User::find()->andWhere(['id' => $userId])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $userId])->asArray()->one()]; }
public function search($params) { $query = (new Query())->select('a.*')->from(SongKingdom::tableName() . ' as a'); $this->load($params); if (!$this->validate()) { $query->where('0=1'); } else { $query->where('1=1'); $query->andFilterWhere(['id' => $this->id, 'song_num' => $this->song_num, 'fav_count' => $this->fav_count, 'share_count' => $this->share_count, 'download_count' => $this->download_count, 'comment_count' => $this->comment_count, 'play_count' => $this->play_count, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'desc', $this->desc])->andFilterWhere(['like', 'privacy', $this->privacy])->andFilterWhere(['like', 'can_reply', $this->can_reply])->andFilterWhere(['like', 'icon', $this->icon])->andFilterWhere(['like', 'cover', $this->cover]); } $sql = $query->createCommand()->getRawSql(); $countQuery = $query->select('count(*)'); $count = $countQuery->createCommand()->queryScalar(); $defaultOrder = ['created_at' => SORT_DESC]; if (!empty($params['orderField'])) { $defaultOrder = [$params['orderField'] => $params['orderDirection'] == 'asc' ? SORT_ASC : SORT_DESC]; } $dataProvider = new SqlDataProvider(['sql' => $sql, 'totalCount' => $count, 'sort' => ['defaultOrder' => $defaultOrder, 'attributes' => array_values($this->attributes())], 'pagination' => ['pageSize' => 20, 'page' => isset($params['pageNum']) ? $params['pageNum'] - 1 : '0']]); return $dataProvider; }
public function getUserLable($userId) { // TODO: Implement getUserLable() method. return SongKingdom::find()->andWhere(['created_by' => $userId])->all(); }
/** * 保存歌单 */ public function actionSave() { try { $post = Yii::$app->request->post(); $id = isset($post['song_kingdom_id']) ? $post['song_kingdom_id'] : ''; if (isset($_FILES['imageFile'])) { $resultUpload = $this->upload($_FILES['imageFile']); } if (!empty($id)) { $model = $this->findModel($id); } else { $model = new SongKingdom(); } if ($model->load($post)) { if (!empty($resultUpload)) { $model->cover = $resultUpload['cover']; $model->icon = $resultUpload['icon']; } if ($model->save()) { $result = ['statusCode' => '200', 'message' => '操作成功', 'navTabId' => 'music_song_kingdom_index_id', 'forwardUrl' => '', 'callbackType' => 'closeCurrent']; echo Json::encode($result); exit; } } $firstError = $model->getFirstError(); if (!empty($firstError)) { throw new \Exception($model->getFirstError()); } } catch (\Exception $exp) { $message = ''; $message .= $exp->getMessage(); $result = ['statusCode' => '300', 'message' => $message, 'navTabId' => 'music_song_kingdom_index_id', 'forwardUrl' => '', 'callbackType' => '']; echo Json::encode($result); exit; } }
/** * Finds the SongKingdom model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return SongKingdom the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SongKingdom::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing Song model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $songKingdomModel = SongKingdom::findOne($model->song_kingdom_id); return $this->render('songUpdate', ['model' => $model, 'songKingdomModel' => $songKingdomModel]); }