forked from science-ation/science-ation
- Update the table editor, instead of doing all that funky stuff for listing
the table, we call a method in the table helper class. That method returns 3 things.. an array of SELECT columns, an array of FROM tables, and an array of WHERE clauses. The table editor takes these, adds ORDER, LIMIT, etc, and runs the sql. - Update the table editor to allow variables to be set. THe helper class reads these variables to do pretty much anything it wants.. In this commit, it reads the judges_show_what variable, to determine how to format the SQL for selecting the table of judges (so the calling php can now know NOTHIGN about the database, it just sets a variable and expects the data to be formatted correctly. - Update the judge manager, show all judges should now SHOW ALL JUDGES.
This commit is contained in:
parent
418dc75cef
commit
3da0ba87e2
@ -56,7 +56,7 @@ function openjudgeinfo(id)
|
||||
if(isset($_POST['show_what'])) {
|
||||
$show_what = $_POST['show_what'];
|
||||
} else {
|
||||
$show_what = "all";
|
||||
$show_what = "cy_complete";
|
||||
}
|
||||
print("<form name=\"ShowJudges\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">");
|
||||
print("<select id=\"show_what\" name=\"show_what\">");
|
||||
@ -77,18 +77,13 @@ function openjudgeinfo(id)
|
||||
|
||||
switch($show_what) {
|
||||
case "all":
|
||||
$editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
||||
$editor->filterList("(judges_years.year={$config['FAIRYEAR']} OR judges_years.year IS NULL)");
|
||||
$editor->setOption('judges_show_what', 'all');
|
||||
break;
|
||||
case "cy_active":
|
||||
$editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
||||
$editor->filterList("(judges_years.year={$config['FAIRYEAR']})");
|
||||
$editor->setOption('judges_show_what', 'current_year_active');
|
||||
break;
|
||||
case "cy_complete":
|
||||
$editor->additionalListTable("judges_years");
|
||||
$editor->filterList("judges_years.judges_id=judges.id");
|
||||
$editor->filterList("judges_years.year={$config['FAIRYEAR']}");
|
||||
$editor->filterList("judges.complete='yes'");
|
||||
$editor->setOption('judges_show_what', 'current_year_complete');
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,16 @@ $judges_fields = array( 'firstname' => 'First Name',
|
||||
'expertise_other' => 'Other Expertise/Notes',
|
||||
'complete' => "Complete");
|
||||
|
||||
/* Setup the table editor with the fields we want to display
|
||||
* when displaying a list of judges, and also the type of each
|
||||
* field where required */
|
||||
$judges_table_fields = array( 'id' => 'ID',
|
||||
'firstname' => 'First Name',
|
||||
'lastname' => 'Last Name',
|
||||
'complete' => 'Complete',
|
||||
// 'year' => 'Year',
|
||||
);
|
||||
|
||||
|
||||
class person {
|
||||
var $id;
|
||||
@ -40,12 +50,12 @@ function person($person_id=NULL)
|
||||
};
|
||||
|
||||
|
||||
class judge extends person {
|
||||
class judge extends person /*implements TableEditorInterface*/ {
|
||||
|
||||
/* Static members for the table editor */
|
||||
function tableEditorSetup($editor)
|
||||
static function tableEditorSetup($editor)
|
||||
{
|
||||
global $judges_fields;
|
||||
global $judges_fields, $judges_table_fields;
|
||||
global $config;
|
||||
|
||||
$cat = array();
|
||||
@ -68,16 +78,6 @@ function tableEditorSetup($editor)
|
||||
|
||||
|
||||
|
||||
/* Setup the table editor with the fields we want to display
|
||||
* when displaying a list of judges, and also the type of each
|
||||
* field where required */
|
||||
$l = array( 'id' => 'ID',
|
||||
'firstname' => 'First Name',
|
||||
'lastname' => 'Last Name',
|
||||
'complete' => 'Complete',
|
||||
'year' => 'Year',
|
||||
);
|
||||
|
||||
/* Most of these should be moved to the base class, as they
|
||||
* will be the same for all person groups */
|
||||
$e = array_merge($judges_fields,
|
||||
@ -87,7 +87,7 @@ function tableEditorSetup($editor)
|
||||
|
||||
$editor->setTable('judges');
|
||||
$editor->setRecordType('Judge');
|
||||
$editor->setListFields($l);
|
||||
$editor->setListFields($judges_table_fields);
|
||||
$editor->setEditFields($e);
|
||||
|
||||
$editor->setFieldOptions('complete', array(
|
||||
@ -132,8 +132,44 @@ function tableEditorSetup($editor)
|
||||
$editor->setFieldOptions("divpref_$did", $expertisechoices);
|
||||
$editor->setFieldInputType("divpref_$did", 'select');
|
||||
}
|
||||
|
||||
$editor->createOption('judges_show_what');
|
||||
}
|
||||
|
||||
/* STATIC */
|
||||
static function tableEditorGetList($editor)
|
||||
{
|
||||
//return $editor->defaultGetList();
|
||||
global $config;
|
||||
global $judges_table_fields;
|
||||
|
||||
$show_what = $editor->getOption('judges_show_what');
|
||||
|
||||
$sel = array_keys($judges_table_fields);
|
||||
$from = array('judges');
|
||||
$where = array();
|
||||
|
||||
switch($show_what) {
|
||||
case "all":
|
||||
// $editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
||||
// $editor->filterList("(judges_years.year={$config['FAIRYEAR']} OR judges_years.year IS NULL)");
|
||||
break;
|
||||
case "current_year_active":
|
||||
$from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.year={$config['FAIRYEAR']}";
|
||||
break;
|
||||
case "current_year_complete":
|
||||
$from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.year={$config['FAIRYEAR']}";
|
||||
$where[] = "judges.complete='yes'";
|
||||
break;
|
||||
}
|
||||
return array($sel, $from, $where);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Functions for $this */
|
||||
|
||||
|
||||
@ -296,6 +332,7 @@ function tableEditorDelete()
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
|
@ -343,7 +343,6 @@ else
|
||||
|
||||
if($config['participant_student_tshirt']=="yes")
|
||||
{
|
||||
|
||||
$tshirt_cost = floatval($config['participant_student_tshirt_cost']);
|
||||
echo "<tr>\n";
|
||||
echo " <td>".i18n("T-Shirt Size")."</td><td colspan=3>";
|
||||
|
@ -27,6 +27,17 @@
|
||||
// - Fix INSERTING with a hidden field with value of NOW()
|
||||
|
||||
|
||||
interface TableEditorInterface {
|
||||
function tableEditorSetup($editor);
|
||||
function tableEditorLoad();
|
||||
function tableEditorSave($data);
|
||||
function tableEditorDelete();
|
||||
function tableEditorGetList($editor);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//ironforge
|
||||
//$icon_path="/phpscripts/icons/16";
|
||||
//lightbox
|
||||
@ -95,6 +106,7 @@ class TableEditor
|
||||
var $fieldFilterList=array();
|
||||
var $actionButtons=array();
|
||||
var $additionalListTables=array();
|
||||
var $options=array();
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
@ -316,6 +328,29 @@ class TableEditor
|
||||
$this->DEBUG=$d;
|
||||
}
|
||||
|
||||
function createOption($o)
|
||||
{
|
||||
$this->options[$o] = null;
|
||||
}
|
||||
|
||||
function setOption($o, $v)
|
||||
{
|
||||
if(array_key_exists($o, $this->options)) {
|
||||
$this->options[$o] = $v;
|
||||
return;
|
||||
}
|
||||
echo "Attempt to setOption($o, $v): option doesn't exist (create it with createOption)";
|
||||
exit;
|
||||
}
|
||||
function getOption($o)
|
||||
{
|
||||
if(array_key_exists($o, $this->options)) {
|
||||
return $this->options[$o];
|
||||
}
|
||||
echo "Attempt to getOption($o): option doesn't exist (create it with createOption)";
|
||||
exit;
|
||||
}
|
||||
|
||||
function getFieldType($f)
|
||||
{
|
||||
$inputtype = '';
|
||||
@ -875,33 +910,50 @@ class TableEditor
|
||||
|
||||
}
|
||||
|
||||
function defaultGetList()
|
||||
{
|
||||
$sel = array();
|
||||
$from = array();
|
||||
$where = array();
|
||||
|
||||
foreach($this->listfields AS $f=>$n)
|
||||
$sel[] = "`$f`";
|
||||
|
||||
$from[] = "`{$this->table}`";
|
||||
if(count($this->additionalListTables)) {
|
||||
foreach($this->additionalListTables as $t) {
|
||||
$from[] = "$t ";
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->fieldFilterList)) {
|
||||
foreach($this->fieldFilterList AS $k=>$v) {
|
||||
$where = ($v == false) ? $k : "`$k`='$v'";
|
||||
}
|
||||
}
|
||||
return array($sel, $from, $where);
|
||||
}
|
||||
|
||||
function displayTable()
|
||||
{
|
||||
global $icon_path;
|
||||
global $icon_extension;
|
||||
|
||||
$query="SELECT SQL_CALC_FOUND_ROWS {$this->primaryKey}";
|
||||
foreach($this->listfields AS $f=>$n)
|
||||
$query.=", `$f`";
|
||||
$query.=" FROM `{$this->table}`";
|
||||
|
||||
if(count($this->additionalListTables)) {
|
||||
foreach($this->additionalListTables as $t) {
|
||||
$query .= "$t ";
|
||||
}
|
||||
if(is_callable($this->classname, 'tableEditorGetList')) {
|
||||
list($sel, $from, $where) = call_user_func(array($this->classname, 'tableEditorGetList'), &$this);
|
||||
} else {
|
||||
echo "Calling default func\n";
|
||||
list($sel, $from, $where) = $this->defaultGetList();
|
||||
}
|
||||
|
||||
if(count($this->fieldFilterList))
|
||||
{
|
||||
$query.=" WHERE 1 ";
|
||||
foreach($this->fieldFilterList AS $k=>$v)
|
||||
{
|
||||
if($v == false)
|
||||
$query .= "AND $k ";
|
||||
else
|
||||
$query.=" AND `$k`='$v' ";
|
||||
}
|
||||
}
|
||||
foreach($sel as $s) $query .= ",$s";
|
||||
$query .= " FROM ";
|
||||
foreach($from as $f) $query .= "$f ";
|
||||
$query .= " WHERE 1 ";
|
||||
foreach($where as $w) $query .= "AND $w ";
|
||||
|
||||
if($this->sortField())
|
||||
$query.=" ORDER BY ".$this->sortField()."";
|
||||
|
||||
@ -921,6 +973,8 @@ class TableEditor
|
||||
echo "<a href=\"{$_SERVER['PHP_SELF']}?TableEditorAction=add\">".i18n("Add new %1",array($this->recordType))."</a><br /><br />";
|
||||
}
|
||||
if($this->DEBUG) echo $query;
|
||||
|
||||
// print("query[$query]");
|
||||
$q=mysql_query($query);
|
||||
|
||||
//put in some paganation stuff here.
|
||||
|
Loading…
x
Reference in New Issue
Block a user