public function getCMSFields() { $fields = FieldList::create(new TabSet($name = 'Root', new Tab($title = 'Main', HeaderField::create('ContactHD', 'Contact Information'), TextField::create('Title', 'Name'), TextField::create('Phone'), EmailField::create('Email', 'Email'), TextField::create('Website')->setAttribute('placeholder', 'http://'), DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))->setEmptyString('-- select --'), CheckboxField::create('ShowInLocator', 'Show in results')->setDescription('Location will be included in results list'), CheckboxField::create('Featured')->setDescription('Location will show at/near the top of the results list')))); // allow to be extended via DataExtension $this->extend('updateCMSFields', $fields); // override Suburb field name $fields->dataFieldByName('Suburb')->setTitle('City'); return $fields; }
public static function getCategoryByName(&$obj, $val, $record) { $val = Convert::raw2sql($val); $category = LocationCategory::get()->filter(array('Name' => $val))->First(); if (!$category) { $category = LocationCategory::create(); $category->Name = $val; $category->write(); } return $category; }
public function getCMSFields() { $fields = parent::getCMSFields(); // remove Main tab $fields->removeByName('Main'); // create and populate Info tab $fields->addFieldsToTab('Root.Info', array(HeaderField::create('InfoHeader', 'Contact Information'), TextField::create('Website'), TextField::create('EmailAddress'), TextField::create('Phone'))); // change label of Suburb from Addressable to City $fields->removeByName('Suburb'); $fields->insertBefore(TextField::create('Suburb', 'City'), 'State'); // If categories have been created, show category drop down if (LocationCategory::get()->Count() > 0) { $fields->insertAfter(DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))->setEmptyString('-- select --'), 'Phone'); } // move Title and ShowInLocator fields to Address tab from Addressable $fields->insertAfter(TextField::create('Title'), 'AddressHeader'); $fields->insertAfter(CheckboxField::create('Featured', 'Featured'), 'Title'); $fields->insertAfter(CheckboxField::create('ShowInLocator', 'Show on Map'), 'Country'); // allow to be extended via DataExtension $this->extend('updateCMSFields', $fields); return $fields; }
/** * @return DataList */ public static function get_all_categories() { return LocationCategory::get(); }
/** * LocationSearch form. * * Search form for locations, updates map and results list via AJAX * * @return Form */ public function LocationSearch() { $fields = FieldList::create($address = TextField::create('address', '')); $address->setAttribute('placeholder', 'address or zip code'); if (LocationCategory::get()->Count() > 0) { $filter = array(); $locals = Locator::getLocations($filter, $exclude = array('CategoryID' => 0)); $categories = ArrayList::create(); foreach ($locals as $local) { $categories->add($local->Category()); } if ($categories->count() > 0) { $fields->push(DropdownField::create('category', '', $categories->map('Title', 'Title'))->setEmptyString('Select Category')); } } $actions = FieldList::create(FormAction::create('', 'Search')); return Form::create($this, 'LocationSearch', $fields, $actions); }
public static function getCatByName(&$obj, $val, $record) { $val = Convert::raw2sql($val); return LocationCategory::get()->filter('Name', $val)->First(); //); }