Skip to content

Commit

Permalink
ActiveTable updates for KKK
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Sep 4, 2007
1 parent 300ca89 commit 280c22e
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions active_table/active_table.class.php
Expand Up @@ -549,7 +549,7 @@ public function __call($method,$parameters)
$total = round((microtime(true) - $start),4);
$this->debug("#__call($method) executed in '$total' seconds.",'method_time');

return $this->grab($set_name);
return $this->grab($set_name,$parameters[0],$parameters[1],$parameters[2]);
} // end load record sets
elseif(preg_match('/^findOneBy([A-Z][A-Za-z0-9_]*)$/',$method,$FOUND) == true)
{
Expand Down Expand Up @@ -587,19 +587,27 @@ public function __call($method,$parameters)
/**
* Grab RELATED record set.
*
* @param string
* @param string $record_set A record set name.
* @param string $order_by A raw ORDER BY clause.
* @param string $limit A raw LIMIT clause.
* @param bool $reset Throw away any cached results from previous grabs.
* @return array
**/
public function grab($record_set)
public function grab($record_set,$order_by=null,$limit=null,$reset=false)
{
$start = microtime(true);

if(array_key_exists($record_set,$this->RELATED) == false)
{
throw new ArgumentError('No such recordset is defined.');
} // end recordset does not exist

// The array in RELATED_OBJECTS is not created for the set until loaded.
// This keeps a difference between non-loaded and loaded-but-zero-rows-returned.
if(array_key_exists($record_set,$this->RELATED_OBJECTS) == false)
if(array_key_exists($record_set,$this->RELATED_OBJECTS) == false || $reset == true)
{
$this->RELATED_IDS[$record_set] = $this->load_recordset_id_list($this->RELATED[$record_set]);
$this->load_recordset($record_set);
$this->RELATED_IDS[$record_set] = $this->load_recordset_id_list($this->RELATED[$record_set],"$order_by $limit");
$this->load_recordset($record_set,$order_by);
} // end record set not loaded

$total = round((microtime(true) - $start),4);
Expand Down Expand Up @@ -1401,7 +1409,7 @@ private function newSqlGenerator()
/**
* Grab a list of fields in the table.
*
* @var The table name. This defaults to the current table.
* @param string The table name. This defaults to the current table.
* @internal
*/
private function load_fields($table=null,$database=null)
Expand Down Expand Up @@ -1452,7 +1460,14 @@ private function load_fields($table=null,$database=null)
return $RESULT;
} // end load_fields

private function load_recordset_id_list($RELATED)
/**
* load_recordset_id_list
*
* @param array $RELATED Record set specification.
* @param string $order_by A raw ORDER BY clause.
* @return void
**/
private function load_recordset_id_list($RELATED,$order_by=null)
{
/*
* 'record_set' => array( // Verbose example.
Expand All @@ -1475,6 +1490,12 @@ private function load_recordset_id_list($RELATED)
$sql_generator->addFrom($RELATED['foreign_table'],$RELATED['foreign_database']);
$sql_generator->addJoinClause($RELATED['foreign_table'],$RELATED['foreign_key'],$RELATED['local_table'],$RELATED['local_table'],$RELATED['local_key'],'inner',$RELATED['foreign_database']);
$sql_generator->addWhere($RELATED['local_table'],$RELATED['local_key']);

if($order_by != null)
{
$sql_generator->addOrder($order_by);
}

$sql = $sql_generator->getQuery('select');

$resource = $this->db->query($sql,array($this->get($RELATED['local_key'],$RELATED['local_table'])));
Expand Down Expand Up @@ -1502,7 +1523,7 @@ private function load_recordset_id_list($RELATED)
* is not actually defined.
* @return void
**/
private function load_recordset($record_set_name)
private function load_recordset($record_set_name,$order_by=null)
{
if(array_key_exists($record_set_name,$this->RELATED) == false)
{
Expand Down Expand Up @@ -1533,15 +1554,15 @@ private function load_recordset($record_set_name)
{
$method = 'findOneBy';
}

eval('$tmp = new '.$SET['class'].'($this->db);');
$this->RELATED_OBJECTS[$record_set_name] = $tmp->$method(array(
array(
'table' => $tmp->tableName(),
'column' => $tmp->primaryKey(),
'value' => $IDS,
),
));
),$order_by);
}

return true;
Expand Down

0 comments on commit 280c22e

Please sign in to comment.