UPD: remove incompatibles

This commit is contained in:
Tony Air 2024-04-22 14:14:10 +02:00
parent 01071730da
commit 32d8fa88c3
3 changed files with 0 additions and 463 deletions

View File

@ -1,105 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 6/30/18
* Time: 11:54 PM
*/
namespace A2nt\ElementalBasics\Elements;
use A2nt\SilverStripeMapboxField\MapboxField;
use BetterBrief\GoogleMapField;
use Colymba\BulkManager\BulkManager;
use DNADesign\Elemental\Models\ElementContent;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\NumericField;
use A2nt\ElementalBasics\Controllers\MapElementController;
use A2nt\ElementalBasics\Extensions\MapExtension;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
/**
* Class \A2nt\ElementalBasics\Elements\MapElement
*
* @property int $MapZoom
* @method \SilverStripe\ORM\ManyManyList|\A2nt\ElementalBasics\Models\MapPin[] Locations()
* @mixin \A2nt\ElementalBasics\Extensions\MapExtension
*/
class MapElement extends ElementContent
{
private static $icon = 'font-icon-globe-1';
private static $singular_name = 'Map Element';
private static $plural_name = 'Map Element';
private static $description = 'Displays dynamic map';
private static $table_name = 'MapElement';
private static $controller_class = MapElementController::class;
private static $map_type = 'mapbox';
private static $extensions = [
MapExtension::class,
];
public function getType(): string
{
return _t(__CLASS__ . '.BlockType', self::$singular_name);
}
public function getCMSFields(): FieldList
{
$fields = parent::getCMSFields();
$fields->remove('HTML');
$tab = $fields->findOrMakeTab('Root.MapPins');
$tab->setTitle('Description');
$tab->push(HTMLEditorField::create('HTML', 'Content'));
$fields->addFieldsToTab('Root.Main', [
NumericField::create('MapZoom', 'Initial Map Zoom (enter a number from 0 to 24)'),
GridField::create(
'Locations',
'Locations',
$this->Locations(),
$cfg = GridFieldConfig_RelationEditor::create(100)
)
]);
$cfg->getComponentByType(GridFieldDataColumns::class)->setFieldFormatting([
'ShowAtMap' => static function ($v, $obj) {
return $v ? 'YES' : 'NO';
}
]);
$cfg->addComponent(new BulkManager());
return $fields;
}
public static function MapAPIKey(): string
{
$type = self::config()->get('map_type');
switch ($type) {
case 'mapbox':
$key = MapboxField::getAccessToken();
break;
case 'google-maps':
$cfg = Config::inst()->get(GoogleMapField::class, 'default_options');
$key = $cfg['api_key'];
break;
default:
$key = '';
break;
}
return $key;
}
}

View File

@ -1,186 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 6/30/18
* Time: 11:54 PM
*/
namespace A2nt\ElementalBasics\Elements;
use Colymba\BulkUpload\BulkUploader;
use Dynamic\Elements\Flexslider\Elements\ElementSlideshow;
use Dynamic\FlexSlider\Model\SlideImage;
use Dynamic\FlexSlider\ORM\FlexSlider;
use SilverStripe\Assets\Image;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\GridField\GridField_ActionMenu;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\ReadonlyField;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
/**
* Class \A2nt\ElementalBasics\Elements\SliderElement
*
* @property string $Animation
* @property boolean $Loop
* @property boolean $Animate
* @property boolean $ThumbnailNav
* @property boolean $SliderControlNav
* @property boolean $SliderDirectionNav
* @property boolean $CarouselControlNav
* @property boolean $CarouselDirectionNav
* @property int $CarouselThumbnailCt
* @property float $FlexSliderSpeed
* @property int $Interval
* @property int $SlidesInRow
* @property boolean $ImageOriginalSize
* @method \SilverStripe\ORM\DataList|\Dynamic\FlexSlider\Model\SlideImage[] Slides()
* @mixin \Dynamic\FlexSlider\ORM\FlexSlider
*/
class SliderElement extends ElementSlideshow
{
private static $singular_name = 'Slider';
private static $plural_name = 'Sliders';
private static $description = 'Displays slide show';
private static $table_name = 'SliderElement';
private static $slide_width = 2140;
private static $slide_height = 700;
private static $db = [
'Interval' => 'Int',
'SlidesInRow' => 'Int',
'ImageOriginalSize' => 'Boolean(0)',
];
private static $extensions = [
FlexSlider::class,
];
private static $owns = [
'Slides',
];
private $items;
public function getType(): string
{
return _t(__CLASS__ . '.BlockType', self::$singular_name);
}
protected function ratioSize($size)
{
$count = $this->SlidesInRow;
return ($count > 1) ? $size / $count : $size;
}
public function getSlideWidth()
{
if ($this->getField('ImageOriginalSize')) {
return null;
}
return $this->ratioSize(self::config()->get('slide_width'));
}
public function getSlideHeight()
{
if ($this->getField('ImageOriginalSize')) {
return null;
}
return $this->ratioSize(self::config()->get('slide_height'));
}
public function getCMSFields()
{
$fields = parent::getCMSFields();
// remove in case you don't need to provide this functionality
$fields->removeByName([
'ConfigHD',
'Animation',
'Loop',
'Animate',
'ThumbnailNav',
'SliderControlNav',
'SliderDirectionNav',
'CarouselControlNav',
'CarouselDirectionNav',
'CarouselThumbnailCt',
]);
$fields->addFieldsToTab('Root.Settings', [
CheckboxField::create('ImageOriginalSize', 'Use original image size'),
NumericField::create('Interval', 'Auto-play Interval (sec)'),
NumericField::create('SlidesInRow'),
]);
$grid = $fields->dataFieldByName('Slides');
if ($grid) {
$fields->insertBefore('Slides', LiteralField::create(
'SlidesNote',
'<div class="alert alert-info">Note: to show hidden slide open slide item and uncheck "Hide" checkbox</div>'
));
$config = $grid->getConfig();
$config->removeComponentsByType(GridField_ActionMenu::class);
$bulk = new BulkUploader('Image', SlideImage::class, false);
$bulk
->setUfSetup('setFolderName', 'Uploads/SlideImages');
//->setUfSetup('getValidator.setAllowedExtensions', ['jpg', 'jpeg', 'png', 'gif']);
$config->addComponent($bulk);
$config->addComponent(new \Colymba\BulkManager\BulkManager());
$columns = new GridFieldEditableColumns();
$columns->setDisplayFields([
'Hide' => [
'title' => 'Hide it?',
'field' => CheckboxField::class,
],
]);
$config->addComponent($columns);
}
return $fields;
}
/**
* @return mixed
*/
public function getSlideShow()
{
if ($this->items) {
return $this->items;
}
$date = date('Y-m-d H:i:s');
$this->items = $this->Slides()->filter([
'Hide' => '0',
])->filterByCallback(static function ($item, $list) use ($date) {
$on = $item->getField('DateOn');
$off = $item->getField('DateOff');
return ($on <= $date) && (!$off || $off > $date);
})->sort('SortOrder');
return $this->items;
}
public function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->getField('Interval')) {
$this->setField('Interval', 5000);
}
}
}

