@@ -2,21 +2,21 @@ |
||
| 2 | 2 | |
| 3 | 3 | class DistanceDataExtension extends DataExtension |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * @param SQLQuery $query |
|
| 7 | - */ |
|
| 8 | - public function augmentSQL(SQLQuery &$query) |
|
| 9 | - { |
|
| 10 | - if (Controller::curr()->getRequest()->getVar('Address')) { // on frontend |
|
| 11 | - $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 5 | + /** |
|
| 6 | + * @param SQLQuery $query |
|
| 7 | + */ |
|
| 8 | + public function augmentSQL(SQLQuery &$query) |
|
| 9 | + { |
|
| 10 | + if (Controller::curr()->getRequest()->getVar('Address')) { // on frontend |
|
| 11 | + $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 12 | 12 | |
| 13 | - $Lat = $coords['lat']; |
|
| 14 | - $Lng = $coords['lng']; |
|
| 13 | + $Lat = $coords['lat']; |
|
| 14 | + $Lng = $coords['lng']; |
|
| 15 | 15 | |
| 16 | - $query |
|
| 17 | - ->addSelect(array( |
|
| 18 | - '( 3959 * acos( cos( radians('.$Lat.') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians('.$Lng.') ) + sin( radians('.$Lat.') ) * sin( radians( `Lat` ) ) ) ) AS distance', |
|
| 19 | - )); |
|
| 20 | - } |
|
| 21 | - } |
|
| 16 | + $query |
|
| 17 | + ->addSelect(array( |
|
| 18 | + '( 3959 * acos( cos( radians('.$Lat.') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians('.$Lng.') ) + sin( radians('.$Lat.') ) * sin( radians( `Lat` ) ) ) ) AS distance', |
|
| 19 | + )); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -6,45 +6,45 @@ |
||
| 6 | 6 | class LocatorForm extends Form |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * LocatorForm constructor. |
|
| 11 | - * @param Controller $controller |
|
| 12 | - * @param string $name |
|
| 13 | - */ |
|
| 14 | - public function __construct(Controller $controller, $name) |
|
| 15 | - { |
|
| 9 | + /** |
|
| 10 | + * LocatorForm constructor. |
|
| 11 | + * @param Controller $controller |
|
| 12 | + * @param string $name |
|
| 13 | + */ |
|
| 14 | + public function __construct(Controller $controller, $name) |
|
| 15 | + { |
|
| 16 | 16 | |
| 17 | - $fields = FieldList::create( |
|
| 18 | - TextField::create('Address') |
|
| 19 | - ->setTitle('') |
|
| 20 | - ->setAttribute('placeholder', 'address or zip code') |
|
| 21 | - ); |
|
| 17 | + $fields = FieldList::create( |
|
| 18 | + TextField::create('Address') |
|
| 19 | + ->setTitle('') |
|
| 20 | + ->setAttribute('placeholder', 'address or zip code') |
|
| 21 | + ); |
|
| 22 | 22 | |
| 23 | - $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0) |
|
| 24 | - ? Locator::locator_categories_by_locator($controller->data()->ID) |
|
| 25 | - : Locator::get_all_categories(); |
|
| 23 | + $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0) |
|
| 24 | + ? Locator::locator_categories_by_locator($controller->data()->ID) |
|
| 25 | + : Locator::get_all_categories(); |
|
| 26 | 26 | |
| 27 | - $categoriesField = DropdownField::create('CategoryID') |
|
| 28 | - ->setTitle('') |
|
| 29 | - ->setEmptyString('All Categories') |
|
| 30 | - ->setSource($categories->map()); |
|
| 27 | + $categoriesField = DropdownField::create('CategoryID') |
|
| 28 | + ->setTitle('') |
|
| 29 | + ->setEmptyString('All Categories') |
|
| 30 | + ->setSource($categories->map()); |
|
| 31 | 31 | |
| 32 | - $fields->push($categoriesField); |
|
| 32 | + $fields->push($categoriesField); |
|
| 33 | 33 | |
| 34 | - $this->extend('updateLocatorFormFields', $fields); |
|
| 34 | + $this->extend('updateLocatorFormFields', $fields); |
|
| 35 | 35 | |
| 36 | - $actions = FieldList::create( |
|
| 37 | - FormAction::create('doFilterLocations') |
|
| 38 | - ->setTitle('Search') |
|
| 39 | - ); |
|
| 36 | + $actions = FieldList::create( |
|
| 37 | + FormAction::create('doFilterLocations') |
|
| 38 | + ->setTitle('Search') |
|
| 39 | + ); |
|
| 40 | 40 | |
| 41 | - $this->extend('updateLocatorFormActions', $actions); |
|
| 41 | + $this->extend('updateLocatorFormActions', $actions); |
|
| 42 | 42 | |
| 43 | - $validator = RequiredFields::create(); |
|
| 43 | + $validator = RequiredFields::create(); |
|
| 44 | 44 | |
| 45 | - $this->extend('updateLocatorFormRequiredFields', $validator); |
|
| 45 | + $this->extend('updateLocatorFormRequiredFields', $validator); |
|
| 46 | 46 | |
| 47 | - parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 48 | - } |
|
| 47 | + parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -2,53 +2,53 @@ |
||
| 2 | 2 | |
| 3 | 3 | if (class_exists('BootstrapForm')) { |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Class LocatorForm |
|
| 7 | - */ |
|
| 8 | - class LocatorBootstrapForm extends BootstrapForm |
|
| 9 | - { |
|
| 5 | + /** |
|
| 6 | + * Class LocatorForm |
|
| 7 | + */ |
|
| 8 | + class LocatorBootstrapForm extends BootstrapForm |
|
| 9 | + { |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * LocatorForm constructor. |
|
| 13 | - * @param Controller $controller |
|
| 14 | - * @param string $name |
|
| 15 | - */ |
|
| 16 | - public function __construct(Controller $controller, $name) |
|
| 17 | - { |
|
| 11 | + /** |
|
| 12 | + * LocatorForm constructor. |
|
| 13 | + * @param Controller $controller |
|
| 14 | + * @param string $name |
|
| 15 | + */ |
|
| 16 | + public function __construct(Controller $controller, $name) |
|
| 17 | + { |
|
| 18 | 18 | |
| 19 | - $fields = FieldList::create( |
|
| 20 | - TextField::create('Address') |
|
| 21 | - ->setTitle('') |
|
| 22 | - ->setAttribute('placeholder', 'address or zip code') |
|
| 23 | - ); |
|
| 19 | + $fields = FieldList::create( |
|
| 20 | + TextField::create('Address') |
|
| 21 | + ->setTitle('') |
|
| 22 | + ->setAttribute('placeholder', 'address or zip code') |
|
| 23 | + ); |
|
| 24 | 24 | |
| 25 | - $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0) |
|
| 26 | - ? Locator::locator_categories_by_locator($controller->data()->ID) |
|
| 27 | - : Locator::get_all_categories(); |
|
| 25 | + $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0) |
|
| 26 | + ? Locator::locator_categories_by_locator($controller->data()->ID) |
|
| 27 | + : Locator::get_all_categories(); |
|
| 28 | 28 | |
| 29 | - $categoriesField = DropdownField::create('CategoryID') |
|
| 30 | - ->setTitle('') |
|
| 31 | - ->setEmptyString('All Categories') |
|
| 32 | - ->setSource($categories->map()); |
|
| 29 | + $categoriesField = DropdownField::create('CategoryID') |
|
| 30 | + ->setTitle('') |
|
| 31 | + ->setEmptyString('All Categories') |
|
| 32 | + ->setSource($categories->map()); |
|
| 33 | 33 | |
| 34 | - $fields->push($categoriesField); |
|
| 34 | + $fields->push($categoriesField); |
|
| 35 | 35 | |
| 36 | - $this->extend('updateLocatorFormFields', $fields); |
|
| 36 | + $this->extend('updateLocatorFormFields', $fields); |
|
| 37 | 37 | |
| 38 | - $actions = FieldList::create( |
|
| 39 | - FormAction::create('doFilterLocations') |
|
| 40 | - ->setTitle('Search') |
|
| 41 | - ); |
|
| 38 | + $actions = FieldList::create( |
|
| 39 | + FormAction::create('doFilterLocations') |
|
| 40 | + ->setTitle('Search') |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - $this->extend('updateLocatorFormActions', $actions); |
|
| 43 | + $this->extend('updateLocatorFormActions', $actions); |
|
| 44 | 44 | |
| 45 | - $validator = RequiredFields::create(); |
|
| 45 | + $validator = RequiredFields::create(); |
|
| 46 | 46 | |
| 47 | - $this->extend('updateLocatorFormRequiredFields', $validator); |
|
| 47 | + $this->extend('updateLocatorFormRequiredFields', $validator); |
|
| 48 | 48 | |
| 49 | - parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 50 | - } |
|
| 49 | + parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -11,137 +11,137 @@ discard block |
||
| 11 | 11 | class Locator extends Page |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - private static $db = array( |
|
| 18 | - 'AutoGeocode' => 'Boolean', |
|
| 19 | - 'ModalWindow' => 'Boolean', |
|
| 20 | - 'Unit' => 'Enum("m,km","m")', |
|
| 21 | - ); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - private static $many_many = array( |
|
| 27 | - 'Categories' => 'LocationCategory', |
|
| 28 | - ); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private static $defaults = array( |
|
| 34 | - 'AutoGeocode' => true, |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - private static $singular_name = 'Locator'; |
|
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private static $plural_name = 'Locators'; |
|
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - private static $description = 'Find locations on a map'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return FieldList |
|
| 52 | - */ |
|
| 53 | - public function getCMSFields() |
|
| 54 | - { |
|
| 55 | - $fields = parent::getCMSFields(); |
|
| 56 | - |
|
| 57 | - // Settings |
|
| 58 | - $fields->addFieldsToTab('Root.Settings', array( |
|
| 59 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 60 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 61 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 62 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 63 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 64 | - )); |
|
| 65 | - |
|
| 66 | - // Filter categories |
|
| 67 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 68 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 69 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 70 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 71 | - } |
|
| 72 | - $categories = $this->Categories(); |
|
| 73 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 74 | - ->setDescription('only show locations from the selected category'); |
|
| 75 | - |
|
| 76 | - // Filter |
|
| 77 | - $fields->addFieldsToTab('Root.Filter', array( |
|
| 78 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 79 | - $categoriesField, |
|
| 80 | - )); |
|
| 81 | - |
|
| 82 | - $this->extend('updateCMSFields', $fields); |
|
| 83 | - |
|
| 84 | - return $fields; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param array $filter |
|
| 89 | - * @param array $filterAny |
|
| 90 | - * @param array $exclude |
|
| 91 | - * @param null|callable $callback |
|
| 92 | - * @return DataList|ArrayList |
|
| 93 | - */ |
|
| 94 | - public static function get_locations( |
|
| 95 | - $filter = [], |
|
| 96 | - $filterAny = [], |
|
| 97 | - $exclude = [], |
|
| 98 | - $callback = null |
|
| 99 | - ) |
|
| 100 | - { |
|
| 101 | - $locations = Location::get()->filter($filter)->exclude($exclude); |
|
| 102 | - |
|
| 103 | - if (!empty($filterAny)) { |
|
| 104 | - $locations = $locations->filterAny($filterAny); |
|
| 105 | - } |
|
| 106 | - if (!empty($exclude)) { |
|
| 107 | - $locations = $locations->exclude($exclude); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ($callback !== null && is_callable($callback)) { |
|
| 111 | - $locations->filterByCallback($callback); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $locations; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return DataList |
|
| 119 | - */ |
|
| 120 | - public static function get_all_categories() |
|
| 121 | - { |
|
| 122 | - return LocationCategory::get(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 128 | - public function getPageCategories() |
|
| 129 | - { |
|
| 130 | - return self::locator_categories_by_locator($this->ID); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param int $id |
|
| 135 | - * @return bool| |
|
| 136 | - */ |
|
| 137 | - public static function locator_categories_by_locator($id = 0) |
|
| 138 | - { |
|
| 139 | - if ($id == 0) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return Locator::get()->byID($id)->Categories(); |
|
| 144 | - } |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + private static $db = array( |
|
| 18 | + 'AutoGeocode' => 'Boolean', |
|
| 19 | + 'ModalWindow' => 'Boolean', |
|
| 20 | + 'Unit' => 'Enum("m,km","m")', |
|
| 21 | + ); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + private static $many_many = array( |
|
| 27 | + 'Categories' => 'LocationCategory', |
|
| 28 | + ); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private static $defaults = array( |
|
| 34 | + 'AutoGeocode' => true, |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + private static $singular_name = 'Locator'; |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private static $plural_name = 'Locators'; |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + private static $description = 'Find locations on a map'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return FieldList |
|
| 52 | + */ |
|
| 53 | + public function getCMSFields() |
|
| 54 | + { |
|
| 55 | + $fields = parent::getCMSFields(); |
|
| 56 | + |
|
| 57 | + // Settings |
|
| 58 | + $fields->addFieldsToTab('Root.Settings', array( |
|
| 59 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 60 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 61 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 62 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 63 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 64 | + )); |
|
| 65 | + |
|
| 66 | + // Filter categories |
|
| 67 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 68 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 69 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 70 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 71 | + } |
|
| 72 | + $categories = $this->Categories(); |
|
| 73 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 74 | + ->setDescription('only show locations from the selected category'); |
|
| 75 | + |
|
| 76 | + // Filter |
|
| 77 | + $fields->addFieldsToTab('Root.Filter', array( |
|
| 78 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 79 | + $categoriesField, |
|
| 80 | + )); |
|
| 81 | + |
|
| 82 | + $this->extend('updateCMSFields', $fields); |
|
| 83 | + |
|
| 84 | + return $fields; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param array $filter |
|
| 89 | + * @param array $filterAny |
|
| 90 | + * @param array $exclude |
|
| 91 | + * @param null|callable $callback |
|
| 92 | + * @return DataList|ArrayList |
|
| 93 | + */ |
|
| 94 | + public static function get_locations( |
|
| 95 | + $filter = [], |
|
| 96 | + $filterAny = [], |
|
| 97 | + $exclude = [], |
|
| 98 | + $callback = null |
|
| 99 | + ) |
|
| 100 | + { |
|
| 101 | + $locations = Location::get()->filter($filter)->exclude($exclude); |
|
| 102 | + |
|
| 103 | + if (!empty($filterAny)) { |
|
| 104 | + $locations = $locations->filterAny($filterAny); |
|
| 105 | + } |
|
| 106 | + if (!empty($exclude)) { |
|
| 107 | + $locations = $locations->exclude($exclude); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ($callback !== null && is_callable($callback)) { |
|
| 111 | + $locations->filterByCallback($callback); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $locations; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return DataList |
|
| 119 | + */ |
|
| 120 | + public static function get_all_categories() |
|
| 121 | + { |
|
| 122 | + return LocationCategory::get(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | + public function getPageCategories() |
|
| 129 | + { |
|
| 130 | + return self::locator_categories_by_locator($this->ID); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param int $id |
|
| 135 | + * @return bool| |
|
| 136 | + */ |
|
| 137 | + public static function locator_categories_by_locator($id = 0) |
|
| 138 | + { |
|
| 139 | + if ($id == 0) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return Locator::get()->byID($id)->Categories(); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | } |
@@ -151,106 +151,106 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | class Locator_Controller extends Page_Controller |
| 153 | 153 | { |
| 154 | - /** |
|
| 155 | - * @var array |
|
| 156 | - */ |
|
| 157 | - private static $allowed_actions = array( |
|
| 158 | - 'xml', |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @var array |
|
| 163 | - */ |
|
| 164 | - private static $base_filter = [ |
|
| 165 | - 'ShowInLocator' => true, |
|
| 166 | - ]; |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @var array |
|
| 170 | - */ |
|
| 171 | - private static $base_exclude = [ |
|
| 172 | - 'Lat' => 0, |
|
| 173 | - 'Lng' => 0, |
|
| 174 | - ]; |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @var array |
|
| 178 | - */ |
|
| 179 | - private static $base_filter_any = []; |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @var string |
|
| 183 | - */ |
|
| 184 | - private static $list_template_path = 'locator/templates/location-list-description.html'; |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @var string |
|
| 188 | - */ |
|
| 189 | - private static $info_window_template_path = 'locator/templates/infowindow-description.html'; |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @var DataList|ArrayList |
|
| 193 | - */ |
|
| 194 | - private $locations; |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Set Requirements based on input from CMS |
|
| 198 | - */ |
|
| 199 | - public function init() |
|
| 200 | - { |
|
| 201 | - parent::init(); |
|
| 202 | - |
|
| 203 | - // google maps api key |
|
| 204 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 205 | - |
|
| 206 | - $locations = $this->getLocations(); |
|
| 207 | - |
|
| 208 | - if ($locations) { |
|
| 209 | - |
|
| 210 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 211 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 212 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 213 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 214 | - Requirements::css('locator/css/map.css'); |
|
| 215 | - |
|
| 216 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 217 | - $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : ''; |
|
| 218 | - $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE); |
|
| 219 | - |
|
| 220 | - $featured = $featuredInList |
|
| 221 | - ? 'featuredLocations: true' |
|
| 222 | - : 'featuredLocations: false'; |
|
| 223 | - |
|
| 224 | - // map config based on user input in Settings tab |
|
| 225 | - // AutoGeocode or Full Map |
|
| 226 | - if ($this->data()->AutoGeocode) { |
|
| 227 | - $load = $featuredInList || $defaultCoords || $isChrome != '' |
|
| 228 | - ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
| 229 | - : 'autoGeocode: true, fullMapStart: false,'; |
|
| 230 | - } else { |
|
| 231 | - $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $listTemplatePath = $this->config()->get('list_template_path'); |
|
| 235 | - $infowindowTemplatePath = $this->config()->get('info_window_template_path'); |
|
| 236 | - |
|
| 237 | - // in page or modal |
|
| 238 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 239 | - |
|
| 240 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 241 | - |
|
| 242 | - // pass GET variables to xml action |
|
| 243 | - $vars = $this->request->getVars(); |
|
| 244 | - unset($vars['url']); |
|
| 245 | - unset($vars['action_doFilterLocations']); |
|
| 246 | - $url = ''; |
|
| 247 | - if (count($vars)) { |
|
| 248 | - $url .= '?' . http_build_query($vars); |
|
| 249 | - } |
|
| 250 | - $link = $this->Link() . 'xml.xml' . $url; |
|
| 251 | - |
|
| 252 | - // init map |
|
| 253 | - Requirements::customScript(" |
|
| 154 | + /** |
|
| 155 | + * @var array |
|
| 156 | + */ |
|
| 157 | + private static $allowed_actions = array( |
|
| 158 | + 'xml', |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @var array |
|
| 163 | + */ |
|
| 164 | + private static $base_filter = [ |
|
| 165 | + 'ShowInLocator' => true, |
|
| 166 | + ]; |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @var array |
|
| 170 | + */ |
|
| 171 | + private static $base_exclude = [ |
|
| 172 | + 'Lat' => 0, |
|
| 173 | + 'Lng' => 0, |
|
| 174 | + ]; |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @var array |
|
| 178 | + */ |
|
| 179 | + private static $base_filter_any = []; |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @var string |
|
| 183 | + */ |
|
| 184 | + private static $list_template_path = 'locator/templates/location-list-description.html'; |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @var string |
|
| 188 | + */ |
|
| 189 | + private static $info_window_template_path = 'locator/templates/infowindow-description.html'; |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @var DataList|ArrayList |
|
| 193 | + */ |
|
| 194 | + private $locations; |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Set Requirements based on input from CMS |
|
| 198 | + */ |
|
| 199 | + public function init() |
|
| 200 | + { |
|
| 201 | + parent::init(); |
|
| 202 | + |
|
| 203 | + // google maps api key |
|
| 204 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 205 | + |
|
| 206 | + $locations = $this->getLocations(); |
|
| 207 | + |
|
| 208 | + if ($locations) { |
|
| 209 | + |
|
| 210 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 211 | + Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 212 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 213 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 214 | + Requirements::css('locator/css/map.css'); |
|
| 215 | + |
|
| 216 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 217 | + $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : ''; |
|
| 218 | + $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE); |
|
| 219 | + |
|
| 220 | + $featured = $featuredInList |
|
| 221 | + ? 'featuredLocations: true' |
|
| 222 | + : 'featuredLocations: false'; |
|
| 223 | + |
|
| 224 | + // map config based on user input in Settings tab |
|
| 225 | + // AutoGeocode or Full Map |
|
| 226 | + if ($this->data()->AutoGeocode) { |
|
| 227 | + $load = $featuredInList || $defaultCoords || $isChrome != '' |
|
| 228 | + ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
| 229 | + : 'autoGeocode: true, fullMapStart: false,'; |
|
| 230 | + } else { |
|
| 231 | + $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $listTemplatePath = $this->config()->get('list_template_path'); |
|
| 235 | + $infowindowTemplatePath = $this->config()->get('info_window_template_path'); |
|
| 236 | + |
|
| 237 | + // in page or modal |
|
| 238 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 239 | + |
|
| 240 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 241 | + |
|
| 242 | + // pass GET variables to xml action |
|
| 243 | + $vars = $this->request->getVars(); |
|
| 244 | + unset($vars['url']); |
|
| 245 | + unset($vars['action_doFilterLocations']); |
|
| 246 | + $url = ''; |
|
| 247 | + if (count($vars)) { |
|
| 248 | + $url .= '?' . http_build_query($vars); |
|
| 249 | + } |
|
| 250 | + $link = $this->Link() . 'xml.xml' . $url; |
|
| 251 | + |
|
| 252 | + // init map |
|
| 253 | + Requirements::customScript(" |
|
| 254 | 254 | $(function(){ |
| 255 | 255 | $('#map-container').storeLocator({ |
| 256 | 256 | " . $load . " |
@@ -269,128 +269,128 @@ discard block |
||
| 269 | 269 | }); |
| 270 | 270 | }); |
| 271 | 271 | '); |
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @param SS_HTTPRequest $request |
|
| 277 | - * |
|
| 278 | - * @return ViewableData_Customised |
|
| 279 | - */ |
|
| 280 | - public function index(SS_HTTPRequest $request) |
|
| 281 | - { |
|
| 282 | - $locations = $this->getLocations(); |
|
| 283 | - |
|
| 284 | - if ($locations->canSortBy('distance')) { |
|
| 285 | - $locations = $locations->sort('distance'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $this->customise(array( |
|
| 289 | - 'Locations' => $locations, |
|
| 290 | - )); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Return a XML feed of all locations marked "show in locator" |
|
| 295 | - * |
|
| 296 | - * @param SS_HTTPRequest $request |
|
| 297 | - * @return HTMLText |
|
| 298 | - */ |
|
| 299 | - public function xml(SS_HTTPRequest $request) |
|
| 300 | - { |
|
| 301 | - $locations = $this->getLocations(); |
|
| 302 | - |
|
| 303 | - if ($locations->canSortBy('distance')) { |
|
| 304 | - $locations = $locations->sort('distance'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $this->customise(array( |
|
| 308 | - 'Locations' => $locations, |
|
| 309 | - ))->renderWith('LocationXML'); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @return ArrayList|DataList |
|
| 314 | - */ |
|
| 315 | - public function getLocations() |
|
| 316 | - { |
|
| 317 | - if (!$this->locations) { |
|
| 318 | - $this->setLocations($this->request); |
|
| 319 | - } |
|
| 320 | - return $this->locations; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param SS_HTTPRequest|null $request |
|
| 325 | - * @return $this |
|
| 326 | - */ |
|
| 327 | - public function setLocations(SS_HTTPRequest $request = null) |
|
| 328 | - { |
|
| 329 | - |
|
| 330 | - if ($request === null) { |
|
| 331 | - $request = $this->request; |
|
| 332 | - } |
|
| 333 | - $filter = $this->config()->get('base_filter'); |
|
| 334 | - |
|
| 335 | - if ($request->getVar('CategoryID')) { |
|
| 336 | - $filter['CategoryID'] = $request->getVar('CategoryID'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - $this->extend('updateLocatorFilter', $filter, $request); |
|
| 340 | - |
|
| 341 | - $filterAny = $this->config()->get('base_filter_any'); |
|
| 342 | - $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 343 | - |
|
| 344 | - $exclude = $this->config()->get('base_exclude'); |
|
| 345 | - $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 346 | - |
|
| 347 | - $callback = null; |
|
| 348 | - $this->extend('updateLocatorCallback', $callback, $request); |
|
| 349 | - |
|
| 350 | - $locations = Locator::get_locations($filter, $filterAny, $exclude, $callback); |
|
| 351 | - $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 352 | - |
|
| 353 | - $this->locations = $locations; |
|
| 354 | - return $this; |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @return bool|string |
|
| 360 | - */ |
|
| 361 | - public function getAddressSearchCoords() |
|
| 362 | - { |
|
| 363 | - if (!$this->request->getVar('Address')) { |
|
| 364 | - return false; |
|
| 365 | - } |
|
| 366 | - $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 367 | - |
|
| 368 | - $lat = $coords['lat']; |
|
| 369 | - $lng = $coords['lng']; |
|
| 370 | - |
|
| 371 | - return "defaultLat: {$lat}, defaultLng: {$lng},"; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * LocationSearch form. |
|
| 376 | - * |
|
| 377 | - * Search form for locations, updates map and results list via AJAX |
|
| 378 | - * |
|
| 379 | - * @return Form |
|
| 380 | - */ |
|
| 381 | - public function LocationSearch() |
|
| 382 | - { |
|
| 383 | - if (class_exists('BootstrapForm')) { |
|
| 384 | - $form = LocatorBootstrapForm::create($this, 'LocationSearch'); |
|
| 385 | - } else { |
|
| 386 | - $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $form |
|
| 390 | - ->setFormMethod('GET') |
|
| 391 | - ->setFormAction($this->Link()) |
|
| 392 | - ->disableSecurityToken() |
|
| 393 | - ->loadDataFrom($this->request->getVars()); |
|
| 394 | - } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @param SS_HTTPRequest $request |
|
| 277 | + * |
|
| 278 | + * @return ViewableData_Customised |
|
| 279 | + */ |
|
| 280 | + public function index(SS_HTTPRequest $request) |
|
| 281 | + { |
|
| 282 | + $locations = $this->getLocations(); |
|
| 283 | + |
|
| 284 | + if ($locations->canSortBy('distance')) { |
|
| 285 | + $locations = $locations->sort('distance'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $this->customise(array( |
|
| 289 | + 'Locations' => $locations, |
|
| 290 | + )); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Return a XML feed of all locations marked "show in locator" |
|
| 295 | + * |
|
| 296 | + * @param SS_HTTPRequest $request |
|
| 297 | + * @return HTMLText |
|
| 298 | + */ |
|
| 299 | + public function xml(SS_HTTPRequest $request) |
|
| 300 | + { |
|
| 301 | + $locations = $this->getLocations(); |
|
| 302 | + |
|
| 303 | + if ($locations->canSortBy('distance')) { |
|
| 304 | + $locations = $locations->sort('distance'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $this->customise(array( |
|
| 308 | + 'Locations' => $locations, |
|
| 309 | + ))->renderWith('LocationXML'); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @return ArrayList|DataList |
|
| 314 | + */ |
|
| 315 | + public function getLocations() |
|
| 316 | + { |
|
| 317 | + if (!$this->locations) { |
|
| 318 | + $this->setLocations($this->request); |
|
| 319 | + } |
|
| 320 | + return $this->locations; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param SS_HTTPRequest|null $request |
|
| 325 | + * @return $this |
|
| 326 | + */ |
|
| 327 | + public function setLocations(SS_HTTPRequest $request = null) |
|
| 328 | + { |
|
| 329 | + |
|
| 330 | + if ($request === null) { |
|
| 331 | + $request = $this->request; |
|
| 332 | + } |
|
| 333 | + $filter = $this->config()->get('base_filter'); |
|
| 334 | + |
|
| 335 | + if ($request->getVar('CategoryID')) { |
|
| 336 | + $filter['CategoryID'] = $request->getVar('CategoryID'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + $this->extend('updateLocatorFilter', $filter, $request); |
|
| 340 | + |
|
| 341 | + $filterAny = $this->config()->get('base_filter_any'); |
|
| 342 | + $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 343 | + |
|
| 344 | + $exclude = $this->config()->get('base_exclude'); |
|
| 345 | + $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 346 | + |
|
| 347 | + $callback = null; |
|
| 348 | + $this->extend('updateLocatorCallback', $callback, $request); |
|
| 349 | + |
|
| 350 | + $locations = Locator::get_locations($filter, $filterAny, $exclude, $callback); |
|
| 351 | + $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 352 | + |
|
| 353 | + $this->locations = $locations; |
|
| 354 | + return $this; |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @return bool|string |
|
| 360 | + */ |
|
| 361 | + public function getAddressSearchCoords() |
|
| 362 | + { |
|
| 363 | + if (!$this->request->getVar('Address')) { |
|
| 364 | + return false; |
|
| 365 | + } |
|
| 366 | + $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address')); |
|
| 367 | + |
|
| 368 | + $lat = $coords['lat']; |
|
| 369 | + $lng = $coords['lng']; |
|
| 370 | + |
|
| 371 | + return "defaultLat: {$lat}, defaultLng: {$lng},"; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * LocationSearch form. |
|
| 376 | + * |
|
| 377 | + * Search form for locations, updates map and results list via AJAX |
|
| 378 | + * |
|
| 379 | + * @return Form |
|
| 380 | + */ |
|
| 381 | + public function LocationSearch() |
|
| 382 | + { |
|
| 383 | + if (class_exists('BootstrapForm')) { |
|
| 384 | + $form = LocatorBootstrapForm::create($this, 'LocationSearch'); |
|
| 385 | + } else { |
|
| 386 | + $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $form |
|
| 390 | + ->setFormMethod('GET') |
|
| 391 | + ->setFormAction($this->Link()) |
|
| 392 | + ->disableSecurityToken() |
|
| 393 | + ->loadDataFrom($this->request->getVars()); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | } |
@@ -6,108 +6,108 @@ |
||
| 6 | 6 | class LocatorTest extends Locator_Test |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * |
|
| 11 | - */ |
|
| 12 | - public function testGetCMSFields() |
|
| 13 | - { |
|
| 14 | - $locator = singleton('Locator'); |
|
| 15 | - $this->assertInstanceOf('FieldList', $locator->getCMSFields()); |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function testLocations() |
|
| 22 | - { |
|
| 23 | - $filter = Config::inst()->get('Locator_Controller', 'base_filter'); |
|
| 24 | - $filterAny = Config::inst()->get('Locator_Controller', 'base_filter_any'); |
|
| 25 | - $exclude = Config::inst()->get('Locator_Controller', 'base_exclude'); |
|
| 26 | - $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 27 | - $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 28 | - $this->assertEquals($locations->count(), $locations2->count()); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function testGetAllCategories() |
|
| 35 | - { |
|
| 36 | - |
|
| 37 | - $this->assertEquals(Locator::get_all_categories()->count(), 4); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - */ |
|
| 43 | - public function testGetPageCategories() |
|
| 44 | - { |
|
| 45 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 46 | - $this->assertEquals($locator->getPageCategories()->count(), 2); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function testLocatorCategoriesByLocator() |
|
| 53 | - { |
|
| 54 | - |
|
| 55 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 56 | - $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2); |
|
| 57 | - |
|
| 58 | - $newLocator = Locator::create(); |
|
| 59 | - $newLocator->Title = 'Locator 2'; |
|
| 60 | - $newLocator->write(); |
|
| 61 | - |
|
| 62 | - $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - */ |
|
| 69 | - public function testInit() |
|
| 70 | - { |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * |
|
| 75 | - */ |
|
| 76 | - public function testIndex() |
|
| 77 | - { |
|
| 78 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 79 | - $controller = Locator_Controller::create($locator); |
|
| 80 | - $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * |
|
| 85 | - */ |
|
| 86 | - public function testXml() |
|
| 87 | - { |
|
| 88 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 89 | - $controller = Locator_Controller::create($locator); |
|
| 90 | - $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * |
|
| 95 | - */ |
|
| 96 | - public function testLocationSearch() |
|
| 97 | - { |
|
| 98 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 99 | - $object = Locator_Controller::create($locator); |
|
| 100 | - $form = $object->LocationSearch(); |
|
| 101 | - $this->assertTrue(is_a($form, 'Form')); |
|
| 102 | - |
|
| 103 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 104 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
| 105 | - $locator->Categories()->add($category); |
|
| 106 | - $locator->Categories()->add($category2); |
|
| 107 | - |
|
| 108 | - $form = $object->LocationSearch(); |
|
| 109 | - $fields = $form->Fields(); |
|
| 110 | - $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
| 111 | - } |
|
| 9 | + /** |
|
| 10 | + * |
|
| 11 | + */ |
|
| 12 | + public function testGetCMSFields() |
|
| 13 | + { |
|
| 14 | + $locator = singleton('Locator'); |
|
| 15 | + $this->assertInstanceOf('FieldList', $locator->getCMSFields()); |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function testLocations() |
|
| 22 | + { |
|
| 23 | + $filter = Config::inst()->get('Locator_Controller', 'base_filter'); |
|
| 24 | + $filterAny = Config::inst()->get('Locator_Controller', 'base_filter_any'); |
|
| 25 | + $exclude = Config::inst()->get('Locator_Controller', 'base_exclude'); |
|
| 26 | + $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 27 | + $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 28 | + $this->assertEquals($locations->count(), $locations2->count()); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function testGetAllCategories() |
|
| 35 | + { |
|
| 36 | + |
|
| 37 | + $this->assertEquals(Locator::get_all_categories()->count(), 4); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + */ |
|
| 43 | + public function testGetPageCategories() |
|
| 44 | + { |
|
| 45 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 46 | + $this->assertEquals($locator->getPageCategories()->count(), 2); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function testLocatorCategoriesByLocator() |
|
| 53 | + { |
|
| 54 | + |
|
| 55 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 56 | + $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 2); |
|
| 57 | + |
|
| 58 | + $newLocator = Locator::create(); |
|
| 59 | + $newLocator->Title = 'Locator 2'; |
|
| 60 | + $newLocator->write(); |
|
| 61 | + |
|
| 62 | + $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + */ |
|
| 69 | + public function testInit() |
|
| 70 | + { |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * |
|
| 75 | + */ |
|
| 76 | + public function testIndex() |
|
| 77 | + { |
|
| 78 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 79 | + $controller = Locator_Controller::create($locator); |
|
| 80 | + $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * |
|
| 85 | + */ |
|
| 86 | + public function testXml() |
|
| 87 | + { |
|
| 88 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 89 | + $controller = Locator_Controller::create($locator); |
|
| 90 | + $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * |
|
| 95 | + */ |
|
| 96 | + public function testLocationSearch() |
|
| 97 | + { |
|
| 98 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 99 | + $object = Locator_Controller::create($locator); |
|
| 100 | + $form = $object->LocationSearch(); |
|
| 101 | + $this->assertTrue(is_a($form, 'Form')); |
|
| 102 | + |
|
| 103 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 104 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
| 105 | + $locator->Categories()->add($category); |
|
| 106 | + $locator->Categories()->add($category2); |
|
| 107 | + |
|
| 108 | + $form = $object->LocationSearch(); |
|
| 109 | + $fields = $form->Fields(); |
|
| 110 | + $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |