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'])) {
|
if(isset($_POST['show_what'])) {
|
||||||
$show_what = $_POST['show_what'];
|
$show_what = $_POST['show_what'];
|
||||||
} else {
|
} else {
|
||||||
$show_what = "all";
|
$show_what = "cy_complete";
|
||||||
}
|
}
|
||||||
print("<form name=\"ShowJudges\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">");
|
print("<form name=\"ShowJudges\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">");
|
||||||
print("<select id=\"show_what\" name=\"show_what\">");
|
print("<select id=\"show_what\" name=\"show_what\">");
|
||||||
@ -77,18 +77,13 @@ function openjudgeinfo(id)
|
|||||||
|
|
||||||
switch($show_what) {
|
switch($show_what) {
|
||||||
case "all":
|
case "all":
|
||||||
$editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
$editor->setOption('judges_show_what', 'all');
|
||||||
$editor->filterList("(judges_years.year={$config['FAIRYEAR']} OR judges_years.year IS NULL)");
|
|
||||||
break;
|
break;
|
||||||
case "cy_active":
|
case "cy_active":
|
||||||
$editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
$editor->setOption('judges_show_what', 'current_year_active');
|
||||||
$editor->filterList("(judges_years.year={$config['FAIRYEAR']})");
|
|
||||||
break;
|
break;
|
||||||
case "cy_complete":
|
case "cy_complete":
|
||||||
$editor->additionalListTable("judges_years");
|
$editor->setOption('judges_show_what', 'current_year_complete');
|
||||||
$editor->filterList("judges_years.judges_id=judges.id");
|
|
||||||
$editor->filterList("judges_years.year={$config['FAIRYEAR']}");
|
|
||||||
$editor->filterList("judges.complete='yes'");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,16 @@ $judges_fields = array( 'firstname' => 'First Name',
|
|||||||
'expertise_other' => 'Other Expertise/Notes',
|
'expertise_other' => 'Other Expertise/Notes',
|
||||||
'complete' => "Complete");
|
'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 {
|
class person {
|
||||||
var $id;
|
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 */
|
/* Static members for the table editor */
|
||||||
function tableEditorSetup($editor)
|
static function tableEditorSetup($editor)
|
||||||
{
|
{
|
||||||
global $judges_fields;
|
global $judges_fields, $judges_table_fields;
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$cat = array();
|
$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
|
/* Most of these should be moved to the base class, as they
|
||||||
* will be the same for all person groups */
|
* will be the same for all person groups */
|
||||||
$e = array_merge($judges_fields,
|
$e = array_merge($judges_fields,
|
||||||
@ -87,7 +87,7 @@ function tableEditorSetup($editor)
|
|||||||
|
|
||||||
$editor->setTable('judges');
|
$editor->setTable('judges');
|
||||||
$editor->setRecordType('Judge');
|
$editor->setRecordType('Judge');
|
||||||
$editor->setListFields($l);
|
$editor->setListFields($judges_table_fields);
|
||||||
$editor->setEditFields($e);
|
$editor->setEditFields($e);
|
||||||
|
|
||||||
$editor->setFieldOptions('complete', array(
|
$editor->setFieldOptions('complete', array(
|
||||||
@ -132,8 +132,44 @@ function tableEditorSetup($editor)
|
|||||||
$editor->setFieldOptions("divpref_$did", $expertisechoices);
|
$editor->setFieldOptions("divpref_$did", $expertisechoices);
|
||||||
$editor->setFieldInputType("divpref_$did", 'select');
|
$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 */
|
/* Functions for $this */
|
||||||
|
|
||||||
|
|
||||||
@ -296,6 +332,7 @@ function tableEditorDelete()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -343,7 +343,6 @@ else
|
|||||||
|
|
||||||
if($config['participant_student_tshirt']=="yes")
|
if($config['participant_student_tshirt']=="yes")
|
||||||
{
|
{
|
||||||
|
|
||||||
$tshirt_cost = floatval($config['participant_student_tshirt_cost']);
|
$tshirt_cost = floatval($config['participant_student_tshirt_cost']);
|
||||||
echo "<tr>\n";
|
echo "<tr>\n";
|
||||||
echo " <td>".i18n("T-Shirt Size")."</td><td colspan=3>";
|
echo " <td>".i18n("T-Shirt Size")."</td><td colspan=3>";
|
||||||
|
@ -27,6 +27,17 @@
|
|||||||
// - Fix INSERTING with a hidden field with value of NOW()
|
// - 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
|
//ironforge
|
||||||
//$icon_path="/phpscripts/icons/16";
|
//$icon_path="/phpscripts/icons/16";
|
||||||
//lightbox
|
//lightbox
|
||||||
@ -95,6 +106,7 @@ class TableEditor
|
|||||||
var $fieldFilterList=array();
|
var $fieldFilterList=array();
|
||||||
var $actionButtons=array();
|
var $actionButtons=array();
|
||||||
var $additionalListTables=array();
|
var $additionalListTables=array();
|
||||||
|
var $options=array();
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
@ -316,6 +328,29 @@ class TableEditor
|
|||||||
$this->DEBUG=$d;
|
$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)
|
function getFieldType($f)
|
||||||
{
|
{
|
||||||
$inputtype = '';
|
$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()
|
function displayTable()
|
||||||
{
|
{
|
||||||
global $icon_path;
|
global $icon_path;
|
||||||
global $icon_extension;
|
global $icon_extension;
|
||||||
|
|
||||||
$query="SELECT SQL_CALC_FOUND_ROWS {$this->primaryKey}";
|
$query="SELECT SQL_CALC_FOUND_ROWS {$this->primaryKey}";
|
||||||
foreach($this->listfields AS $f=>$n)
|
|
||||||
$query.=", `$f`";
|
|
||||||
$query.=" FROM `{$this->table}`";
|
|
||||||
|
|
||||||
if(count($this->additionalListTables)) {
|
if(is_callable($this->classname, 'tableEditorGetList')) {
|
||||||
foreach($this->additionalListTables as $t) {
|
list($sel, $from, $where) = call_user_func(array($this->classname, 'tableEditorGetList'), &$this);
|
||||||
$query .= "$t ";
|
} else {
|
||||||
}
|
echo "Calling default func\n";
|
||||||
|
list($sel, $from, $where) = $this->defaultGetList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($this->fieldFilterList))
|
foreach($sel as $s) $query .= ",$s";
|
||||||
{
|
$query .= " FROM ";
|
||||||
$query.=" WHERE 1 ";
|
foreach($from as $f) $query .= "$f ";
|
||||||
foreach($this->fieldFilterList AS $k=>$v)
|
$query .= " WHERE 1 ";
|
||||||
{
|
foreach($where as $w) $query .= "AND $w ";
|
||||||
if($v == false)
|
|
||||||
$query .= "AND $k ";
|
|
||||||
else
|
|
||||||
$query.=" AND `$k`='$v' ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($this->sortField())
|
if($this->sortField())
|
||||||
$query.=" ORDER BY ".$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 />";
|
echo "<a href=\"{$_SERVER['PHP_SELF']}?TableEditorAction=add\">".i18n("Add new %1",array($this->recordType))."</a><br /><br />";
|
||||||
}
|
}
|
||||||
if($this->DEBUG) echo $query;
|
if($this->DEBUG) echo $query;
|
||||||
|
|
||||||
|
// print("query[$query]");
|
||||||
$q=mysql_query($query);
|
$q=mysql_query($query);
|
||||||
|
|
||||||
//put in some paganation stuff here.
|
//put in some paganation stuff here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user