| ... | ... |
@@ -36,9 +36,9 @@ abstract class RealEstateAssetsModuleController extends AbstractFrontendModuleCo |
| 36 | 36 |
* |
| 37 | 37 |
* @return integer |
| 38 | 38 |
*/ |
| 39 |
- public function countRealEstateAssets($arrCategories) |
|
| 39 |
+ public function countRealEstateAssets($arrCategories, array $arrOptions=array()) |
|
| 40 | 40 |
{
|
| 41 |
- return RealEstateAssetsModel::countPublishedByParent($arrCategories); |
|
| 41 |
+ return RealEstateAssetsModel::countPublishedByParent($arrCategories,$arrOptions); |
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
/** |
| ... | ... |
@@ -21,14 +21,14 @@ abstract class RealEstateAssetsModuleController extends AbstractFrontendModuleCo |
| 21 | 21 |
* |
| 22 | 22 |
* @return RealEstateAssetsModel|RealEstateAssetsModel[]|Collection|null |
| 23 | 23 |
*/ |
| 24 |
- public function getRealEstateAssets($arrCategories) |
|
| 24 |
+ public function getRealEstateAssets($arrCategories, array $arrOptions=array()) |
|
| 25 | 25 |
{
|
| 26 | 26 |
if (empty($arrCategories) || !\is_array($arrCategories)) |
| 27 | 27 |
{
|
| 28 | 28 |
return null; |
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
- return RealEstateAssetsModel::findPublishedByParent($arrCategories); |
|
| 31 |
+ return RealEstateAssetsModel::findPublishedByParent($arrCategories, 0,0,$arrOptions); |
|
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 | 34 |
/** |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,148 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace vonRotenberg\RealEstateListingBundle\Controller\FrontendModule; |
|
| 4 |
+ |
|
| 5 |
+use vonRotenberg\RealEstateListingBundle\Model\RealEstateAssetsModel; |
|
| 6 |
+use Contao\ArrayUtil; |
|
| 7 |
+use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; |
|
| 8 |
+use Contao\CoreBundle\Image\Studio\Figure; |
|
| 9 |
+use Contao\CoreBundle\Image\Studio\FigureBuilder; |
|
| 10 |
+use Contao\File; |
|
| 11 |
+use Contao\FilesModel; |
|
| 12 |
+use Contao\Model\Collection; |
|
| 13 |
+use Contao\StringUtil; |
|
| 14 |
+use Contao\System; |
|
| 15 |
+ |
|
| 16 |
+abstract class RealEstateAssetsModuleController extends AbstractFrontendModuleController |
|
| 17 |
+{
|
|
| 18 |
+ |
|
| 19 |
+ /** |
|
| 20 |
+ * @param $arrCategories |
|
| 21 |
+ * |
|
| 22 |
+ * @return RealEstateAssetsModel|RealEstateAssetsModel[]|Collection|null |
|
| 23 |
+ */ |
|
| 24 |
+ public function getRealEstateAssets($arrCategories) |
|
| 25 |
+ {
|
|
| 26 |
+ if (empty($arrCategories) || !\is_array($arrCategories)) |
|
| 27 |
+ {
|
|
| 28 |
+ return null; |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ return RealEstateAssetsModel::findPublishedByParent($arrCategories); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ /** |
|
| 35 |
+ * @param $arrCategories |
|
| 36 |
+ * |
|
| 37 |
+ * @return integer |
|
| 38 |
+ */ |
|
| 39 |
+ public function countRealEstateAssets($arrCategories) |
|
| 40 |
+ {
|
|
| 41 |
+ return RealEstateAssetsModel::countPublishedByParent($arrCategories); |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ /** |
|
| 45 |
+ * @param string|array $strUuids |
|
| 46 |
+ * @param FigureBuilder $figureBuilder |
|
| 47 |
+ * @param string|array $strOrder |
|
| 48 |
+ * |
|
| 49 |
+ * @return array|Figure |
|
| 50 |
+ * @throws \Exception |
|
| 51 |
+ */ |
|
| 52 |
+ public function getImageFigures($strUuids, $figureBuilder, $strOrder = null, int $intLimit = 0, int $intOffset = 0) |
|
| 53 |
+ {
|
|
| 54 |
+ $arrImageFigures = []; |
|
| 55 |
+ |
|
| 56 |
+ if (($imageFiles = FilesModel::findMultipleByUuids(StringUtil::deserialize($strUuids))) !== null) |
|
| 57 |
+ {
|
|
| 58 |
+ $images = array(); |
|
| 59 |
+ while ($imageFiles->next()) |
|
| 60 |
+ {
|
|
| 61 |
+ // Continue if the files has been processed or does not exist |
|
| 62 |
+ if (isset($images[$imageFiles->path]) || !file_exists(System::getContainer()->getParameter('kernel.project_dir') . '/' . $imageFiles->path))
|
|
| 63 |
+ {
|
|
| 64 |
+ continue; |
|
| 65 |
+ } |
|
| 66 |
+ |
|
| 67 |
+ // Single files |
|
| 68 |
+ if ($imageFiles->type == 'file') |
|
| 69 |
+ {
|
|
| 70 |
+ $objFile = new File($imageFiles->path); |
|
| 71 |
+ |
|
| 72 |
+ if (!$objFile->isImage) |
|
| 73 |
+ {
|
|
| 74 |
+ continue; |
|
| 75 |
+ } |
|
| 76 |
+ |
|
| 77 |
+ // Add the image |
|
| 78 |
+ $images[$imageFiles->path] = $imageFiles->current(); |
|
| 79 |
+ } // Folders |
|
| 80 |
+ else |
|
| 81 |
+ {
|
|
| 82 |
+ $objSubfiles = FilesModel::findByPid($imageFiles->uuid, array('order' => 'name'));
|
|
| 83 |
+ |
|
| 84 |
+ if ($objSubfiles === null) |
|
| 85 |
+ {
|
|
| 86 |
+ continue; |
|
| 87 |
+ } |
|
| 88 |
+ |
|
| 89 |
+ while ($objSubfiles->next()) |
|
| 90 |
+ {
|
|
| 91 |
+ // Skip subfolders |
|
| 92 |
+ if ($objSubfiles->type == 'folder') |
|
| 93 |
+ {
|
|
| 94 |
+ continue; |
|
| 95 |
+ } |
|
| 96 |
+ |
|
| 97 |
+ $objFile = new File($objSubfiles->path); |
|
| 98 |
+ |
|
| 99 |
+ if (!$objFile->isImage) |
|
| 100 |
+ {
|
|
| 101 |
+ continue; |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ // Add the image |
|
| 105 |
+ $images[$objSubfiles->path] = $objSubfiles->current(); |
|
| 106 |
+ } |
|
| 107 |
+ } |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ if ($strOrder !== null) |
|
| 111 |
+ {
|
|
| 112 |
+ $images = ArrayUtil::sortByOrderField($images, $strOrder); |
|
| 113 |
+ } |
|
| 114 |
+ $images = array_values($images); |
|
| 115 |
+ |
|
| 116 |
+ // Offset images |
|
| 117 |
+ if ($intOffset > 0) |
|
| 118 |
+ {
|
|
| 119 |
+ $images = \array_slice($images, ($intOffset < count($images) ? $intOffset : count($images))); |
|
| 120 |
+ } |
|
| 121 |
+ |
|
| 122 |
+ // Limit number of images |
|
| 123 |
+ if ($intLimit > 0) |
|
| 124 |
+ {
|
|
| 125 |
+ $images = \array_slice($images, 0, $intLimit); |
|
| 126 |
+ } |
|
| 127 |
+ |
|
| 128 |
+ // Build figures of images |
|
| 129 |
+ foreach ($images as $image) |
|
| 130 |
+ {
|
|
| 131 |
+ $figure = $figureBuilder |
|
| 132 |
+ ->fromFilesModel($image) |
|
| 133 |
+ ->build(); |
|
| 134 |
+ |
|
| 135 |
+ $arrImageFigures[] = $figure; |
|
| 136 |
+ } |
|
| 137 |
+ |
|
| 138 |
+ } |
|
| 139 |
+ return count ($arrImageFigures) === 1 && $intLimit === 1 ? array_shift($arrImageFigures) : $arrImageFigures; |
|
| 140 |
+ } |
|
| 141 |
+ |
|
| 142 |
+ public function getImageDataUrl($path) |
|
| 143 |
+ {
|
|
| 144 |
+ $type = pathinfo($path, PATHINFO_EXTENSION); |
|
| 145 |
+ $data = file_get_contents($path); |
|
| 146 |
+ return 'data:image/' . $type . ';base64,' . base64_encode($data); |
|
| 147 |
+ } |
|
| 148 |
+} |