Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 66 → Rev 67

/trunk/Model.php
92,6 → 92,42
}
 
/**
* Returns an array containing the property-column mapping.
*
* @param array $propertyNames = null
* Names of the properties that should be included.
* The default is to include all persistent properties.
* @return array
*/
public static function getPersistentMapping (array $propertyNames = null)
{
$a = array();
 
$persistent_properties = static::$_persistentProperties;
 
if ($propertyNames === null)
{
$propertyNames = $persistent_properties;
}
 
foreach ($propertyNames as $property_name)
{
if (!array_key_exists($property_name, $persistent_properties))
{
$column_name = $property_name;
}
else
{
$column_name = $persistent_properties[$property_name];
}
 
$a[$property_name] = $column_name;
}
 
return $a;
}
 
/**
* Returns an array for database queries containing the
* property values of this object, using the specified
* property-to-column mapping.
130,12 → 166,11
*
* @param mixed $id = null
* The ID of the object to find. If <code>null</code> (default),
* the object is search for by its current ID.
* @see Table::find(Model)
* the object is searched for by its current ID.
* @return Model|null
* This object filled with missing data, or <code>null</code>
* if there is no data for this object
* @see Table::find(Model)
* @see Table::find(int)
*/
public function find ($id = null)
{
161,6 → 196,44
}
 
/**
* Finds the records for model objects in the table by value,
* and returns the result.
*
* @param string $name
* Name of the property to search for.
* @param mixed $value = null
* The property value to find. If <code>null</code>,
* the current value of the specified property is used.
* (To search for null, you need to make sure that the
* current property value is <code>null</code>, which is
* the PHP default.)
* @return array[Model]|null
* Model objects, or <code>null</code> if there is no data
* for this property and value
* @see Table::select(Model)
*/
public function findByProperty ($name, $value = null)
{
$class = \get_class($this);
$mapping = $class::getPersistentMapping(array($name));
 
if ($value === null)
{
$value = $this->$name;
}
 
$results = $this->persistentTable->select(null,
array($mapping[$name] => $value));
 
if ($results)
{
return array_map(array($this, 'map'), $results);
}
 
return null;
}
 
/**
* Saves the model object in the table
*
* @param array $propertyNames = null