$Model = $Sets ? $Sets[0]->getModel() : NULL; if (!$Sets || in_array($Sets[0]->getModel()->getFullName(), array('Promotions', 'Interviews'))) { Image::OutputImage(); } $pageIterator = 1; $perPage = $perPage && $perPage > 0 ? $perPage : count($Sets); $uuid = Utils::UUID(); $cacheImages = array(); while (($pageIterator - 1) * $perPage < count($Sets)) { $Sets2Process = array_slice($Sets, ($pageIterator - 1) * $perPage, $perPage); $img = GenerateModelIndex($Sets2Process, $Images, $finalWidth, $finalHeight); if (is_null($img)) { $img = imagecreatefromjpeg($pathPrefix . 'images/missing.jpg'); } $CacheImage = new CacheImage($uuid); $CacheImage->setModelIndexID($ModelID); $CacheImage->setKind(CACHEIMAGE_KIND_INDEX); $CacheImage->setImageWidth($finalWidth); $CacheImage->setImageHeight($finalHeight); $CacheImage->setSequenceNumber($pageIterator); $CacheImage->setSequenceTotal(ceil(count($Sets) / $perPage)); CacheImage::Insert($CacheImage, $CurrentUser); imagejpeg($img, $CacheImage->getFilenameOnDisk()); imagedestroy($img); $cacheImages[] = $CacheImage; $pageIterator++; } if ($outputMode == EXPORT_OPTION_IMAGE && count($cacheImages) == 1) { $CacheImage = $cacheImages[0]; Image::OutputImage($CacheImage->getFilenameOnDisk(), $CacheImage->getImageWidth(), $CacheImage->getImageHeight(), TRUE, NULL, $PromptDownload ? sprintf('%1$s.jpg', $Model->GetFullName()) : NULL); }