From 5582309fd39b67a7dcc2490fff35f703e702236f Mon Sep 17 00:00:00 2001 From: Dardo Sordi Date: Tue, 6 May 2008 11:35:18 -0300 Subject: [PATCH] added utility methods to manipulate the scope in the Scoped behavior, fixed the spell and the docblocks --- models/behaviors/scoped.php | 63 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/models/behaviors/scoped.php b/models/behaviors/scoped.php index 771c38e..06d9cc0 100644 --- a/models/behaviors/scoped.php +++ b/models/behaviors/scoped.php @@ -16,7 +16,7 @@ class ScopedBehavior extends ModelBehavior { var $settings = array(); /** - * Stores globals pseudoconstants + * Stores global pseudoconstants * * @var Array */ @@ -25,7 +25,7 @@ class ScopedBehavior extends ModelBehavior { function __construct() { parent::__construct(); $this->globals = array( - 'CURRENT_DATE' => date('c'), + 'CURRENT_DATE' => date('Y-m-d'), 'NOW' => date('Y-m-d H:i:s') ); } @@ -42,7 +42,7 @@ class ScopedBehavior extends ModelBehavior { } /** - * Enables ScopedBhevior on this model + * Enables ScopedBehavior on this model * * @param Model $model */ @@ -51,7 +51,7 @@ class ScopedBehavior extends ModelBehavior { } /** - * Disables ScopedBhevior on this model + * Disables ScopedBehavior on this model * * @param Model $model */ @@ -60,6 +60,57 @@ class ScopedBehavior extends ModelBehavior { } /** + * Adds a scope condition for this model + * + * @param Model $model + * @param String $name + * @param String $value + */ + function addToScope(&$model, $name, $value = null) { + if (is_array($name)) { + $this->settings[$model->alias]['conditions'] = array_merge($this->settings[$model->alias]['constants'], $name); + } else { + $this->settings[$model->alias]['conditions'][$name] = $value; + } + } + + /** + * Unsets a scope condition for this model + * + * @param Model $model + * @param Mixed $name + */ + function removeFromScope(&$model, $name) { + if (is_array($name)) { + foreach ($name as $key) { + unset ($this->settings[$model->alias]['conditions'][$key]); + } + } else { + unset ($this->settings[$model->alias]['conditions'][$name]); + } + } + + /** + * Sets the current scope for this model + * + * @param Model $model + * @param Array $scope + */ + function setScope(&$model, $scope) { + $this->settings[$model->alias]['conditions'] = $scope; + } + + /** + * Gets the current scope for this model + * + * @param Model $model + * @return Array + */ + function getScope(&$model) { + return $this->settings[$model->alias]['conditions']; + } + + /** * Defines a pseudoconstant for this model * * It can handle an associative array in the form 'name' => 'value' @@ -79,8 +130,8 @@ class ScopedBehavior extends ModelBehavior { /** * Unsets a pseudconstant for this model * - * @param unknown_type $model - * @param unknown_type $name + * @param Model $model + * @param Mixed $name */ function removeConstant(&$model, $name) { if (is_array($name)) { -- 2.11.4.GIT