public function actionDel() { $id = Yii::app()->request->getParam('id'); $listsong = PlaylistSongModel::model()->deleteAll('playlist_id = :pid', array(':pid' => $id)); try { $res = PlaylistModel::model()->findByPk($id); try { $res->delete(); echo '1'; } catch (Exception $ex) { echo '0'; } } catch (Exception $ex1) { echo '0'; } Yii::app()->end(); }
public function actionAddNewPlaylist() { $name = CHtml::encode(Yii::app()->request->getParam('name', 0)); $song_id = (int) Yii::app()->request->getParam('songId', 0); $phone = Yii::app()->user->getState('msisdn'); if (strlen($name) >= 80) { echo "3"; } else { $playlist_name = ucwords($name); //if( !preg_match('/^[0-9a-zA-Z_ ]+$/', $playlist_name) ){//ten playlistk dc su dung ky tu dac biet if (preg_match('/[\'\\/~`\\!@#\\$%\\^&\\*\\(\\)_\\-\\+=\\{\\}\\[\\]\\|;:"\\<\\>,\\.\\?\\\\]/', $playlist_name)) { echo '4'; $this->layout = false; Yii::app()->end(); } $list = PlaylistModel::model()->findAllByAttributes(array('msisdn' => $phone)); $listPl = CHtml::listData($list, 'name', 'name'); if (in_array($playlist_name, $listPl, true)) { echo "1"; // trung ten } else { $model = new PlaylistModel(); $model->name = $playlist_name; $model->url_key = Common::makeFriendlyUrl($name); $model->msisdn = Formatter::formatPhone($phone); $model->created_time = new CDbExpression('NOW()'); if ($model->insert()) { // check xem bai hat do da co chua? // $song_in_pl = WapPlaylistSongModel::model()->findByAttributes(array('playlist_id'=>$model->id,'song_id'=>$song_id)); $songInPl = PlaylistSongModel::model()->findAllByAttributes(array("playlist_id" => $model->id)); $listsong = CHtml::listData($songInPl, 'song_id', 'song_id'); if (!$listsong) { $playlist_song = new PlaylistSongModel(); $playlist_song->playlist_id = $model->id; $playlist_song->song_id = $song_id; $playlist_song->status = '1'; $ret = $playlist_song->save(); if ($ret) { echo '2'; } } } else { echo '0'; } } } $this->layout = false; Yii::app()->end(); }