[Solar-svn] Revision 3048

pmjones at solarphp.com pmjones at solarphp.com
Wed Mar 26 07:38:10 CDT 2008


Solar_Sql_Model_Record and Solar_Form_Load_Model

Solar_Form_Load_Model
---------------------

* [ADD] Added "don't load special columns" logic into method fetch(), taken
  from Solar_Sql_Model_Record::form()

Solar_Sql_Model_Record
----------------------

* [DEL] Removed "don't load special columns" logic from method form(), put
  into Solar_Form_Load_Model::fetch().

* [ADD] Method form() now adds form-level feedback for invalid columns that
  don't have form elements.  This will help diagnose save failures caused by
  (e.g.) invalid ID columns.




Modified: trunk/Solar/Form/Load/Model.php
===================================================================
--- trunk/Solar/Form/Load/Model.php	2008-03-25 14:04:45 UTC (rev 3047)
+++ trunk/Solar/Form/Load/Model.php	2008-03-26 12:38:10 UTC (rev 3048)
@@ -48,6 +48,29 @@
         // special condition: if looking for '*' columns,
         // set the list to all the model columns.
         if ($list == '*') {
+            if ($model->fetch_cols) {
+                // use the fetch columns
+                $list = $model->fetch_cols;
+            } else {
+                // use all columns
+                $list = array_keys($model->table_cols);
+            }
+            
+            // flip around so we can unset easier
+            $list = array_flip($list);
+            
+            // remove special columns
+            unset($list[$model->primary_col]);
+            unset($list[$model->created_col]);
+            unset($list[$model->updated_col]);
+            unset($list[$model->inherit_col]);
+            
+            // remove sequence columns
+            foreach ($model->sequence_cols as $key => $val) {
+                unset($list[$key]);
+            }
+            
+            // done!
             $list = array_keys($cols);
         } else {
             settype($list, 'array');

Modified: trunk/Solar/Sql/Model/Record.php
===================================================================
--- trunk/Solar/Sql/Model/Record.php	2008-03-25 14:04:45 UTC (rev 3047)
+++ trunk/Solar/Sql/Model/Record.php	2008-03-26 12:38:10 UTC (rev 3048)
@@ -1112,31 +1112,9 @@
      */
     public function form($cols = null)
     {
+        // use all columns?
         if (empty($cols)) {
-            if ($this->_model->fetch_cols) {
-                // use the fetch columns
-                $cols = $this->_model->fetch_cols;
-            } else {
-                // use all columns
-                $cols = array_keys($this->_model->table_cols);
-            }
-            
-            // flip around so we can unset easier
-            $cols = array_flip($cols);
-            
-            // remove special columns
-            unset($cols[$this->_model->primary_col]);
-            unset($cols[$this->_model->created_col]);
-            unset($cols[$this->_model->updated_col]);
-            unset($cols[$this->_model->inherit_col]);
-            
-            // remove sequence columns
-            foreach ($this->_model->sequence_cols as $key => $val) {
-                unset($cols[$key]);
-            }
-            
-            // done!
-            $cols = array_keys($cols);
+            $cols = '*';
         }
         
         // put into this array in the form
@@ -1159,8 +1137,21 @@
             break;
         }
         
-        // @todo: add invalidation messages to the form itself, where
-        // elements are missing.
+        // if a column is invalid, and an element for it does not exist in the
+        // form, add the invalidation message as feedback on the form as a 
+        // whole.  this helps you track down errors on columns that prevented
+        // a save but were not part of the form, like IDs.
+        foreach ($this->_invalid as $key => $val) {
+            // the element name in the form
+            $elem_name = $array_name . "[$key]";
+            // is the column invalid, but not in the form?
+            if ($this->_invalid[$key] && empty($form->elements[$elem_name])) {
+                // add the invalidation messages as feedback
+                foreach ((array) $this->_invalid[$key] as $text) {
+                    $form->feedback[] = "$key: $text";
+                }
+            }
+        }
         
         return $form;
     }




More information about the Solar-svn mailing list