public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self(); } return self::$_instance; }
public function getTableName() { $tableName = storageRegistry::getInstance()->modelSettings[$this->_modelName]['table']; return is_string($tableName) ? $tableName : false; }
public function getRegistry() { return storageRegistry::getInstance(); }
public static function getIndirectTablesJoins($sourceTable, $targetTable, $joinTypes, $joinWhere) { $keys =& storageRegistry::getInstance()->foreignKeys; $sourceClass = self::getTableModel($sourceTable); $targetClass = self::getTableModel($targetTable); $joins = array(); $joinedTables = array(); //echo 'Connecting from '.$sourceClass.' to '.$targetClass.'<br />'; foreach ($keys[$sourceClass] as $foreignClass => $options) { if ($foreignClass == $targetClass) { if (!is_array($options)) { $viaClass = $options; //echo 'Connecting via '.$viaClass.'<br />'; $viaTable = modelCollection::getInstance($viaClass); $subJoins = self::getIndirectTablesJoins($sourceTable, $viaTable, $joinTypes, $joinWhere); if ($subJoins !== false) { foreach ($subJoins as $uid => $joinString) { $joins[$uid] = $joinString; } } $subJoins = self::getIndirectTablesJoins($viaTable, $targetTable, $joinTypes, $joinWhere); if ($subJoins !== false) { foreach ($subJoins as $uid => $joinString) { $joins[$uid] = $joinString; } } return $joins; } else { // FIXED JOIN TYPE & ON() SELECTION $joinType = isset($joinTypes[$targetTable->getUniqueId()]) ? $joinTypes[$targetTable->getUniqueId()] : 'INNER'; $joinOn = $sourceTable->getJoinOn($targetTable); if ($joinOn === null) { $joinOn = $targetTable->getJoinOn($sourceTable); if ($joinOn === null) { $joinOn = ''; } } list($sourcePropertyName, $targetPropertyName) = $options; $joinString = " " . $joinType . " JOIN {$targetTable->getTableName()} AS {$targetTable} ON ({$sourceTable->{$sourcePropertyName}} = {$targetTable->{$targetPropertyName}}"; if (isset($joinWhere[$targetTable->getUniqueId()])) { // apply filters $joinString .= " AND " . implode(" AND ", $joinWhere[$targetTable->getUniqueId()]); } if (strlen($joinOn)) { $joinString .= " AND " . $joinOn; } $joinString .= ")"; //$joins[$sourceTable->getUniqueId()] = true; $joins[$targetTable->getUniqueId()] = $joinString; //echo 'Connecting via DIRECT<br />'; if ($joinString !== false) { return $joins; } //array($joinedTables, $joinString); } } } //var_dump($keys[$sourceClass]); //throw new Exception('Connecting via FALSE'); return false; }
/** * @return string */ public function getTableName() { return storageRegistry::getInstance()->modelSettings[get_class($this)]['table']; }