Source of file ListPage.php
Size: 5,262 Bytes - Last Modified: 2022-02-21T10:01:38+00:00
/var/www/docs.ssmods.com/process/src/code/ListPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | <?php class ListPage extends Page { private static $db = array( 'ToggleEffect' => 'Boolean', 'ToggleEffectItems' => 'Boolean', 'StartToggleClosed' => 'Boolean', 'AlphabeticalOrder' => 'Boolean', 'AlphaOrderCategories' => 'Boolean', 'BottomContent' => 'HTMLText', 'PhotoMaxWidth' => 'Int' ); private static $has_many = array( 'ListItems' => 'ListItem', 'ListCategories' => 'ListCategory' ); private static $defaults = array( 'ToggleEffect' => true, 'ToggleEffectItems' => true, 'StartToggleClosed' => true, 'AlphabeticalOrder' => false, 'AlphaOrderCategories' => false, 'PhotoMaxWidth' => '300' ); private static $icon = "listpage/images/listpage"; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Main', HTMLEditorField::create('BottomContent')->setTitle('Content for below the list items'), 'Metadata'); $fields->addFieldToTab('Root.ListItems', GridField::create( 'ListItems', 'List Items', $this->ListItems(), GridFieldConfig_RecordEditor::create('50')->addComponent($sortableitems = new GridFieldSortableRows('SortID')) )); $sortableitems->setAppendToTop(true); $fields->addFieldToTab('Root.ListCategories', GridField::create( 'ListCategories', 'List Categories', $this->ListCategories(), GridFieldConfig_RecordEditor::create('50')->addComponent($sortablecategories = new GridFieldSortableRows('SortID')) )); $sortablecategories->setAppendToTop(true); $fields->addFieldToTab('Root.Config', HeaderField::create('ListItemsDesc')->setTitle('List Items Options')); $fields->addFieldToTab('Root.Config', CheckboxField::create('AlphabeticalOrder')->setTitle('Alphabetical Order for List Items')->setDescription('Show in alphabetical order (By the list item title, overwrites drag and drop order)')); $fields->addFieldToTab('Root.Config', CheckboxField::create('ToggleEffectItems')->setTitle('Toggle Effect for List Items')->setDescription('Set toggle effect on list items')); $fields->addFieldToTab("Root.Config", SliderField::create("PhotoMaxWidth", "Max Photo Width", 50, 1600)->setDescription('For photo that is associated with list items')); $fields->addFieldToTab('Root.Config', HeaderField::create('ListCategoriesDesc')->setTitle('List Categories Options')); $fields->addFieldToTab('Root.Config', CheckboxField::create('AlphaOrderCategories')->setTitle('Alphabetical Order for List Categories')->setDescription('Show in alphabetical order (By the list category title, overwrites drag and drop ordering)')); $fields->addFieldToTab('Root.Config', CheckboxField::create('ToggleEffect')->setTitle('Toggle Effect for List Cateogries')->setDescription('Set toggle effect on list categories')); $fields->addFieldToTab('Root.Config', CheckboxField::create('StartToggleClosed')->setTitle('Start Toggle Closed for List Categories')->setDescription('The toggle for all catogries will start closed, if off the first category toggle will be open')); return $fields; } } class ListPage_Controller extends Page_Controller { public static function load_requirements() { Requirements::css('listpage/css/listpage.css'); Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js'); Requirements::javascript('listpage/js/listpage.js'); } public function init() { parent::init(); self::load_requirements(); } public function ListCategories() { $listcategoriesfiltered = new ArrayList(); if ($this->AlphaOrderCategories) { $listcategories = $this->getComponents('ListCategories')->sort('Category ASC'); } else { $listcategories = $this->getComponents('ListCategories'); } if ($listcategories) { foreach ($listcategories as $listcategory) { if ($listcategory->getComponents('ListItems')->count() > 0) { $listcategoriesfiltered->push($listcategory); } } } return $listcategoriesfiltered; } public function UncategorizedListItems() { $uncategorizedlistitems = new ArrayList(); if ($this->AlphabeticalOrder) { $listitems = $this->getComponents('ListItems')->sort("Title ASC"); } else { $listitems = $this->getComponents('ListItems'); } if ($listitems) { foreach ($listitems as $listitem) { if ($listitem->Category() == "Other") { $uncategorizedlistitems->push($listitem); } } } return $uncategorizedlistitems; } public function MoreThanOneListCategory() { if ($this->ListCategories()->count()) { return true; } } public function ToggleEffect() { if ($this->ToggleEffect == true and $this->ListCategories()->count() > 0) { return true; } } } |