03/08/2012 5:06pm

PHP | Problem - Course.php


<?php

class Course extends KursusGruppe {

static $icon = "cms/images/treeicons/task";

public static $db = array(
'StartDate' => 'Date',
'EndDate' => 'Date',
"TimeOfDay" => "Enum(',Formiddag,Eftermiddag')",
'City' => 'Varchar',
'Location' => 'Varchar',
'SpecialPeriod' => 'Varchar'
);

public static $has_one = array(
);

public static $has_many = array(
'CourseSignups' => 'CourseSignup'
);


static $searchable_fields = array(
'Title' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Kursus navn'
),
'City' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'By'
),
'Location' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Sted'
),
'StartDate' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Start dato'
),
'EndDate' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Slut dato'
),
'SpecialPeriod' => array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => 'Periode'
),
'TimeOfDay' => array(
'field' => 'TextField',
'filter' => 'ExactMatchFilter',
'title' => 'Tidspunkt'
)
);

static $summary_fields = array(
'Title' => 'Kursus titel',
'City' => 'By',
'Location' => 'Sted',
'StartDate' => 'Start dato',
'EndDate' => 'Slut dato',
'TimeOfDay' => 'Tidspunkt',
'Parent.Title' => 'Kursus gruppe'
);


public static $defaults = array(
'ShowNewsletterSignup' => false,
'ShowTestimonials' => false,
'ShowFind' => false,
'ShowInMenus' => false
);


public function getCMSFields() {
$fields = parent::getCMSFields();

// Adding custom fields to CMS
// http://doc.silverstripe.org/form-field-types

$startDateField = new DateField('StartDate', 'Start dato for kursus');
$startDateField->setConfig('showcalendar', true);
$startDateField->setLocale('da_DK');

$endDateField = new DateField('EndDate', 'Slut dato for kursus');
$endDateField->setConfig('showcalendar', true);
$startDateField->setLocale('da_DK');

$fields->addFieldToTab('Root.Content.Main', new TextField('City', 'By'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Location', 'Sted'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('SpecialPeriod', 'Kursus periode (hvis andet end start slut dato)'), 'Content');

$fields->addFieldToTab('Root.Content.Main', $startDateField, 'Content');
$fields->addFieldToTab('Root.Content.Main', $endDateField, 'Content');

$fields->addFieldToTab('Root.Content.Main', new DropdownField('TimeOfDay', 'Tidspunkt', singleton('Course')->dbObject('TimeOfDay')->enumValues()), 'Content');


$tablefield = new ComplexTableField(
$this,
'CourseSignups',
'CourseSignup',
array(
'FirstName' => 'Fornavn',
'LastName' => 'Efternavn',
'ZipCode' => 'Post nr.',
'City' => 'By',
'Email' => 'Email',
'Phone' => 'Telefon'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( ' tilmelding' );

$fields->addFieldToTab( 'Root.Content.Tilmeldinger', $tablefield );


return $fields;
}


public function getCustomSearchContext() {

$fields = $this->scaffoldSearchFields(array(
'restrictFields' => array(
//'Title',
'City',
'TimeOfDay'
//'Location',
//'StartDate'
//'EndDate'
),
'FieldClasses' => array(
'StartDate' => 'HiddenField'
)
));

$filters = array(
'Title' => new PartialMatchFilter('Title'),
'City' => new PartialMatchFilter('City'),
'TimeOfDay' => new ExactMatchFilter('TimeOfDay'),
'Location' => new PartialMatchFilter('Location'),
'StartDate' => new GreaterThanFilter('StartDate'),
'EndDate' => new LessThanFilter('EndDate')
);

// Create a dropdown of all available cities
$cities = DB::query('SELECT DISTINCT "City" FROM "Course" WHERE StartDate >= CURDATE() ORDER BY "CITY" ASC')->column();
$newCities = array_combine($cities, $cities);
$CityDropDownField = new DropdownField('City', 'By', $newCities);

$CityDropDownField->sethasEmptyDefault(true);
$fields->replaceField("City", $CityDropDownField);

// Create a dropdown of all available locations
$locations = DB::query('SELECT DISTINCT "Location" FROM "Course"')->column();
$newLocations = array_combine($locations, $locations);
$LocationsDropDownField = new DropdownField('Location', 'Sted', $newLocations);

$LocationsDropDownField->sethasEmptyDefault(true);
$fields->replaceField("Location", $LocationsDropDownField);

$TimeofDayDD = new DropdownField('TimeOfDay', 'Tidspunkt', singleton('Course')->dbObject('TimeOfDay')->enumValues());
$fields->replaceField("TimeOfDay", $TimeofDayDD);


return new SearchContext(
$this->class,
$fields,
$filters
);
}

}
class Course_Controller extends KursusGruppe_Controller {


public static $allowed_actions = array (
);


public function init() {
parent::init();

// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
//Requirements::themedCSS('layout');
//Requirements::themedCSS('typography');
//Requirements::themedCSS('form');
}



}
?>


Post Comment