[Solar-svn] Revision 2851
pmjones at solarphp.com
pmjones at solarphp.com
Wed Oct 10 12:04:45 CDT 2007
updated comments
Modified: trunk/Solar/Sql/Model/Collection.php
===================================================================
--- trunk/Solar/Sql/Model/Collection.php 2007-10-10 16:38:57 UTC (rev 2850)
+++ trunk/Solar/Sql/Model/Collection.php 2007-10-10 17:04:45 UTC (rev 2851)
@@ -42,11 +42,51 @@
*
* Data for related objects.
*
+ * @var array
+ *
*/
protected $_related = array();
/**
*
+ * Returns a record from the collection based on its key value. Converts
+ * the stored data array to a record of the correct class on-the-fly.
+ *
+ * @param int|string $key The sequential or associative key value for the
+ * record.
+ *
+ */
+ public function __get($key)
+ {
+ // convert array to record object
+ // honors single-table inheritance
+ if (is_array($this->_data[$key])) {
+
+ // convert the data array to an object.
+ // get the main data to load to the record.
+ $load = $this->_data[$key];
+
+ // add related data to load data
+ $primary = $load[$this->_model->primary_col];
+ foreach ($this->_related as $name => $data) {
+ if (! empty($data[$primary])) {
+ // add the data
+ $load[$name] = $data[$primary];
+ // save some memory
+ unset($data[$primary]);
+ }
+ }
+
+ // done
+ $this->_data[$key] = $this->_model->newRecord($load);
+ }
+
+ // return the record
+ return $this->_data[$key];
+ }
+
+ /**
+ *
* Injects the model from which the data originates.
*
* Also loads accessor method lists for column and related properties.
@@ -87,7 +127,7 @@
*
* @param string $name The relationship name.
*
- * @param $data The related data.
+ * @param array $data The related data.
*
* @return void
*
@@ -108,6 +148,13 @@
}
}
+ /**
+ *
+ * Returns the data for each record in this collection as an array.
+ *
+ * @return array
+ *
+ */
public function toArray()
{
$data = array();
@@ -120,8 +167,8 @@
/**
*
- * Saves all the records from this collection to the database, inserting
- * or updating as needed.
+ * Saves all the records from this collection to the database one-by-one,
+ * inserting or updating as needed.
*
* @return void
*
@@ -143,15 +190,35 @@
$this->_postSave();
}
+ /**
+ *
+ * User-defined pre-save logic for the collection.
+ *
+ * @return void
+ *
+ */
public function _preSave()
{
}
+ /**
+ *
+ * User-defined post-save logic for the collection.
+ *
+ * @return void
+ *
+ */
public function _postSave()
{
}
- // deletes each record in the collection
+ /**
+ *
+ * Deletes each record in the collection one-by-one.
+ *
+ * @return void
+ *
+ */
public function delete()
{
$this->_preDelete();
@@ -164,30 +231,26 @@
$this->_postDelete();
}
+ /**
+ *
+ * User-defined pre-delete logic.
+ *
+ * @return void
+ *
+ */
public function _preDelete()
{
}
- protected function _postDelete()
- {
- }
-
- // -----------------------------------------------------------------
- //
- // Iterator
- //
- // -----------------------------------------------------------------
-
/**
*
- * Iterator: returns the current record from the collection.
+ * User-defined post-delete logic.
*
- * @return Solar_Sql_Model_Record A model with a focus on one record.
+ * @return void
*
*/
- public function current()
+ protected function _postDelete()
{
- return $this->offsetGet($this->key());
}
// -----------------------------------------------------------------
@@ -196,38 +259,9 @@
//
// -----------------------------------------------------------------
- public function __get($key)
- {
- // convert array to record object
- // honors single-table inheritance
- if (is_array($this->_data[$key])) {
-
- // convert the data array to an object.
- // get the main data to load to the record.
- $load = $this->_data[$key];
-
- // add related data to load data
- $primary = $load[$this->_model->primary_col];
- foreach ($this->_related as $name => $data) {
- if (! empty($data[$primary])) {
- // add the data
- $load[$name] = $data[$primary];
- // save some memory
- unset($data[$primary]);
- }
- }
-
- // done
- $this->_data[$key] = $this->getModel()->newRecord($load);
- }
-
- // return the record
- return $this->_data[$key];
- }
-
/**
*
- * ArrayAccess: set a key value.
+ * ArrayAccess: set a key value; appends to the
*
* @param string $key The requested key.
*
Modified: trunk/Solar/Sql/Model/Exception.php
===================================================================
--- trunk/Solar/Sql/Model/Exception.php 2007-10-10 16:38:57 UTC (rev 2850)
+++ trunk/Solar/Sql/Model/Exception.php 2007-10-10 17:04:45 UTC (rev 2851)
@@ -1,2 +1,27 @@
<?php
+/**
+ *
+ * Base exception class for Solar_Sql_Model.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ *
+ */
+
+/**
+ *
+ * Base exception class for Solar_Sql_Model.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ */
class Solar_Sql_Model_Exception extends Solar_Sql_Exception {}
\ No newline at end of file
Modified: trunk/Solar/Sql/Model/Filter/ValidateConfirm.php
===================================================================
--- trunk/Solar/Sql/Model/Filter/ValidateConfirm.php 2007-10-10 16:38:57 UTC (rev 2850)
+++ trunk/Solar/Sql/Model/Filter/ValidateConfirm.php 2007-10-10 17:04:45 UTC (rev 2851)
@@ -1,4 +1,31 @@
<?php
+/**
+ *
+ * Validates that the "confirmation" value is the same as the "real"
+ * value being confirmed.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id$
+ *
+ */
+
+/**
+ *
+ * Validates that the "confirmation" value is the same as the "real"
+ * value being confirmed.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ */
class Solar_Sql_Model_Filter_ValidateConfirm extends Solar_Filter_Abstract {
/**
Modified: trunk/Solar/Sql/Model/Filter/ValidateUnique.php
===================================================================
--- trunk/Solar/Sql/Model/Filter/ValidateUnique.php 2007-10-10 16:38:57 UTC (rev 2850)
+++ trunk/Solar/Sql/Model/Filter/ValidateUnique.php 2007-10-10 17:04:45 UTC (rev 2851)
@@ -1,4 +1,31 @@
<?php
+/**
+ *
+ * Validates that a value for the current data key is unique among all
+ * model records of its inheritance type.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id$
+ *
+ */
+
+/**
+ *
+ * Validates that a value for the current data key is unique among all
+ * model records of its inheritance type.
+ *
+ * @category Solar
+ *
+ * @package Solar_Sql_Model
+ *
+ */
class Solar_Sql_Model_Filter_ValidateUnique extends Solar_Filter_Abstract {
/**
Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php 2007-10-10 16:38:57 UTC (rev 2850)
+++ trunk/Solar/Sql/Model.php 2007-10-10 17:04:45 UTC (rev 2851)
@@ -2,10 +2,8 @@
/**
*
* An SQL-centric Model class combining TableModule and TableDataGateway,
- * using a Collection of ActiveRecord objects for returns.
+ * using a Collection of Record objects for returns.
*
- * This class is Solar_Sql converted to do only the data mapping part.
- *
* @category Solar
*
* @package Solar_Sql_Model
@@ -21,7 +19,7 @@
/**
*
* An SQL-centric Model class combining TableModule and TableDataGateway,
- * using a Collection of ActiveRecord objects for returns.
+ * using a Collection of Record objects for returns.
*
* @category Solar
*
@@ -475,9 +473,10 @@
/**
*
- * Call this before you
+ * Call this before you unset the instance so that you release the memory
+ * from all the internal child objects.
*
- * @param array $config User-provided configuration values.
+ * @return void
*
*/
public function __destruct()
@@ -508,9 +507,11 @@
*
* Read-only access to protected model properties.
*
- * @var string $key The requested property; e.g., `'foo'` will read from
+ * @param string $key The requested property; e.g., `'foo'` will read from
* `$_foo`.
*
+ * @return mixed
+ *
*/
public function __get($key)
{
@@ -719,6 +720,19 @@
return $this->_fetchAll($select, $params);
}
+ /**
+ *
+ * Support method for fetchAll() to add eager related records.
+ *
+ * @param Solar_Sql_Select $select The select object for fetching.
+ *
+ * @param array $params The original params passed to fetchAll(). In
+ * general, only needed for the 'eager' key.
+ *
+ * @return mixed Solar_Sql_Model_Collection of found records, or an empty
+ * array if no records were found.
+ *
+ */
protected function _fetchAll($select, $params)
{
$data = $select->fetchAll();
@@ -797,6 +811,19 @@
return $this->_fetchAssoc($select, $params);
}
+ /**
+ *
+ * Support method for fetchAssoc() to add eager related records.
+ *
+ * @param Solar_Sql_Select $select The select object for fetching.
+ *
+ * @param array $params The original params passed to fetchAll(). In
+ * general, only needed for the 'eager' key.
+ *
+ * @return mixed Solar_Sql_Model_Collection of found records, or an empty
+ * array if no records were found.
+ *
+ */
protected function _fetchAssoc($select, $params)
{
$data = $select->fetchAssoc();
@@ -1156,8 +1183,11 @@
*
* Counts the number of records in a related model for a given record.
*
- * @param string $name The relationship name.
+ * @param Solar_Sql_Model_Record $record The record to count related pages
+ * for.
*
+ * @param string $name The name of the relationship to count pages for.
+ *
* @param array $params Parameters for the related SELECT; honors keys for
* 'where', 'having', 'group', and 'paging'.
*
More information about the Solar-svn
mailing list