/** * @param $description * @param $id */ public function trimImageDesc($description, $id) { $productGallery = new productGalleryModel(); $productGalleryService = new productGalleryService(); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->strictErrorChecking = false; preg_match_all('/src="(.*?)"/', $description, $items); $images = $items[1]; $productImageDesc = $productGallery->getImagesProductByProductId($id, PRODUCT_IMAGE_TYPE_DESC); foreach ($productImageDesc as $image) { if (!in_array($image->image, $images)) { $productGalleryService->deleteImage($image->id); } } }
public function updateProductImageType(Request $request) { $productId = $request->input('productId'); $imageId = $request->input('imageId'); $action = $request->input('action'); $productGallery = new productGalleryModel(); $productGalleryService = new productGalleryService(); $return['ok'] = 0; try { $image = $productGallery->getImageById($imageId); if ($action == 'setPrimaryImage') { $return['data'] = $productGallery->setPrimaryImage($imageId, $productId); } elseif ($action == 'deleteImage') { $productGalleryService->deleteImage($imageId); $return['data'] = true; } elseif ($action == 'setSlideImage') { $return['data'] = $productGallery->setSlideImage($imageId); } $return['ok'] = 1; } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }