Skip to content

Commit

Permalink
Merge commit 'v2.6.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
enyo committed Mar 13, 2012
2 parents f2025c7 + 03b7529 commit 6ec3174
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rincewind Version 2.6.3 # Rincewind Version 2.6.4


Is a PHP library. Is a PHP library.


Expand Down
6 changes: 3 additions & 3 deletions library/Dao/File/FileDaoBase.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function exportMap($map) {


if ( ! is_array($map)) throw new DaoWrongValueException("The passed map is not an array."); if ( ! is_array($map)) throw new DaoWrongValueException("The passed map is not an array.");


$assignments = array(); $exportedMap = array();


foreach ($map as $attributeName => $value) { foreach ($map as $attributeName => $value) {
if ($value instanceof DaoAttributeAssignment) { if ($value instanceof DaoAttributeAssignment) {
Expand All @@ -267,10 +267,10 @@ protected function exportMap($map) {
} }


$type = $this->attributes[$attributeName]; $type = $this->attributes[$attributeName];
$map[$this->exportAttributeName($attributeName)] = $this->exportValue($attributeName, $value, $type, $this->notNull($attributeName)); $exportedMap[$this->exportAttributeName($attributeName)] = $this->exportValue($attributeName, $value, $type, $this->notNull($attributeName));
} }


return $map; return $exportedMap;
} }


/** /**
Expand Down
25 changes: 24 additions & 1 deletion library/Dao/Reference/BasicDaoReference.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ abstract class BasicDaoReference implements DaoReference {
* @var string * @var string
*/ */
protected $foreignKey = 'id'; protected $foreignKey = 'id';
/**
* Can contain values the referenced records will be filtered with.
*
* Eg.: array('deleted' => false)
*
* @var array
*/
protected $filterMap;
/** /**
* The Dao this reference is assigned to. * The Dao this reference is assigned to.
* @var Dao * @var Dao
Expand All @@ -109,13 +117,15 @@ abstract class BasicDaoReference implements DaoReference {
* @param bool $export specifies if this reference should be sent to the * @param bool $export specifies if this reference should be sent to the
* datasource when saving. * datasource when saving.
* @param bool $exportData If true, the complete data will be exported, not only the id. * @param bool $exportData If true, the complete data will be exported, not only the id.
* @param array $filterMap
*/ */
public function __construct($foreignDaoName, $localKey = null, $foreignKey = null, $export = false, $exportData = false) { public function __construct($foreignDaoName, $localKey = null, $foreignKey = null, $export = false, $exportData = false, $filterMap = null) {
$this->foreignDao = $foreignDaoName; $this->foreignDao = $foreignDaoName;
$this->localKey = $localKey; $this->localKey = $localKey;
if ($foreignKey !== null) $this->foreignKey = $foreignKey; if ($foreignKey !== null) $this->foreignKey = $foreignKey;
$this->export = $export; $this->export = $export;
$this->exportData = $exportData; $this->exportData = $exportData;
$this->filterMap = $filterMap;
} }


/** /**
Expand Down Expand Up @@ -234,4 +244,17 @@ protected function cacheAndReturn($record, $attributeName, $value) {
return $value; return $value;
} }


/**
* Adds the filterMap to the provided map.
* If values exist in both, $map will override the $filterMap
*
* @param array $map The map to add the filter to
* @return array
* @uses $filterMap
*/
protected function applyFilter($map) {
if (!$this->filterMap) return $map;
else return array_merge($this->filterMap, $map);
}

} }
7 changes: 4 additions & 3 deletions library/Dao/Reference/DaoJoinTableToManyReference.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class DaoJoinTableToManyReference extends BasicDaoToManyReference {
* @param string $joinToForeignKey * @param string $joinToForeignKey
* @param string $localKey * @param string $localKey
* @param string $foreignKey * @param string $foreignKey
* @param array $filterMap
*/ */
public function __construct($foreignDaoName, $joinDaoName, $joinToLocalKey, $joinToForeignKey, $localKey = 'id', $foreignKey = 'id') { public function __construct($foreignDaoName, $joinDaoName, $joinToLocalKey, $joinToForeignKey, $localKey = 'id', $foreignKey = 'id', $filterMap = null) {
parent::__construct($foreignDaoName, $localKey, $foreignKey, false); parent::__construct($foreignDaoName, $localKey, $foreignKey, false, false, $filterMap);
$this->joinDao = $joinDaoName; $this->joinDao = $joinDaoName;
$this->joinToLocalKey = $joinToLocalKey; $this->joinToLocalKey = $joinToLocalKey;
$this->joinToForeignKey = $joinToForeignKey; $this->joinToForeignKey = $joinToForeignKey;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function getReferenced($record, $attribute) {
$joinDao = $this->getJoinDao(); $joinDao = $this->getJoinDao();


// Get all joins, that point to the local key. // Get all joins, that point to the local key.
$joins = $joinDao->getIterator(array($this->getJoinToLocalKey() => $record->get($this->getLocalKey()))); $joins = $joinDao->getIterator($this->applyFilter(array($this->getJoinToLocalKey() => $record->get($this->getLocalKey()))));


// Extract an array of foreign keys. // Extract an array of foreign keys.
$foreignKeys = array(); $foreignKeys = array();
Expand Down
6 changes: 3 additions & 3 deletions library/Dao/Reference/DaoJoinToManyReference.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class DaoJoinToManyReference extends BasicDaoToManyReference {
* @param string $foreignKey * @param string $foreignKey
* @param string $localKey * @param string $localKey
*/ */
public function __construct($foreignDaoName, $foreignKey, $localKey = 'id') { public function __construct($foreignDaoName, $foreignKey, $localKey = 'id', $filterMap = null) {
parent::__construct($foreignDaoName, $localKey, $foreignKey, false); parent::__construct($foreignDaoName, $localKey, $foreignKey, false, false, $filterMap);
} }


/** /**
Expand All @@ -66,7 +66,7 @@ public function getReferenced($record, $attributeName) {
} }
} }
else { else {
return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getIterator(array($this->getForeignKey() => $record->get($this->getLocalKey())))); return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getIterator($this->applyFilter(array($this->getForeignKey() => $record->get($this->getLocalKey())))));
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion library/rincewind.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/** /**
* Defines the current rincewind version * Defines the current rincewind version
*/ */
define('RINCEWIND_VERSION', '2.6.3'); define('RINCEWIND_VERSION', '2.6.4');


/** /**
* Defines the path to the rincewind library. * Defines the path to the rincewind library.
Expand Down

0 comments on commit 6ec3174

Please sign in to comment.