Source for file joinmatrix.php
Documentation is available at joinmatrix.php
* Similar to JoinData, but presents the options in a matrix not a list
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'field.php';
/** uses ID field objects */
require_once 'idfield.php';
/** database row manipulation object */
require_once 'dbrow.php';
/** connect to database */
require_once 'inc/db.php';
* Similar to JoinData, but presents the options in a matrix not a list
* The entries in one table can be a matrix with the coordinates from two others
* We respect the 'field' interface while overriding pretty much all of it.
* // jointable has structure: key1 key2 field1 field2 field3...
* // where key1 is the id key of table1 and key2 is the id key for table2.
* // we will display field* in rows for each key2 for a given key1
* $f = new JoinMatrix('jointable', 'jtid'
'key2', 'id2', 'table2', $name, $longname, $description);
* $key1 = new TextField('key1', 'label1');
* $key1->setFormat('id', '%s (%s)', array('name', 'longname'));
* $key2 = new TextField('key2', 'label2');
* $f->addKeys($key1, $key2);
* $f1 = new TextField('field1', 'label');
* $f2 = new TextField('field2', 'label');
* @subpackage FormsLibrary
/** @var string name of the join table (table has columns of form (LeftID, RightID) to join Left and Right tables */
/** @var string column in the join table that is the ID field for entries (unused) */
/** @var string value of the key for the left table that should be constant */
/** @var string column name in the join table for the column with keys/Ids from the left table (id will be constant throughout the process) */
/** @var string name of the left table */
/** @var string column name of ID column in the left table */
/** @var Field representation of the key for the left table (unused?) */
/** @var array list of Field objects to be included along the header of the matrix */
/** @var string column name in the join table for the column with keys/Ids from the right table (id will vary throughout the process) */
/** @var string name of the right table */
/** @var string column name of ID column in the right table */
/** @var Field representation of the key for the right table */
/** @var DBRow prototype DBRow object that is replicated for each entry in the join table (1:many join) */
/** @var array list of DBRow objects for each row returned in a 1:many join */
/** @var integer number of rows in the join */
/** @var string number of columns that this field should span in the table */
/** @var array list of id-pairs in the join table */
/** @var integer number of fields that are also in the join table */
/** @var boolean SQL errors should be fatal (die()) */
* Create a new joinmatrix object
* @param string $jointable see $this->joinTable
* @param string $jtIdField (presently unused)
* @param string $jtConstKeyCol see $this->jtConstKeyCol
* @param string $table1IdCol see $this->table1IdCol
* @param string $table1 see $this->table1
* @param string $jtVarKeyCol see $this->jtVarKeyCol
* @param string $table2IdCol see $this->table2IdCol
* @param string $table2 see $this->table2
* @param string $name the name of the field (db name, and html field name
* @param string $longname used in the html label
* @param string $description used in the html title or longdesc for the field
$jtConstKeyCol, $table1IdCol, $table1,
$jtVarKeyCol, $table2IdCol, $table2,
$name, $longname, $description=
'') {
parent::Field($name, $longname, $description);
$this->header2 =
array();
* Add key Fields for the id columns in the left and right tables
* @param Field $key1 key field for left table (unused?)
* @param Field $key2 key field for right table
//$this->key1->namebase = $this->table1;
//$this->key2->namebase = $this->table2;
* set the id that this object will match in the left table
* @param integer $id id from the left table to match
* populates the matrix from the database
* @global string prefix to table names
* add a field to the join table
* Field will appear in each row returned from the join table
* @param Field $field the field to be added
* @param string $groupValidTest data validation routine for this field
* Create a new row from the protorow for storing data
* @param integer $rowNum number of this row (used as unique identifier in the namebase)
$this->rows[$rowNum]->setNamebase($this->name.
'-'.
$rowNum.
'-');
* Fill from the database one row at a time
for ($i=
0; $i <
$this->number; $i++
) {
$this->rows[$i]->ignoreId =
true;
$this->rows[$i]->recStart =
$i;
$this->rows[$i]->restriction =
// $this->rows[$i]->insertRow = ! ($this->rows[$i]->fields[$this->table2IdCol]->value > 0);
$t =
'<table><tr><td></td>'.
$eol;
for ($field=
0; $field <
$this->numFields; $field++
) {
$t .=
'<td title="'.
$this->header1[$field]->description.
'">'
.
$this->header1[$field]->longname.
'</td>'.
$eol;
for ($row=
0; $row<
$this->number; $row++
) {
for ($field=
0; $field <
$this->numFields; $field++
) {
$f =
& $this->rows[$row]->fields[$this->header1[$field]->name];
$ft =
$f->selectedValue();
$t .=
'<td title="'.
$f->description.
'">'.
$ft.
'</td>'.
$eol;
//check how many fields we need to have (again) as we might have to show more this time around.
//$cols += $this->colspan;
.
'<tr><td colspan="'.
$this->colspan.
'">'.
$eol;
for ($i=
0; $i<
$cols-
2; $i++
) {
for ($i=
0; $i <
$this->number; $i++
) {
$rowchanged =
$this->rows[$i]->update($data);
$this->log('JoinData-Row '.
$i.
' has changed.');
#$this->rows[$i]->fields[$this->jtRightIDCol]->changed = $rowchanged;
#if ($v->name != $this->jtRightIDCol && $v->name != $this->jtLeftIDCol) {
$this->rows[$i]->fields[$k]->changed =
$rowchanged;
$this->log('Overall JoinData row changed='.
$this->changed);
* trip the complex field within us to sync(), which allows us
* to then know our actual value (at last).
#echo "JoinData::sqlSetStr";
//We return an empty string as this is only a join table entry,
//so it has no representation within the row itself.
* synchronise the join table
for ($i=
0; $i <
$this->number; $i++
) {
#echo "before sync row $i oob='".$this->oob_status."' ";
$this->log('JoinData::_joinSync(): Syncing row '.
$i);
#echo " after sync row $i oob='".$this->oob_status."'";
* override the isValid method of the Field class, using the
* checkValid method of each member row completed as well as
* cross checks on other fields.
* @return boolean data is valid
for ($i=
0; $i <
$this->number; $i++
) {
* Change the Id value of each row
for ($i=
0; $i <
$this->number; $i++
) {
$this->rows[$i]->setId($newId);
* Set the name base of the rows
for ($i=
0; $i <
$this->number; $i++
) {
$this->rows[$i]->setNamebase($namebase);
$this->protoRow->setNamebase($namebase);
* set whether each row is editable
for ($i=
0; $i <
$this->number; $i++
) {
$this->rows[$i]->setEditable($editable);
$this->protoRow->setEditable($editable);
Documentation generated on Tue, 06 Mar 2007 10:01:43 +0000 by phpDocumentor 1.3.0