コード例 #1
0
 public function getCMSFields()
 {
     $f = parent::getCMSFields();
     // hack
     $this->SummitID = $_REQUEST['SummitID'];
     $this->VenueID = $_REQUEST['VenueID'];
     $f->addFieldToTab('Root.Main', new NumericField('Capacity', 'Capacity'));
     $f->addFieldToTab('Root.Main', new CheckboxField('OverrideBlackouts', 'Overrides Blackouts'));
     $f->addFieldToTab('Root.Main', new HiddenField('VenueID', 'VenueID'));
     $f->addFieldToTab('Root.Main', $ddl_floor = new DropdownField('FloorID', 'Floor', SummitVenueFloor::get()->filter('VenueID', $this->VenueID)->map("ID", "FullName")));
     $ddl_floor->setEmptyString("-- SELECT A FLOOR --");
     $f->addFieldToTab('Root.Main', $upload_field = new UploadField('Image', 'Map'));
     $upload_field->setAllowedMaxFileNumber(1);
     $upload_field->setFolderName(sprintf('summits/%s/locations/%s/rooms/', $_REQUEST['SummitID'], $_REQUEST['LocationID']));
     $upload_field->getValidator()->setAllowedMaxFileSize(array('*' => 512 * 1024));
     if ($this->ID > 0) {
         $config = GridFieldConfig_RecordEditor::create();
         $gridField = new GridField('Metrics', 'Metrics', $this->Metrics(), $config);
         $f->addFieldToTab('Root.Main', $gridField);
     }
     return $f;
 }
コード例 #2
0
 /**
  * @return ValidationResult
  */
 protected function validate()
 {
     $valid = parent::validate();
     if (!$valid->valid()) {
         return $valid;
     }
     $name = trim($this->Name);
     if (empty($name)) {
         return $valid->error('Name is mandatory!');
     }
     $number = intval($this->Number);
     if ($number < 0) {
         return $valid->error('Number should be greather or equal than zero!');
     }
     if (SummitVenueFloor::get()->filter(["VenueID" => $this->VenueID, "ID:ExactMatch:not" => $this->ID, "Number" => $this->Number])->count() > 0) {
         return $valid->error(sprintf("There is already a floor with that number on venue %s", $this->VenueID));
     }
     if (SummitVenueFloor::get()->filter(["VenueID" => $this->VenueID, "ID:ExactMatch:not" => $this->ID, "Name" => $this->Name])->count() > 0) {
         return $valid->error(sprintf("There is already a floor with that name on venue %s", $this->VenueID));
     }
     return $valid;
 }