]> git.andy128k.dev Git - ipf.git/commitdiff
admin templates
authoravl <alex.litovchenko@gmail.com>
Mon, 22 Dec 2008 04:52:48 +0000 (06:52 +0200)
committeravl <alex.litovchenko@gmail.com>
Mon, 22 Dec 2008 04:52:48 +0000 (06:52 +0200)
ipf/admin/model.php
ipf/admin/templates/admin/change.html
ipf/orm/record.php
ipf/orm/relation/association.php
ipf/orm/relation/parser.php

index 0b8f7bcf707cfa360b14cd3f0f478bc430f41fc2..4ac7e7313c870c383ce1bacee27c5d32bc37e117 100644 (file)
@@ -242,12 +242,13 @@ class IPF_Admin_Model{
         }
 
         $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'),
         );
@@ -275,6 +276,7 @@ class IPF_Admin_Model{
             $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();
@@ -289,6 +291,7 @@ class IPF_Admin_Model{
         }
 
         $context = array(
+               'mode'=>'change',
             'page_title'=>'Edit '.$this->modelName,
             'classname'=>$this->modelName,
             'object'=>$o,
index cc5e2989bd4279d11a89642af43d076ef476076f..18564763a603940fcbbd143732209060ea4aea43 100644 (file)
@@ -49,8 +49,9 @@
             {/foreach}
                {/if}
                    <div class="submit-row">
-                       {if array_search('delete',$perms)!==false}<p class="float-left"><a href="{url 'IPF_Admin_Views_DeleteItem', array($lapp, $lmodel, $object.id)}" class="deletelink">Delete</a></p>{/if}
-                       <input type="submit" value="Save" class="default" />
+                       {if ($mode=='change') && (array_search('delete',$perms)!==false)}<p class="float-left"><a href="{url 'IPF_Admin_Views_DeleteItem', array($lapp, $lmodel, $object.pk())}" class="deletelink">Delete</a></p>{/if}
+                       {if ($mode=='change') && (array_search('change',$perms)!==false)}<input type="submit" value="Save" class="default" />{/if}
+                {if ($mode=='add') && (array_search('add',$perms)!==false)}<input type="submit" value="Add" class="default" />{/if}
                 <input type="button" value="Cancel" onclick="javascript:history.back();" />
                    </div>
                </div>
index 0b7d506e5a8d3520ab067127aaad76df166ffdbc..a8baf48ba8ad7f829372268e997d065f95d6b507 100644 (file)
@@ -1013,7 +1013,7 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
     public function pk($sep='_')
     {
        $pk = '';
-       while (list($key, $val) = each($this->_id)) {
+       foreach($this->_id as $val) {
                if ($pk!='')
                        $pk .= $sep;
                $pk .= $val;
index 4a1958dd8156916408e6a5304fdcb5b486456455..93dfffc495ace5211f909fb12d91ceb9cc5f6f70 100644 (file)
@@ -15,7 +15,7 @@ class IPF_ORM_Relation_Association extends IPF_ORM_Relation
     {
         $table = $this->definition['refTable'];
         $component = $this->definition['refTable']->getComponentName();
-        
+
         switch ($context) {
             case "record":
                 $sub  = substr(str_repeat("?, ", $count),0,-2);
@@ -30,13 +30,12 @@ class IPF_ORM_Relation_Association extends IPF_ORM_Relation
                 $dql .= ' WHERE ' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
                 break;
         }
-
         return $dql;
     }
 
     public function fetchRelatedFor(IPF_ORM_Record $record)
     {
-        $id = $record->getIncremented();
+        $id = $record->pk();
         if (empty($id) || ! $this->definition['table']->getAttribute(IPF_ORM::ATTR_LOAD_REFERENCES)) {
             $coll = new IPF_ORM_Collection($this->getTable());
         } else {
index e15228eec7303f84bcb726bd5959fbd88fe852c6..fde505b5da218f7c1717e28d6d7d8fc239cec2cd 100644 (file)
@@ -1,12 +1,12 @@
 <?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;
     }
@@ -16,21 +16,21 @@ class IPF_ORM_Relation_Parser
         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]);
     }
@@ -40,7 +40,7 @@ class IPF_ORM_Relation_Parser
         if ( ! isset($this->_pending[$name]) && ! isset($this->_relations[$name])) {
             return false;
         }
-        
+
         return true;
     }
 
@@ -60,7 +60,7 @@ class IPF_ORM_Relation_Parser
         }
 
         $this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
-        
+
         return $this->_pending[$alias];
     }
 
@@ -74,14 +74,14 @@ class IPF_ORM_Relation_Parser
             $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();
@@ -133,7 +133,6 @@ class IPF_ORM_Relation_Parser
         }
         if ($recursive) {
             $this->getRelations();
-
             return $this->getRelation($alias, false);
         } else {
             throw new IPF_ORM_Exception('Unknown relation alias ' . $alias);
@@ -155,7 +154,7 @@ class IPF_ORM_Relation_Parser
 
         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);
             }
@@ -166,7 +165,7 @@ class IPF_ORM_Relation_Parser
         return $conn->getTable($impl);
     }
 
-    public function completeAssocDefinition($def) 
+    public function completeAssocDefinition($def)
     {
         $conn = $this->_table->getConnection();
         $def['table'] = $this->getImpl($def['class']);
@@ -180,7 +179,7 @@ class IPF_ORM_Relation_Parser
             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'])) {
@@ -194,16 +193,16 @@ class IPF_ORM_Relation_Parser
             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;
             }
         }
@@ -214,7 +213,7 @@ class IPF_ORM_Relation_Parser
     {
         $componentNameToLower = strtolower($table->getComponentName());
         if (is_array($table->getIdentifier())) {
-            $columns = array();      
+            $columns = array();
             foreach ((array) $table->getIdentifierColumnNames() as $identColName) {
                 $columns[] = $componentNameToLower . '_' . $identColName;
             }
@@ -249,7 +248,7 @@ class IPF_ORM_Relation_Parser
                 break;
             }
         }
-        
+
         if ( ! $found) {
             throw new IPF_ORM_Exception("Couldn't find columns.");
         }
@@ -344,7 +343,7 @@ class IPF_ORM_Relation_Parser
                     $idColumnName = array_pop($identifierColumnNames);
                     $column = strtolower($table->getComponentName())
                             . '_' . $idColumnName;
-                
+
                     foreach ($localClasses as $class2) {
                         $table2 = $conn->getTable($class2);
                         if ($table2->hasColumn($column)) {
@@ -374,7 +373,7 @@ class IPF_ORM_Relation_Parser
                     unset($col['primary']);
 
                     $def['table']->setColumn($column, $type, $length, $col);
-                    
+
                     $columns[] = $column;
                 }
                 if (count($columns) > 1) {