Source of file NeighbourhoodFeature.php
Size: 2,673 Bytes - Last Modified: 2021-12-23T10:51:36+00:00
/var/www/docs.ssmods.com/process/src/code/DataObjects/NeighbourhoodFeature.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 | <?php /** * * @package Realestate Listing System - Neighbourhood DataObject * @requires DataObjectManager * @author Richard Rudy twitter:@thezenmonkey web: http://designplusawesome.com */ class NeighbourhoodFeature extends DataObject { /** * Static vars * ----------------------------------*/ /** * Object vars * ----------------------------------*/ /** * Static methods * ----------------------------------*/ /** * Data model * ----------------------------------*/ private static $db = array( 'Name' => 'Varchar', 'Address' => 'Varchar', 'Town' => 'Varchar', 'PostalCode' => 'Varchar(7)', 'Lat' => 'Varchar', 'Lon' => 'Varchar', 'Type' => "Enum('Elementary School,Middle School,Secondary School,RC Elementary School,RC Middle School,RC Secondary School,College,Shopping,Church,Synagogue,Mosque')", 'Grades' => 'Varchar', 'Note' => 'Varchar' ); private static $has_one = array( 'Neighbourhood' => 'NeighbourhoodPage', 'City' => 'MunicipalityPage' ); private static $belongs_many_many = array( 'Listings' => 'Listing' ); private static $summary_fields = array( 'Name' => 'Name', 'Type' => 'Type', 'City.Title' => 'City' ); private static $searchable_fields = array( 'Name', 'City.Title' ); /** * Common methods * ----------------------------------*/ function getCMSFields() { $cityfield = new DropdownField('CityID', 'City', MunicipalityPage::get()->map('ID', 'Title')); $cityfield->setEmptyString('(Select one)'); return new FieldList( new TextField('Name'), new TextField('Address'), $cityfield, new TextField('Town'), new TextField('PostalCode'), new DropdownField('Type','Type',singleton('NeighbourhoodFeature')->dbObject('Type')->enumValues()), new TextField('Grades'), new TextField('Note') ); } function onBeforeWrite() { parent::onBeforeWrite(); if ( is_null($this->Lat) || is_null($this->Lon) ) { $LatLon = Geocoder::Geocode($this->Address." ".$this->City()->Title." Ontario ".$this->PostalCode); if($LatLon) { $this->Lat = $LatLon["Lat"]; $this->Lon = $LatLon["Lon"]; } } } /** * Accessor methods * ----------------------------------*/ public function getGeocoded() { if($this->Lat != 0) { return "coded"; } else { return "uncoded"; } } /** * Controller actions * ----------------------------------*/ /** * Template accessors * ----------------------------------*/ public function CleanType() { return str_replace(" ", "", $this->Type); } /** * Object methods * ----------------------------------*/ } |