/** * @param $socialProductPostId * @param $galleryId * @param $image * @param $caption * @param $ref * @return socialGalleryPostModel */ public static function addItem($socialProductPostId, $galleryId, $image, $caption, $ref) { $socialGalleryPost = new socialGalleryPostModel(); $socialGalleryPost->social_product_post_id = $socialProductPostId; $socialGalleryPost->gallery_id = $galleryId; $socialGalleryPost->image = $image; $socialGalleryPost->caption = $caption; $socialGalleryPost->ref = $ref; $socialGalleryPost->save(); return $socialGalleryPost; }
public function postToSocial($socialPostId, $userId, $social, $images, $descPost) { $util = new Util(); $socialPostModel = new socialPostModel(); $socialGalleryPostModel = new socialGalleryPostModel(); $userBusinessSocial = new userBusinessSocialModel(); if (!$this->isValidSocial($userId, $social->type, $social->socialId)) { throw new \Exception('BAD Social ID'); } $socialAccount = $userBusinessSocial->getItem($userId, $social->type, $social->socialId); $facebook = $util->initFacebook(); $facebook->setDefaultAccessToken($socialAccount->token); $arrayFbMedia = []; foreach ($images as $image) { $imagePost = $facebook->postPhoto($image->url, $image->caption); $socialGalleryPostModel->updateItem($image->socialGalleryPostId, ['ref' => $imagePost['id']]); array_push($arrayFbMedia, $imagePost); } $socialPost = $facebook->postFeed($arrayFbMedia, $descPost); $socialPostModel->updateItem($socialPostId, ['ref' => $socialPost['id']]); return $socialPost; }