View File

@ -1,172 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 9/12/18
* Time: 2:55 AM
*/
namespace A2nt\ElementalBasics\Models;
use A2nt\SilverStripeMapboxField\MapboxField;
use A2nt\SilverStripeMapboxField\MarkerExtension;
use gorriecoe\LinkField\LinkField;
use gorriecoe\Link\Models\Link;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use A2nt\ElementalBasics\Elements\MapElement;
use Symbiote\Addressable\Addressable;
/**
* Class \A2nt\ElementalBasics\Models\MapPin
*
* @property int $Version
* @property boolean $DirectionsByAddress
* @property boolean $LatLngOverride
* @property float $Lat
* @property float $Lng
* @property string $Address
* @property string $Suburb
* @property string $State
* @property string $Postcode
* @property string $Country
* @property string $Title
* @property boolean $ShowAtMap
* @property int $PhoneNumberID
* @property int $FaxID
* @method \Sheadawson\Linkable\Models\Link PhoneNumber()
* @method \Sheadawson\Linkable\Models\Link Fax()
* @method \SilverStripe\ORM\ManyManyList|\A2nt\ElementalBasics\Elements\MapElement[] MapElements()
* @mixin \Symbiote\Addressable\Addressable
* @mixin \A2nt\SilverStripeMapboxField\MarkerExtension
* @mixin \SilverStripe\Versioned\Versioned
*/
class MapPin extends DataObject
{
private static $table_name = 'MapPin';
private static $db = [
'Title' => 'Varchar(255)',
'ShowAtMap' => 'Boolean(1)',
];
private static $has_one = [
'PhoneNumber' => Link::class,
'Fax' => Link::class,
];
private static $extensions = [
Addressable::class,
MarkerExtension::class,
Versioned::class,
];
private static $belongs_many_many = [
'MapElements' => MapElement::class,
];
private static $default_sort = 'Title ASC, ID DESC';
private static $summary_fields = [
'Title',
'Address',
'ShowAtMap',
];
private static $defaults = [
'ShowAtMap' => '1',
'Suburb' => 'Syracuse',
'State' => 'NY',
'Postcode' => '13210',
'Country' => 'US',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName('MapElements');
$fields->replaceField(
'PhoneNumberID',
LinkField::create('PhoneNumber', 'Phone Number', $this, [
'types' => ['Phone']
])
);
$fields->replaceField(
'Fax',
LinkField::create('Fax', 'FAX', $this, [
'types' => ['Phone']
])
);
$fields->removeByName(['Map', 'LatLngOverride', 'Lng','Lat']);
$fields->addFieldsToTab('Root.Main', [
CheckboxField::create('ShowAtMap', 'Show at the map?'),
CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?')
->setDescription('Check this box and save to be able to edit the latitude and longitude manually.'),
MapboxField::create('Map', 'Choose a location', 'Lat', 'Lng'),
]);
$this->extend('updateMapPinFields', $fields);
return $fields;
}
public function onBeforeWrite()
{
parent::onBeforeWrite();
$lng = $this->getField('Lng');
$lat = $this->getField('Lat');
if (!$this->getField('Country')) {
$this->setField('Country', 'us');
}
// geocode
try {
// reverse geocoding get address
if (!$this->hasAddress() && $lng && $lat) {
require_once BASE_PATH . '/app/thirdparty/geocoding-example/php/Mapbox.php';
$mapbox = new \Mapbox(MapboxField::getAccessToken());
// GET Address
$res = $mapbox->reverseGeocode($lng, $lat);
if ($res->success() && $res->getCount()) {
$res = $res->getData();
if (count($res) && isset($res[0]['place_name'])) {
$details = explode(',', $res[0]['place_name']);
$fields = [
'Address',
'City',
'State',
//'Country',
];
$n = count($fields);
for ($i = 0; $i < $n; $i++) {
if (!isset($details[$i])) {
continue;
}
$name = $fields[$i];
$val = $details[$i];
// get postal code
if ($name === 'State') {
$this->setField('PostalCode', substr($val, strrpos($val, ' ')+1));
}
$this->setField($name, $val);
}
}
}
}
} catch (\Exception $e) {
}
}
}