Extending
Add data to every area
Renderer::EVENT_DEFINE_AREA_DATA fires for each area as a plan becomes front-end data (the
Twig render, planData() and the JSON endpoint alike). Whatever you put in payload arrives as
area.data in JavaScript:
use justinholtweb\hitz\events\DefineAreaDataEvent;
use justinholtweb\hitz\services\Renderer;
use yii\base\Event;
Event::on(Renderer::class, Renderer::EVENT_DEFINE_AREA_DATA, function(DefineAreaDataEvent $e) {
$exhibitor = $e->area->exhibitor->one();
$e->payload['logo'] = $exhibitor?->logo->one()?->getUrl(['width' => 160]);
// The built-in search also matches `keywords`.
$e->payload['keywords'] = $exhibitor?->productCategories->collect()->pluck('title')->join(' ');
});
Area type events
AreaTypes::EVENT_BEFORE_SAVE_AREA_TYPE, EVENT_AFTER_SAVE_AREA_TYPE and
EVENT_BEFORE_DELETE_AREA_TYPE (an AreaTypeEvent; set isValid = false on the delete event to
keep the type).
Element events
Plans and areas are ordinary elements: Element::EVENT_BEFORE_SAVE, EVENT_AFTER_SAVE,
Elements::EVENT_AFTER_DELETE_ELEMENT and the rest all fire. To react to a stand being booked,
compare the stored value before the save with the new one:
use craft\base\Element;
use craft\events\ModelEvent;
use justinholtweb\hitz\elements\Area;
Event::on(Area::class, Element::EVENT_BEFORE_SAVE, function(ModelEvent $e) {
/** @var Area $area */
$area = $e->sender;
$before = $area->id ? Area::find()->id($area->id)->status(null)->one()?->availability : null;
if ($before !== Area::AVAILABILITY_BOOKED && $area->availability === Area::AVAILABILITY_BOOKED) {
// queue a job to tell the sales channel
}
});
The designer
The designer announces itself with a hitz:designer-ready event and lives on
document.getElementById('hitz-designer').hitzDesigner — .map is the Leaflet map, .areas
every area and its layer, .focus(id) selects and zooms. Register a CP asset bundle on the
designer route to add your own tools.
Services
Plugin::getInstance()->getPlans(), getAreas() (createArea(), suggestCode(),
assignHalls()), getAreaTypes(), getRenderer() and getTransfer(). Geometry is
justinholtweb\hitz\models\Geometry — rectangle(), polygon(), circle(), surface(),
centroid(), contains().