Made some things for real estate website
Nimekiri.php (Page type)
<?php
class Nimekiri extends Page
{
static $has_many = array (
'Objektid' => 'Objekt'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->removeFieldFromTab("Root.Content.Main","Content");
$manager = new DataObjectManager(
$this,
'Objektid',
'Objekt',
array('Objektinimi' => 'Objekti nimi', 'Kirjeldus' => 'Objekti kirjeldus'),
'getCMSFields_forPopup'
);
$f->addFieldToTab('Root.Content.Main', $manager);
return $f;
}
}
class Nimekiri_Controller extends Page_Controller {
function ObjektList() {
return DataObject::get("Objekt");
}
}
?>
Objekt.php (Dataobject)
<?php
class Objekt extends DataObject
{
static $db = array (
'Objektinimi' => 'Text',
'Kirjeldus' => 'HTMLText',
'Hind' => 'Text',
'Elamutyyp' => "Enum('Korter, Maja, Aripind, Suvila, Ridaelamu, Paarismaja, Maatykk')",
'Soojaveetyyp' => "Enum('Keskkyte, Elekter')",
'Kyttetyyp' => "Enum('Keskkyte, Elekter, Puukyte')",
'Tubadearv' => "Enum('1, 2, 3, 4,5,rohkem')",
'Krundisuurus' => 'Text',
'Yldpind' => 'Text',
'Korrus' => 'Text',
'Vannitube' => 'Text',
'Tualette' => 'Text',
'Aadress' => 'Text',
'Linn' => 'Text',
'Vald' => 'Text',
'Maakond' => 'Text'
);
static $has_one = array (
'Nimekiri' => 'Nimekiri',
'Photo' => 'Image'
);
static $has_many = array (
'GalleryImages' => 'GalleryImage'
);
static $searchable_fields = array(
'Elamutyyp' => 'ExactMatchFilter',
'Yldpind' => 'ExactMatchFilter',
'Linn' => 'ExactMatchFilter',
'Tubadearv' => 'ExactMatchFilter'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Objektinimi'),
new SimpleWysiwygField('Kirjeldus'),
new DropdownField(
'Elamutyyp',
'Elamutyyp',
singleton('Objekt')->dbObject('Elamutyyp')->enumValues()),
new DropdownField(
'Soojaveetyyp',
'Soojaveetyyp',
singleton('Objekt')->dbObject('Soojaveetyyp')->enumValues()),
new DropdownField(
'Kyttetyyp',
'Kyttetyyp',
singleton('Objekt')->dbObject('Kyttetyyp')->enumValues()),
new TextField('Hind'),
new TextField('Krundisuurus'),
new TextField('Yldpind'),
new DropdownField(
'Tubadearv',
'Tubadearv',
singleton('Objekt')->dbObject('Tubadearv')->enumValues()),
new TextField('Korrus'),
new TextField('Vannitube'),
new TextField('Tualette'),
new ImageField('Photo'),
new TextField('Aadress'),
new TextField('Linn'),
new TextField('Vald'),
new TextField('Maakond'),
new ImageDataObjectManager(
$this,
'GalleryImages', // Source name
'GalleryImage', // Source class
'MyGalleryImage', // File name on DataObject
array('Pildinimi' => 'Pildinimi'))
);
}
public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array('Elamutyyp','Yldpind','Linn','Tubadearv')
);
$filters = array(
'Elamutyyp' => new ExactMatchFilter('Elamutyyp'),
'Yldpind' => new ExactMatchFilter('Yldpind'),
'Linn' => new ExactMatchFilter('Linn'),
'Tubadearv' => new ExactMatchFilter('Tubadearv')
);
return new SearchContext(
$this->class,
$fields,
$filters
);
}
}
?>