Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

static $db variable


Reply


1170 Views

Avatar
Nicolaas

Forum Moderator, 213 Posts

21 October 2007 at 4:12pm

Edited: 21/10/2007 4:13pm

Hi

I thought of a clever way to define database fields and database forms. I noticed that in writing things like complexTables and various forms on various pages, you have to rewrite a lot of things. That goes against my motto: never write anything twice.

My question is what can I replace XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with????? Is there a way to add those from the defining function?

Basically I want to define the static $db variables using a function.

<?php

/*
DEFINITION of fieldArray
0 dbfieldname,
1 dbformat,
2 formfield
3 required, 4 show in table list , 5 Ok field,
*/
class jobSubmissionDataObject extends DataObject {
var $data;
static $db = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
static $has_one = array(
"Parent" => "jobSubPage"
);

function __construct() {
$data = $this->VacancyDefinitions();
}

function getCMSFields($withOkfield = 1) {
$jobsDataObject->CMSFields();
return $fields;
}

function requiredFieldsObject() {
foreach($this->data as $ds) {
if($ds[0] && $ds[3]) {
$fieldsArray[] = $ds[0];
}
}
return new RequiredFields($fieldsArray);
}

function complexTableFields() {
foreach($this->data as $ds) {
if($ds[0] && $ds[4]) {
$fieldsArray[$ds[0]] = $ds[0];
}
}
return $fieldsArray;
}

private function CMSFields($withOkfield = 1) {
foreach($this->data as $ds) {
if(!$ds[5] || $withOkfield) {
$formFieldArray[] = $ds[2];
}
}
$fieldSet = new FieldSet( $formFieldArray);
return $fieldSet;
}

function databaseFields() {
$data = $this->VacancyDefinitions();
foreach($this->data as $ds) {
if($ds[0] && $ds[1]) {
$fieldsArray[$ds[0]] = $ds[1];
}
}
return $data;
}

/*
DEFINITION:
0 dbfieldname,
1 dbformat,
2 formfield
3 required, 4 show in table list , 5 Ok field,
*/

function VacancyDefinitions() {
$data = Array (
Array(
'Oked',
'Boolean',
new CheckboxField('Oked', 'Publish')
, 0, 1, 0
),

Array(
'',
'',
new HeaderField('Details of person completing this form:', 3, true)
, 0, 0, 0
),
Array(
'RequestorName',
'varchar(255)',
new TextField('RequestorName', 'Name')
, 1, 0, 0
),
Array(
'RequestorPosition',
'varchar(255)',
new TextField('RequestorPosition', 'Position')
, 1, 0, 0
),
Array(
'RequestorOrganisation',
'varchar(255)',
new TextField('RequestorOrganisation', 'Organisation')
, 1, 0, 0
),
Array(
'RequestorPhone',
'varchar(50)',
new TextField('RequestorPhone', 'Phone')
, 1, 0, 0
),
Array(
'RequestorEmail',
'varchar(255)',
new EmailField('RequestorEmail', 'Email')
, 1, 0, 0
)
);
return $data;
}

}