/** * Get all icons. * * @return array */ public function getIcons() { $collection = IconModel::findAll(array('order' => 'title')); $builder = OptionsBuilder::fromCollection($collection, function ($model) { return sprintf('%s [%s]', $model['title'], $model['type']); }); return $builder->getOptions(); }
/** * Build the amenity icons map. * * @param Model $model Definition model. * * @return array */ protected function buildAmenityIconsMap(Model $model) { $amenityIconsMap = $this->filterAmenityIconsConfig($model->amenityIcons); if ($amenityIconsMap) { $collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap)); $icons = []; if ($collection) { foreach ($collection as $iconModel) { $icons[$iconModel->id] = $iconModel->alias ?: $iconModel->id; } foreach ($amenityIconsMap as $amenity => $iconId) { if (isset($icons[$iconId])) { $amenityIconsMap[$amenity] = $icons[$iconId]; } } } } return $amenityIconsMap; }
/** * Load fallback icon. * * @param DefinitionMapper $mapper The definition mapper. * * @return void */ protected function loadFallbackIcon(DefinitionMapper $mapper) { if ($this->model->icon) { $iconModel = IconModel::findByPk($this->model->icon); if ($iconModel) { $this->fallbackIcon = $mapper->handle($iconModel); } } }
/** * Load icons. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) */ public function loadIcons() { $collection = IconModel::findBy('active', true); if ($collection) { /** @var DefinitionMapper $mapper */ $mapper = $GLOBALS['container']['leaflet.definition.mapper']; $buffer = ''; $icons = array(); foreach ($collection as $model) { /** @var ImageIcon $icon */ $icon = $mapper->handle($model); $icons[] = array('id' => $icon->getId(), 'type' => lcfirst($icon->getType()), 'options' => $icon->getOptions()); } if ($icons) { $buffer = sprintf('L.contao.loadIcons(%s);', json_encode($icons)); } $file = new \File('assets/leaflet/js/icons.js'); $file->write($buffer); $file->close(); // @codingStandardsIgnoreStart // TODO: Cache it. // codingStandardsIgnoreEnd $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js' . $this->staticFlag(); } }
/** * Load icons. * * @return void */ public function loadIcons() { if (!$this->definitionMapper) { return; } $collection = IconModel::findBy('active', true); if ($collection) { $buffer = ''; $icons = array(); foreach ($collection as $model) { /** @var ImageIcon $icon */ $icon = $this->definitionMapper->handle($model); $icons[] = array('id' => $icon->getId(), 'type' => lcfirst($icon->getType()), 'options' => $icon->getOptions()); $this->loadIconsLibraries($icon); } if ($icons) { $buffer = sprintf('L.contao.loadIcons(%s);', json_encode($icons)); } // @codingStandardsIgnoreStart // TODO: Cache it. // codingStandardsIgnoreEnd $file = new \File('assets/leaflet/js/icons.js'); $file->write($buffer); $file->close(); } }
/** * {@inheritdoc} */ protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null) { if ($definition instanceof Marker) { if ($model->addPopup) { $popup = null; $content = $this->valueFilter->filter($model->popupContent); if ($model->popup) { $popupModel = PopupModel::findActiveByPK($model->popup); if ($popupModel) { $popup = $mapper->handle($popupModel, $filter, null, $definition); } } if ($popup instanceof Popup) { $definition->bindPopup($content, $popup->getOptions()); } else { $definition->bindPopup($content); } } if ($model->customIcon) { $iconModel = IconModel::findBy(array('id=?', 'active=1'), array($model->icon), array('return' => 'Model')); if ($iconModel) { /** @var ImageIcon $icon */ $icon = $mapper->handle($iconModel); $definition->setIcon($icon); } } } }