Пример #1
0
 /**
  * @param $userId
  * @param $type
  * @param $token
  * @param $socialId
  * @return bool
  */
 public function createItem($userId, $type, $token, $socialId)
 {
     $userSocial = new userSocialModel();
     $userSocial->user_id = $userId;
     $userSocial->type = $type;
     $userSocial->token = $token;
     $userSocial->social_id = $socialId;
     return $userSocial->save();
 }
Пример #2
0
 /**
  * @param $profiles
  * @param $accessToken
  * @param $user
  * @return mixed
  */
 public function updateFacebookAccessToken($profiles, $accessToken, $user)
 {
     $userSocialModel = new userSocialModel();
     $result['ok'] = 0;
     if (!$profiles) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_FACEBOOK_PROFILE;
         $result['error_message'] = 'Chúng tôi không thể lấy thông tin từ facebook của bạn!';
         return $result;
     }
     $userSocial = $userSocialModel->getItemBySocialId($profiles['id'], KACANA_SOCIAL_TYPE_FACEBOOK);
     if ($userSocial) {
         if ($userSocial->user_id == $user->id) {
             $items = ['ref' => 1, 'token' => $accessToken, 'social_id' => $profiles['id']];
             $userSocialModel->updateItem($user->id, KACANA_SOCIAL_TYPE_FACEBOOK, $items);
             $result['ok'] = 1;
         } else {
             $result['error_code'] = KACANA_AUTH_SIGNUP_EXISTS_SOCIAL_ACCOUNT;
             $result['error_message'] = 'Tài khoản facebook này đã được sử dụng vui lòng đăng nhập lại!';
             return $result;
         }
     } else {
         $userSocialModel->createItem($user->id, KACANA_SOCIAL_TYPE_FACEBOOK, $accessToken, $profiles['id']);
         $result['ok'] = 1;
     }
     return $result;
 }
Пример #3
0
 public function postProductToFacebook($productId, $descPost, $images, $userId)
 {
     $productModel = new productModel();
     $userSocialModel = new userSocialModel();
     $util = new Util();
     $socialAccount = $userSocialModel->getItem($userId, KACANA_SOCIAL_TYPE_FACEBOOK);
     $facebook = $util->initFacebook();
     $facebook->setDefaultAccessToken($socialAccount->token);
     $product = $productModel->getProductById($productId);
     if (!$product) {
         throw new \Exception('BAD Product ID');
     }
     $galleries = $product->galleries;
     $arrayFbMedia = [];
     foreach ($galleries as $gallery) {
         if (in_array($gallery->id, $images)) {
             array_push($arrayFbMedia, $facebook->postPhoto('http:' . AWS_CDN_URL . str_replace(' ', '%20', $gallery->getOriginal('image')), $product->name));
         }
     }
     return $facebook->postFeed($arrayFbMedia, $descPost);
 }