}
$context = array(
+ 'mode'=>'add',
'page_title'=>'Add '.$this->modelName,
'classname'=>$this->modelName,
'form'=>$form,
'inlineInstances'=>$this->inlineInstances,
'lapp'=>$lapp,
- 'perms'=>array(),
+ 'perms'=>$this->getPerms($request),
'lmodel'=>$lmodel,
'admin_title' => IPF::get('admin_title'),
);
$data = $o->getData();
foreach($o->getTable()->getRelations() as $rname=>$rel){
$pk = $rel->getTable()->getIdentifier();
+ //print $pk;
if (array_search($rname,$this->fields())){
if ($rel->getType()==IPF_ORM_Relation::MANY_AGGREGATE){
$data[$rname] = array();
}
$context = array(
+ 'mode'=>'change',
'page_title'=>'Edit '.$this->modelName,
'classname'=>$this->modelName,
'object'=>$o,
<?php
-class IPF_ORM_Relation_Parser
+class IPF_ORM_Relation_Parser
{
protected $_table;
protected $_relations = array();
protected $_pending = array();
- public function __construct(IPF_ORM_Table $table)
+ public function __construct(IPF_ORM_Table $table)
{
$this->_table = $table;
}
return $this->_table;
}
- public function getPendingRelation($name)
+ public function getPendingRelation($name)
{
if ( ! isset($this->_pending[$name])) {
throw new IPF_ORM_Exception('Unknown pending relation ' . $name);
}
-
+
return $this->_pending[$name];
}
- public function getPendingRelations()
+ public function getPendingRelations()
{
return $this->_pending;
}
- public function unsetPendingRelations($name)
+ public function unsetPendingRelations($name)
{
unset($this->_pending[$name]);
}
if ( ! isset($this->_pending[$name]) && ! isset($this->_relations[$name])) {
return false;
}
-
+
return true;
}
}
$this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
-
+
return $this->_pending[$alias];
}
$def = $this->_pending[$alias];
$identifierColumnNames = $this->_table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames);
-
+
// check if reference class name exists
// if it does we are dealing with association relation
if (isset($def['refClass'])) {
$def = $this->completeAssocDefinition($def);
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
- if ( ! isset($this->_pending[$def['refClass']]) &&
+ if ( ! isset($this->_pending[$def['refClass']]) &&
! isset($this->_relations[$def['refClass']])) {
$parser = $def['refTable']->getRelationParser();
}
if ($recursive) {
$this->getRelations();
-
return $this->getRelation($alias, false);
} else {
throw new IPF_ORM_Exception('Unknown relation alias ' . $alias);
if (in_array('IPF_ORM_Template', class_parents($template))) {
$impl = $this->_table->getImpl($template);
-
+
if ($impl === null) {
throw new IPF_ORM_Exception("Couldn't find concrete implementation for template " . $template);
}
return $conn->getTable($impl);
}
- public function completeAssocDefinition($def)
+ public function completeAssocDefinition($def)
{
$conn = $this->_table->getConnection();
$def['table'] = $this->getImpl($def['class']);
if ( ! isset($def['foreign'])) {
// foreign key not set
// try to guess the foreign key
-
+
$def['foreign'] = ($def['local'] === $id[0]) ? $id[1] : $id[0];
}
if ( ! isset($def['local'])) {
if ( ! isset($def['foreign'])) {
// foreign key not set
// try to guess the foreign key
-
+
$columns = $this->getIdentifiers($def['table']);
-
+
$def['foreign'] = $columns;
}
if ( ! isset($def['local'])) {
// local key not set
// try to guess the local key
$columns = $this->getIdentifiers($this->_table);
-
+
$def['local'] = $columns;
}
}
{
$componentNameToLower = strtolower($table->getComponentName());
if (is_array($table->getIdentifier())) {
- $columns = array();
+ $columns = array();
foreach ((array) $table->getIdentifierColumnNames() as $identColName) {
$columns[] = $componentNameToLower . '_' . $identColName;
}
break;
}
}
-
+
if ( ! $found) {
throw new IPF_ORM_Exception("Couldn't find columns.");
}
$idColumnName = array_pop($identifierColumnNames);
$column = strtolower($table->getComponentName())
. '_' . $idColumnName;
-
+
foreach ($localClasses as $class2) {
$table2 = $conn->getTable($class2);
if ($table2->hasColumn($column)) {
unset($col['primary']);
$def['table']->setColumn($column, $type, $length, $col);
-
+
$columns[] = $column;
}
if (count($columns) > 1) {