public function delete($deleteFiles = false) { if ($deleteFiles) { $this->deleteFiles(); } return parent::delete(); }
/** * * @param int $surveyId * @param string $scenario * @return Response Description */ public static function create($surveyId, $scenario = 'insert') { return parent::create($surveyId, $scenario); }
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); }
public function createComments() { $transaction = Yii::app()->db->beginTransaction(); try { if ($this->save()) { $program = CacheManager::getProgramVOByID($this->content_id); Program::model()->incCommentCount($this->content_id); if ($program !== null) { // var_dump(($program->name)); $dynamic = new Dynamic(); $dynamic->author_id = $this->author_id; $dynamic->content_id = $program->id; $dynamic->status = Constants::OBJECT_APPROVAL; $dynamic->create_date = new CDbExpression('NOW()'); $dynamic->content_desc = $this->comments; $dynamic->content_type = $program->pro_type; $dynamic->content_name = $program->name; $dynamic->dynamic_type = Constants::DYNAMIC_TYPE_COMMENTS; $dynamic->content_pic_url = $program->poster; $dynamic->save(); $recommendOwnerId = Dynamic::model()->getRecommendOwnsForProd($this->content_id); if (isset($recommendOwnerId) && is_array($recommendOwnerId)) { foreach ($recommendOwnerId as $id) { if ($id['author_id'] !== Yii::app()->user->id) { // add notify msg $msg = new NotifyMsg(); $msg->author_id = $id['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 = $program->id; $msg->content_info = $program->name; $msg->content_type = $program->pro_type; $msg->created_date = new CDbExpression('NOW()'); $msg->status = Constants::OBJECT_APPROVAL; $msg->notify_type = Constants::NOTIFY_TYPE_COMMENT; $msg->content_desc = $this->comments; $msg->save(); } } } } $transaction->commit(); return true; } else { $transaction->commit(); return false; } } catch (Exception $e) { $transaction->rollback(); return false; } }
public function focusDynamic($params = array()) { extract($params); if (isset($user_id) && $user_id) { // $obj = Dynamic::model()->with('focus')->findAll('user_id=:user_id and is_focus=:focus', array(':user_id' => $user_id, ':focus' => '1')); $obj = Dynamic::model()->getFocusDynamic($user_id); if ($obj) { //获取用户信息 $focus_users = $this->getFocus($user_id); $dynamic = array(); foreach ($obj as $key => $val) { $user_info = $focus_users[$val->focus->focus_id]; if ($user_info) { $image = explode(',', $val->dy_images); $images = array(); if ($image) { foreach ($image as $k => $v) { $images[] = Yii::app()->params['qiniu']['host'] . $v; } } $dynamic[$key] = array('id' => $val->dy_id, 'content' => $val->dy_content, 'images' => $images, 'num' => $val->dy_agree, 'time' => $val->gmt_created); $dynamic[$key]['logo'] = Yii::app()->params['qiniu']['host'] . $user_info['image']; $dynamic[$key]['nickname'] = $user_info['user_name']; $dynamic[$key]['url'] = 'www.baidu.com'; } } if ($dynamic) { $ret = $this->notice('OK', 0, '成功', $dynamic); } else { $ret = $this->notice('OK', 0, '暂无数据', []); } } else { $ret = $this->notice('OK', 0, '暂无数据', []); } } else { //$ret = $this->notice('ERR', 301, '缺少参数', []); $obj = Dynamic::model()->findAll(array('order' => 'gmt_created desc', 'limit' => '100')); $dynamic = array(); if ($obj) { //user $users = User::model()->loadUsers(); $alliances = Alliance::model()->loadAlliances(); $stores = Store::model()->loadStores(); foreach ($obj as $key => $val) { if (!$val->dy_type) { $user = $users[$val->dy_user]; if ($user) { $dynamic[$key]['logo'] = Yii::app()->params['qiniu']['host'] . $user['image']; $dynamic[$key]['nickname'] = $user['name']; } else { continue; } } else { if ($val->dy_type == 1) { $alliance = $alliances[$val->dy_user]; if ($alliance) { $dynamic[$key]['logo'] = Yii::app()->params['qiniu']['host'] . $alliance['image']; $dynamic[$key]['nickname'] = $alliance['name']; } else { continue; } } else { if ($val->dy_type == 2) { $store = $stores[$val->dy_user]; if ($store) { $dynamic[$key]['logo'] = Yii::app()->params['qiniu']['host'] . $store['image']; $dynamic[$key]['nickname'] = $store['name']; } else { continue; } } } } $image = explode(',', $val->dy_images); $images = array(); if ($image) { foreach ($image as $k => $v) { $images[] = Yii::app()->params['qiniu']['host'] . $v; } } $dynamic[$key] = array('id' => $val->dy_id, 'content' => $val->dy_content, 'images' => $images, 'num' => $val->dy_agree, 'time' => $val->gmt_created); $dynamic[$key]['url'] = 'www.baidu.com'; } if ($dynamic) { $ret = $this->notice('OK', 0, '成功', $dynamic); } else { $ret = $this->notice('OK', 0, '暂无数据', []); } } else { $ret = $this->notice('OK', 0, '暂无数据', []); } } return $ret; }
public function followFriends($friends) { if (isset($friends) && is_array($friends)) { $transaction = Yii::app()->db->beginTransaction(); try { $userid = Yii::app()->user->id; $count = 0; foreach ($friends as $id) { if ($id === $userid) { continue; } $user = User::model()->findByPk($id); if (isset($user) && !is_null($user)) { $friendt = $this->getFriend($userid, $id); if (!(isset($friendt) && !is_null($friendt) && $friendt->status == Constants::OBJECT_APPROVAL)) { if (isset($friendt) && !is_null($friendt)) { $friendt->status = Constants::OBJECT_APPROVAL; $friendt->save(); } else { $friend = new Friend(); $friend->author_id = $userid; $friend->friend_id = $id; $friend->friend_photo_url = $user->user_photo_url; $friend->friend_username = $user->nickname; $friend->create_date = new CDbExpression('NOW()'); $friend->status = Constants::OBJECT_APPROVAL; $friend->save(); } $count++; $user->fan_number = $user->fan_number + 1; $user->save(); //add dynamic $dynamic = new Dynamic(); $dynamic->author_id = $userid; $dynamic->content_id = $id; $dynamic->status = Constants::OBJECT_APPROVAL; $dynamic->create_date = new CDbExpression('NOW()'); $dynamic->content_name = $user->nickname; $dynamic->dynamic_type = Constants::DYNAMIC_TYPE_FOLLOW; $dynamic->content_pic_url = $user->user_photo_url; $dynamic->save(); //ADD NOTIFY MSG $msg = new NotifyMsg(); $msg->author_id = $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->created_date = new CDbExpression('NOW()'); $msg->status = Constants::OBJECT_APPROVAL; $msg->notify_type = Constants::NOTIFY_TYPE_FOLLOW; $msg->save(); } } } if ($count > 0) { User::model()->updateFollowUserCount($userid, $count); } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollback(); return false; } } return true; }
public function save($runValidation = true, $attributes = null) { $beforeTokenSave = new PluginEvent('beforeTokenSave'); $beforeTokenSave->set('model', $this); $beforeTokenSave->set('iSurveyID', $this->dynamicId); App()->getPluginManager()->dispatchEvent($beforeTokenSave); return parent::save($runValidation, $attributes); }
public function actionChange() { $id = $this->_get('id'); if ($id) { $model = Dynamic::model()->findByPk($id); if ($_POST['Dynamic']) { $accessKey = Yii::app()->params['qiniu']['accessKey']; $secretKey = Yii::app()->params['qiniu']['secretKey']; $auth = new Auth($accessKey, $secretKey); $bucket = 'urtime1'; $token = $auth->uploadToken($bucket); $uploadMgr = new UploadManager(); $_POST['Dynamic']['dy_type'] = 2; if ($_FILES['upImage']['name'] != null) { $images = $this->setImageInformation($_FILES, $token, $uploadMgr); if ($images) { //$images_str = implode(',',$images); $_POST['Dynamic']['dy_images'] = json_encode($images); //$images_str; } } $model->attributes = $_POST['Dynamic']; if ($model->validate() && $model->save()) { //$this->redirect('site/index'); Yii::app()->user->setFlash('dynamic', '修改成功'); // Yii::app()->end(); $this->redirect(array('/dynamic/index')); } } $images = array(); if ($model->dy_images) { $image = json_decode($model->dy_images); foreach ($image as $key => $val) { $images[] = Yii::app()->params['qiniu']['host'] . $val; } } $stores = Store::model()->getName(); $this->render('change', ['model' => $model, 'images' => $images, 'stores' => $stores]); } else { $this->redirect(array('/site/index')); } }
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 agree($params = array()) { extract($params); if (isset($id) && $id && isset($user_id) && $user_id) { $cache_ext = Yii::app()->cache_ext; if (!$cache_ext->hget('Dynamic.' . $id, $user_id)) { $model = Dynamic::model()->findByPk($id); if ($model) { $user = array('dy_agree' => $model->dy_agree + 1); $model->attributes = $user; if ($model->save() && $model->validate()) { $cache_ext->hset('Dynamic.' . $id, $user_id, 1); $ret = $this->notice('OK', 0, '成功', []); } else { $ret = $this->notice('ERR', 307, '操作数据错误', []); } } else { $ret = $this->notice('ERR', 306, '获取不到数据', []); } } else { $ret = $this->notice('ERR', 305, '已经点赞过了', []); } } else { $ret = $this->notice('ERR', 301, '缺少关键参数', []); } return $ret; }
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 actionSupports() { header('Content-type: application/json'); if (!IjoyPlusServiceUtils::validateAPPKey()) { IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID); return; } $userid = Yii::app()->request->getParam("userid"); if (!isset($userid) || is_null($userid)) { if (IjoyPlusServiceUtils::validateUserID()) { IjoyPlusServiceUtils::exportServiceError(Constants::USER_ID_INVALID); return; } $userid = Yii::app()->user->id; } $page_size = Yii::app()->request->getParam("page_size"); $page_num = Yii::app()->request->getParam("page_num"); $vodType = Yii::app()->request->getParam("vod_type"); 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 { if ($vodType === null || $vodType === '') { $favorities = Dynamic::model()->searchUserSupports($userid, $page_size, $page_size * ($page_num - 1)); } else { $favorities = Dynamic::model()->searchUserSupportsVodType($userid, $page_size, $page_size * ($page_num - 1), $vodType); } if (isset($favorities) && !is_null($favorities) && is_array($favorities)) { IjoyPlusServiceUtils::exportEntity(array('support' => $favorities)); } else { IjoyPlusServiceUtils::exportEntity(array('support' => array())); } } catch (Exception $e) { Yii::log(CJSON::encode($e), "error"); IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR); } }