Exemplo n.º 1
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Exemplo n.º 2
0
 public function getMaxContentCode($cpId, $content = 'song')
 {
     $cpObj = AdminCpModel::model()->findByPk($cpId);
     $limitCode = $cpObj['code'] + Yii::app()->params['cp_limit_content'];
     switch ($content) {
         case "video":
             $c = new CDbCriteria();
             $c->select = "code";
             $c->condition = "cp_id=:CPID";
             $c->params = array(':CPID' => $cpId);
             $c->order = "code DESC";
             $c->limit = 1;
             $video = AdminVideoModel::model()->find($c);
             $maxCode = isset($video['code']) ? $video['code'] : 0;
             //echo $maxCode; exit;
             if ($maxCode >= $limitCode) {
                 return false;
             } else {
                 if ($maxCode < $cpObj['code'] || $maxCode <= 0) {
                     return $cpObj['code'];
                 } else {
                     return $maxCode + 1;
                 }
             }
             break;
         case "ringtone":
             $c = new CDbCriteria();
             $c->select = "code";
             $c->condition = "cp_id=:CPID";
             $c->params = array(':CPID' => $cpId);
             $c->order = "code DESC";
             $c->limit = 1;
             $ringtone = AdminRingtoneModel::model()->find($c);
             $maxCode = isset($ringtone['code']) ? $ringtone['code'] : 0;
             if ($maxCode >= $limitCode) {
                 return false;
             } else {
                 if ($maxCode < $cpObj['code'] || $maxCode <= 0) {
                     return $cpObj['code'];
                 } else {
                     return $maxCode + 1;
                 }
             }
             break;
         case "song":
         default:
             $c = new CDbCriteria();
             $c->select = "code";
             $c->condition = "cp_id=:CPID";
             $c->params = array(':CPID' => $cpId);
             $c->order = "code DESC";
             $c->limit = 1;
             $song = AdminSongModel::model()->find($c);
             $maxCode = isset($song['code']) ? $song['code'] : 0;
             if ($maxCode >= $limitCode) {
                 return false;
             } else {
                 if ($maxCode < $cpObj['code'] || $maxCode <= 0) {
                     $code = $cpObj['code'];
                 } else {
                     $code = $maxCode + 1;
                 }
             }
             //check exist code
             if ($code >= $maxCode) {
                 $e = 0;
                 while ($e == 0) {
                     $sql = "SELECT count(*) FROM song WHERE code='{$code}'";
                     $count = Yii::app()->db->createCommand($sql)->queryScalar();
                     if ($count > 0) {
                         $code++;
                     } else {
                         $e++;
                     }
                 }
             }
             return $code;
             break;
     }
 }
Exemplo n.º 3
0
 public function actionRestore()
 {
     $songId = Yii::app()->request->getParam('song_id', 0);
     $reason = "restore";
     $result = new stdClass();
     $result->errorCode = 1;
     $result->message = "success";
     $result->completed = 0;
     $songs = ToolsSongModel::model()->getSongToRestore();
     /* echo '<pre>';print_r($songs);die('stop'); */
     $i = 0;
     if ($songs) {
         $song = $songs[0];
         $songId = $song['song_id'];
         $reason = $song['reason'];
         if ($songId > 0) {
             $connection = Yii::app()->db;
             $transaction = $connection->beginTransaction();
             try {
                 //UPDATE SONG_STATUS TO APPROVED
                 $sql1 = "\tUPDATE song_status t1\n\t\t\t\t\t\tSET t1.approve_status=" . AdminSongStatusModel::APPROVED . "\n\t\t\t\t\t\tWHERE t1.song_id = :song_id";
                 $command1 = $connection->createCommand($sql1);
                 $command1->bindParam(':song_id', $songId, PDO::PARAM_INT);
                 $res1 = $command1->execute();
                 // DELETE from song_delete
                 $sql2 = "DELETE FROM song_deleted WHERE song_id=:song_id";
                 $command2 = $connection->createCommand($sql2);
                 $command2->bindParam(':song_id', $songId, PDO::PARAM_INT);
                 $res2 = $command2->execute();
                 //update song
                 $songModel = AdminSongModel::model()->findByPk($songId);
                 $songModel->updated_time = date("Y-m-d H:i:s");
                 $songModel->save(false);
                 //.... other SQL executions
                 $transaction->commit();
                 $result->message = "Restore success {$songId}";
                 /* $log = new KLogger('HIDE_LOG', KLogger::INFO);
                 			$log->LogInfo("Hide LOG: |sql1:".$sql1.$songId." |sql2: ".$sql2.$reason, false); */
             } catch (Exception $e) {
                 $result->errorCode = 2;
                 $result->message = "Exception " . $e->getMessage();
                 $transaction->rollback();
             }
         } else {
             $result->errorCode = 1;
             $result->message = "Song Id Not Avaiable ({$songId})";
         }
         ToolsSongModel::model()->updateStatusRestore($song['id'], $result->errorCode);
     } else {
         $result->completed = 1;
         $result->message = "Completed";
     }
     $result->message .= "<br />";
     echo CJSON::encode($result);
     Yii::app()->end();
 }