/** * Add a user to follower list of other and send notifcation * * @author Kuldeep Dangi <*****@*****.**> */ public function actionFollowUser($userId, $followerId) { $model = new UserFollow(); $userFollowingObj = Users::model()->findByPk($userId); $userObj = Users::model()->findByPk($followerId); if ($userFollowingObj && $userObj) { $isRecrodExist = $model->findByAttributes(array('id_follower' => $followerId, 'id_following' => $userId)); if ($isRecrodExist) { $this->result['success'] = true; } else { $model->attributes = array('id_follower' => $followerId, 'id_following' => $userId); if ($model->validate() && $model->save()) { $notificationObj = new Notifications(); $notificationObj->addNotification(array('byUserId' => $userId, 'user_id' => $followerId, 'type' => 'FOLLOW')); $notificationObj->sendPushNotification(array('deviceToken' => $userObj->deviceToken, 'deviceType' => $userObj->deviceType, 'message' => $userFollowingObj->username . ' has started following you.')); $this->result['success'] = true; $this->getUserInformation($userId); $this->result['message'] = 'Record saved successfuly.'; } else { $this->result['message'] = 'Invalid Data.'; } } } else { $this->result['message'] = 'Invalid data.'; } $this->sendResponse($this->result); }
/** * Add a file in response of a wishlist request. * * @author Kuldeep Dangi <*****@*****.**> */ public function actionAddFile() { $model = new Extensions(); $modelUserFeed = new UserFeed(); if (!empty($_POST['user_id']) && !empty($_POST['reply_to_feed'])) { $model->attributes = $_POST; $uploadedFiles = CUploadedFile::getInstancesByName('images'); if ($uploadedFiles && count($uploadedFiles) > 0) { $allUploadedFiles = array(); foreach ($uploadedFiles as $uploadedFile) { $fileName = strtotime($this->getCurrentDateTime()) . '-' . $uploadedFile; $uploadedFile->saveAs(Yii::app()->basePath . '/../../' . Extensions::FILE_UPLOAD_PATH . $fileName); $allUploadedFiles[] = $fileName; } $savedFileNames = $model->getPdfFromImages($allUploadedFiles); $model->pdf = Extensions::FILE_CONVERT_PATH . $savedFileNames['pdf']; $model->imagepdf = $savedFileNames['imagepdf']; $model->image = Extensions::FILE_IMAGE_PATH . $savedFileNames['image']; if ($model->save()) { $modelUserFeed->user_id = $_POST['user_id']; $modelUserFeed->reply_to_feed = $_POST['reply_to_feed']; $modelUserFeed->comment = Extensions::FILE_CONVERT_PATH . $savedFileNames['pdf']; $modelUserFeed->is_file = 1; $modelUserFeed->date_add = time(); $modelUserFeed->save(); $feedData = $this->loadModel($_POST['reply_to_feed']); $notificationObj = new Notifications(); $notificationObj->addNotification(array('byUserId' => $_GET['user_id'], 'user_id' => $feedData->user_id, 'notify_comment' => $feedData->user_feed_id, 'type' => 'WISHLISTUPLOAD')); $userObj = Users::model()->findByPk($feedData->user_id); if ($userObj && !empty($userObj->deviceToken)) { $notificationObj->sendPushNotification(array('deviceToken' => $userObj->deviceToken, 'deviceType' => $userObj->deviceType, 'message' => 6)); } $this->result['success'] = true; } } } else { $this->result['message'] = 'Invalid Data.'; } $this->sendResponse($this->result); }