Exemplo n.º 1
0
 /**
  * @param $socialPostId
  * @param $productId
  * @return socialProductPostModel
  */
 public static function addItem($socialPostId, $productId)
 {
     $socialProductPost = new socialProductPostModel();
     $socialProductPost->social_post_id = $socialPostId;
     $socialProductPost->product_id = $productId;
     $socialProductPost->save();
     return $socialProductPost;
 }
Exemplo n.º 2
0
 public function superPostToSocial($userId, $socials, $products, $desc)
 {
     $productModel = new productModel();
     $productGalleryModel = new productGalleryModel();
     $socialPostModel = new socialPostModel();
     $socialProductPostModel = new socialProductPostModel();
     $socialGalleryPostModel = new socialGalleryPostModel();
     $bootType = SOCIAL_BOOT_TYPE_SUPER;
     if (count($products) == 1) {
         $bootType = SOCIAL_BOOT_TYPE_NORMAL;
     }
     foreach ($socials as $social) {
         $socialPost = $socialPostModel->addItem($userId, $social['socialId'], $social['type'], $bootType, $this->trimDescPostToFacebook($desc), '');
         $arrayImage = [];
         foreach ($products as $product) {
             if ($this->isValidProduct($userId, $product['productId'])) {
                 $socialProductPost = $socialProductPostModel->addItem($socialPost->id, $product['productId']);
                 $productImageIds = $product['images'];
                 for ($i = 0; $i < count($productImageIds); $i++) {
                     $urlImage = '';
                     if ($productImageIds[$i] == 'image') {
                         $productTemp = $productModel->getProductById($product['productId'], false);
                         $urlImage = $productTemp->image;
                     } else {
                         $gallery = $productGalleryModel->getById($productImageIds[$i], $product['productId']);
                         $urlImage = $gallery->image;
                     }
                     $socialGalleryPost = $socialGalleryPostModel->addItem($socialProductPost->id, $productImageIds[$i], $urlImage, $this->trimDescPostToFacebook($product['caption']), '');
                     array_push($arrayImage, ['socialGalleryPostId' => $socialGalleryPost->id, 'url' => $this->trimImageLinkForSocial($urlImage), 'caption' => $this->trimDescPostToFacebook($product['caption'])]);
                 }
             }
         }
         $job = ["socialPostId" => $socialPost->id, "userId" => $userId, "social" => $social, "images" => $arrayImage, "desc" => $this->trimDescPostToFacebook($desc)];
         // push process to post to queue and response for user is processing
         Queue::push(new PostToSocial(base64_encode(json_encode($job))));
     }
     return true;
 }