public function actionViewRecommend()
 {
     header('Content-type: application/json');
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     $prod_id = Yii::app()->request->getParam("prod_id");
     if (!isset($prod_id) || is_null($prod_id)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PARAM_IS_INVALID);
         return;
     }
     $program = Program::model()->findByPk($prod_id);
     if ($program === null) {
         IjoyPlusServiceUtils::exportServiceError(Constants::OBJECT_NOT_FOUND);
         return;
     }
     $userid = Yii::app()->request->getParam("user_id");
     if (!isset($userid) || is_null($userid)) {
         $userid = Yii::app()->user->id;
     }
     $prod = ProgramUtil::exportProgramEntity($program);
     $reCom = Dynamic::model()->getDynamicByProd($userid, $prod_id, Constants::DYNAMIC_TYPE_RECOMMEND);
     if (isset($reCom) && !is_null($reCom)) {
         $prod['reason'] = $reCom->content_desc;
     }
     $comments = Comment::model()->getCommentsByProgram($prod_id, 10, 0);
     if (isset($comments) && is_array($comments)) {
         $commentTemps = array();
         foreach ($comments as $comment) {
             $commentTemps[] = IjoyPlusServiceUtils::transferComments($comment);
         }
         $prod['comments'] = $commentTemps;
     } else {
         $prod['comments'] = array();
     }
     $dynamic = Dynamic::model()->friendDynamicForProgram(Yii::app()->user->id, $prod_id, 10, 0);
     if (isset($dynamic) && is_array($dynamic)) {
         $prod['dynamics'] = $this->transferDynamics($dynamic);
     } else {
         $prod['dynamics'] = array();
     }
     $topics = Topic::model()->getRelatedTops($prod_id);
     if (isset($topics) && is_array($topics)) {
         $prod['topics'] = $topics;
     } else {
         $prod['topics'] = array();
     }
     IjoyPlusServiceUtils::exportEntity($prod);
 }
 function actionUnbindAccount()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     $source_type = Yii::app()->request->getParam("source_type");
     $userid = Yii::app()->user->id;
     if (IjoyPlusServiceUtils::validateThirdPartSource($source_type)) {
         $code = User::model()->unBindAccount($userid, $source_type);
         IjoyPlusServiceUtils::exportServiceError($code);
     } else {
         IjoyPlusServiceUtils::exportServiceError(Constants::THIRD_PART_SOURCE_TYPE_INVALID);
     }
 }
 function actionDel()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     $topic_id = Yii::app()->request->getParam("topic_id");
     if (!isset($topic_id) || is_null($topic_id)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PARAM_IS_INVALID);
         return;
     }
     $owner_id = Yii::app()->user->id;
     $topic = Topic::model()->findByPk($topic_id);
     if ($topic !== null) {
         if (isset($topic->t_userid) && !is_null($topic->t_userid) && $topic->t_userid === $owner_id) {
             if (Topic::model()->deleteTopic($topic_id)) {
                 User::model()->updateTopBDCount($owner_id, -1);
                 IjoyPlusServiceUtils::exportServiceError(Constants::SUCC);
             } else {
                 IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
             }
         } else {
             IjoyPlusServiceUtils::exportServiceError(Constants::NO_RIGHT);
         }
     } else {
         IjoyPlusServiceUtils::exportServiceError(Constants::OBJECT_NOT_FOUND);
     }
 }
 function actionReply()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     if (!IjoyPlusServiceUtils::checkCSRCToken()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::DUPLICAT_REQUEST);
         return;
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $thread_id = Yii::app()->request->getParam("thread_id");
         $parentComm = Comment::model()->findByPk($thread_id);
         if (isset($parentComm) && !is_null($parentComm)) {
             $model = new Comment();
             $model->status = Constants::OBJECT_APPROVAL;
             $model->create_date = new CDbExpression('NOW()');
             $model->comments = Yii::app()->request->getParam("content");
             $model->thread_id = Yii::app()->request->getParam("thread_id");
             $model->author_id = Yii::app()->user->id;
             $model->author_username = Yii::app()->user->getState("nickname");
             $model->author_photo_url = Yii::app()->user->getState("pic_url");
             $model->save();
             //add dynamic
             $dynamic = new Dynamic();
             $dynamic->author_id = Yii::app()->user->id;
             $dynamic->content_id = $thread_id;
             $dynamic->status = Constants::OBJECT_APPROVAL;
             $dynamic->create_date = new CDbExpression('NOW()');
             $dynamic->content_desc = $model->comments;
             $dynamic->dynamic_type = Constants::DYNAMIC_TYPE_COMMENT_REPLI;
             $dynamic->content_name = $parentComm->content_name;
             $dynamic->content_type = $parentComm->content_type;
             $dynamic->content_pic_url = $parentComm->content_pic_url;
             $dynamic->save();
             if ($parentComm->author_id !== Yii::app()->user->id) {
                 // add notify msg
                 $msg = new NotifyMsg();
                 $msg->author_id = $parentComm->author_id;
                 $msg->nofity_user_id = Yii::app()->user->id;
                 $msg->notify_user_name = Yii::app()->user->getState("nickname");
                 $msg->notify_user_pic_url = Yii::app()->user->getState("pic_url");
                 $msg->content_id = $thread_id;
                 $msg->content_desc = $model->comments;
                 $msg->content_type = $parentComm->content_type;
                 $msg->content_info = $parentComm->content_name;
                 $msg->created_date = new CDbExpression('NOW()');
                 $msg->status = Constants::OBJECT_APPROVAL;
                 $msg->notify_type = Constants::NOTIFY_TYPE_REPLIE_COMMENT;
                 $msg->save();
             }
         }
         $transaction->commit();
         IjoyPlusServiceUtils::exportServiceError(Constants::SUCC);
     } catch (Exception $e) {
         $transaction->rollback();
         IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
     }
 }
 public function actionRecommends()
 {
     header('Content-type: application/json');
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     $page_size = Yii::app()->request->getParam("page_size");
     $page_num = Yii::app()->request->getParam("page_num");
     if (!(isset($page_size) && is_numeric($page_size))) {
         $page_size = 10;
         $page_num = 1;
     } else {
         if (!(isset($page_num) && is_numeric($page_num))) {
             $page_num = 1;
         }
     }
     try {
         $recommends = Dynamic::model()->friendRecommends(Yii::app()->user->id, $page_size, $page_size * ($page_num - 1));
         if (isset($recommends) && !is_null($recommends) && is_array($recommends)) {
             IjoyPlusServiceUtils::exportEntity(array('recommends' => $recommends));
         } else {
             IjoyPlusServiceUtils::exportEntity(array('recommends' => array()));
         }
     } catch (Exception $e) {
         IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
     }
 }
 public function actionUpdateBGPicUrl()
 {
     header('Content-type: application/json');
     if (!Yii::app()->request->isPostRequest) {
         IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
         return;
     }
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     if (IjoyPlusServiceUtils::validateUserID()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID);
         return;
     }
     try {
         $url = Yii::app()->request->getParam("url");
         $validator = new CUrlValidator();
         if (!$validator->validateValue($url)) {
             IjoyPlusServiceUtils::exportServiceError(Constants::URL_INVALID);
         }
         $msgs = User::model()->updateBGPicUrl(Yii::app()->user->id, $url);
         IjoyPlusServiceUtils::exportServiceError(Constants::SUCC);
     } catch (Exception $e) {
         IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
     }
 }