2017-10-13 01:31:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNADesign\ElementalList\Model;
|
|
|
|
|
|
|
|
use DNADesign\Elemental\Models\BaseElement;
|
|
|
|
use DNADesign\Elemental\Models\ElementalArea;
|
|
|
|
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\ORM\ArrayList;
|
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
|
|
|
|
class ElementList extends BaseElement
|
|
|
|
{
|
2018-02-24 16:26:44 +01:00
|
|
|
private static $icon = 'font-icon-block-file-list';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
|
|
|
private static $has_one = [
|
|
|
|
'Elements' => ElementalArea::class
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $owns = [
|
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $cascade_deletes = [
|
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
2018-06-26 22:48:29 +02:00
|
|
|
private static $cascade_duplicates = [
|
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
2017-10-13 01:31:11 +02:00
|
|
|
private static $extensions = [
|
|
|
|
ElementalAreasExtension::class
|
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'ElementList';
|
|
|
|
|
|
|
|
private static $title = 'Group';
|
|
|
|
|
|
|
|
private static $description = 'Orderable list of elements';
|
2018-06-26 22:48:29 +02:00
|
|
|
|
2018-02-24 18:46:15 +01:00
|
|
|
private static $singular_name = 'list';
|
|
|
|
|
|
|
|
private static $plural_name = 'lists';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
2017-11-08 00:22:48 +01:00
|
|
|
public function getType()
|
|
|
|
{
|
|
|
|
return _t(__CLASS__ . '.BlockType', 'List');
|
|
|
|
}
|
2017-10-13 01:31:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DBField
|
|
|
|
*/
|
2017-11-08 00:22:48 +01:00
|
|
|
public function getSummary()
|
2017-10-13 01:31:11 +02:00
|
|
|
{
|
2017-11-08 00:22:48 +01:00
|
|
|
$count = $this->Elements()->Elements()->Count();
|
2017-10-13 01:31:11 +02:00
|
|
|
$suffix = $count === 1 ? 'element': 'elements';
|
|
|
|
$summary = $this->ListDescription ? DBField::create_field('HTMLText', $this->ListDescription)->Summary(10) . '<br />': '';
|
|
|
|
|
|
|
|
return DBField::create_field('HTMLText', $summary . ' <span class="el-meta">Contains ' . $count . ' ' . $suffix . '</span>');
|
|
|
|
}
|
2018-01-11 22:55:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a elemental area relation name which this element owns
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOwnedAreaRelationName()
|
|
|
|
{
|
|
|
|
$has_one = $this->config()->get('has_one');
|
|
|
|
|
|
|
|
foreach ($has_one as $relationName => $relationClass) {
|
|
|
|
if ($relationClass === ElementalArea::class && $relationName !== 'Parent') {
|
|
|
|
return $relationName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Elements';
|
|
|
|
}
|
2017-10-13 01:31:11 +02:00
|
|
|
}
|