Source of file PersonalisationAdmin.php
Size: 8,125 Bytes - Last Modified: 2021-12-23T10:33:31+00:00
/var/www/docs.ssmods.com/process/src/code/admin/PersonalisationAdmin.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | <?php class PersonalisationAdmin extends ModelAdmin { public static $url_segment = 'personalisation'; public static $menu_title = 'Personalisation'; public static $managed_models = array('BasicPersonalisation'); public static function managed_personalisation_models() { $classes = array(); foreach (ClassInfo::subclassesFor('PersonalisationScheme') as $i => $class) { if ($class == 'PersonalisationScheme') { continue; } if (ClassInfo::classImplements($class, 'TestOnly')) { continue; } $tempObj = singleton($class); if (!$tempObj::$is_abstract) { $classes[] = $class; } } return $classes; } public static function managed_variation_models() { $classes = array(); foreach (ClassInfo::subclassesFor('PersonalisationVariation') as $i => $class) { if ($class == 'PersonalisationVariation') { continue; } if (ClassInfo::classImplements($class, 'TestOnly')) { continue; } //if(singleton($class)->canCreate()) $classes[] = $class; $classes[] = $class; } return $classes; } /** * @todo Are we using this? get rid of it **/ public function getList() { $context = $this->getSearchContext(); $params = $this->request->requestVar('q'); $list = $context->getResults($params); $this->extend('updateList', $list); return $list; } public function getEditForm($id = null, $fields = null) { $tempList = PersonalisationScheme::get(); $list = new ArrayList(); if ($tempList->Count() != 0) { foreach ($tempList as $e) { $list->push($e); } } else { $list = new DataList('BasicPersonalisation'); } $listField = GridField::create( $this->sanitiseClassName($this->modelClass), false, $list, $fieldConfig = GridFieldConfig_RecordEditor_Personalisation::create($this->stat('page_length')) ->removeComponentsByType('GridFieldFilterHeader') ); // Validation if (singleton($this->modelClass)->hasMethod('getCMSValidator')) { $detailValidator = singleton($this->modelClass)->getCMSValidator(); $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator); } $form = new Form( $this, 'EditForm', new FieldList($listField), new FieldList() ); $form->addExtraClass('cms-edit-form cms-panel-padded center'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm'); $form->setFormAction($editFormAction); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; } public function init() { LeftAndMain::init(); $models = $this->getManagedModels(); if ($this->request->param('ModelClass')) { $this->modelClass = $this->unsanitiseClassName($this->request->param('ModelClass')); } else { reset($models); $this->modelClass = key($models); } Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ModelAdmin.js'); Requirements::css("personalisation/css/personalisationAdmin.css"); Requirements::javascript("personalisation/thirdparty/flot-0.7/jquery.flot.js"); Requirements::javascript("personalisation/thirdparty/flot-0.7/jquery.flot.time.js"); Requirements::javascript("personalisation/thirdparty/flot-0.7/jquery.flot.selection.js"); Requirements::javascript("personalisation/thirdparty/flot-0.7/jquery.flot.resize.js"); Requirements::customScript( "var personalisationReportsBase='" . PersonalisationReportController::$base_link . "';" ); } public function getReport() { } public function Breadcrumbs($unlinked = false) { return new ArrayList(); } public function Backlink() { return 'admin/personalisation'; } } class GridFieldConfig_RecordEditor_Personalisation extends GridFieldConfig { /** * * @param int $itemsPerPage - How many items per page should show up */ public function __construct($itemsPerPage=null) { $this->addComponent(new GridFieldButtonRow('before')); $this->addComponent(new GridFieldAddNewButton_Personalisation('buttons-before-left')); $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent($sort = new GridFieldSortableHeader()); $this->addComponent($filter = new GridFieldFilterHeader()); $this->addComponent(new GridFieldDataColumns()); $this->addComponent(new GridFieldEditButton()); //$this->addComponent(new GridFieldDeleteAction()); $this->addComponent(new GridFieldPageCount('toolbar-header-right')); $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage)); $gridDetailForm = new GridFieldDetailForm(); $gridDetailForm->setItemRequestClass('GridFieldDetailFormPersonalisation_ItemRequest'); $this->addComponent($gridDetailForm); $sort->setThrowExceptionOnBadDataType(false); $filter->setThrowExceptionOnBadDataType(false); $pagination->setThrowExceptionOnBadDataType(false); } public function getReports() { return "foo"; } } class GridFieldDetailFormPersonalisation_ItemRequest extends GridFieldDetailForm_ItemRequest { public function __construct($gridField, $component, $record, $popupController, $popupFormName) { $params = Controller::curr()->request->allParams(); if ($params['ID'] == 'new') { $record = new $params['ModelClass']; } $this->gridField = $gridField; $this->component = $component; $this->record = $record; $this->popupController = $popupController; $this->popupFormName = $popupFormName; parent::__construct($gridField, $component, $record, $popupController, $popupFormName); } } class GridFieldAddNewButton_Personalisation implements GridField_HTMLProvider { protected $targetFragment; protected $buttonName; public function setButtonName($name) { $this->buttonName = $name; return $this; } public function __construct($targetFragment = 'before') { $this->targetFragment = $targetFragment; } public function getHTMLFragments($gridField) { if (!$this->buttonName) { $objectName = singleton($gridField->getModelClass())->i18n_singular_name(); $this->buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName)); } $managedClasses = PersonalisationAdmin::managed_personalisation_models(); $buttons = new ArrayList(); foreach ($managedClasses as $managedClass) { $gridField->setModelClass($managedClass); $gridField->getForm()->setFormAction('admin/personalisation/'.$managedClass.'/EditForm/'); $gridField->setName($managedClass); $buttons->push(new ArrayData(array( 'NewLink' => Controller::join_links($gridField->Link('item'), 'new'), 'ButtonName' => ucwords(trim(strtolower(preg_replace('/_?([A-Z])/', ' $1', $managedClass)))) ))); } $data = new ArrayData(array( 'Buttons' => $buttons )); return array( $this->targetFragment => $data->renderWith('GridFieldAddNewbutton_Personalisation'), ); } } |