Skip to content

Commit

Permalink
Fixing strict errors in translate and acl behaviors.
Browse files Browse the repository at this point in the history
Removing conditional definition of I18nModel.  There is no reason for it to exist anymore.
Removing duplicate class definition.
  • Loading branch information
markstory committed Dec 12, 2010
1 parent cc81f6d commit 48879f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 59 deletions.
8 changes: 4 additions & 4 deletions cake/libs/model/behaviors/acl.php
Expand Up @@ -43,7 +43,7 @@ class AclBehavior extends ModelBehavior {
* @param mixed $config
* @return void
*/
public function setup(&$model, $config = array()) {
public function setup($model, $config = array()) {
if (is_string($config)) {
$config = array('type' => $config);
}
Expand All @@ -67,7 +67,7 @@ public function setup(&$model, $config = array()) {
* @return array
* @link http://book.cakephp.org/view/1322/node
*/
public function node(&$model, $ref = null) {
public function node($model, $ref = null) {
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
if (empty($ref)) {
$ref = array('model' => $model->name, 'foreign_key' => $model->id);
Expand All @@ -81,7 +81,7 @@ public function node(&$model, $ref = null) {
* @param boolean $created True if this is a new record
* @return void
*/
public function afterSave(&$model, $created) {
public function afterSave($model, $created) {
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$parent = $model->parentNode();
if (!empty($parent)) {
Expand All @@ -105,7 +105,7 @@ public function afterSave(&$model, $created) {
*
* @return void
*/
public function afterDelete(&$model) {
public function afterDelete($model) {
$type = $this->__typeMaps[$this->settings[$model->name]['type']];
$node = Set::extract($this->node($model), "0.{$type}.id");
if (!empty($node)) {
Expand Down
42 changes: 20 additions & 22 deletions cake/libs/model/behaviors/translate.php
Expand Up @@ -51,7 +51,7 @@ class TranslateBehavior extends ModelBehavior {
* @param array $config Array of configuration information.
* @return mixed
*/
public function setup(&$model, $config = array()) {
public function setup($model, $config = array()) {
$db = ConnectionManager::getDataSource($model->useDbConfig);
if (!$db->connected) {
trigger_error(
Expand All @@ -73,7 +73,7 @@ public function setup(&$model, $config = array()) {
* @param Model $model Model being detached.
* @return void
*/
public function cleanup(&$model) {
public function cleanup($model) {
$this->unbindTranslation($model);
unset($this->settings[$model->alias]);
unset($this->runtime[$model->alias]);
Expand All @@ -86,7 +86,7 @@ public function cleanup(&$model) {
* @param array $query Array of Query parameters.
* @return array Modified query
*/
public function beforeFind(&$model, $query) {
public function beforeFind($model, $query) {
$this->runtime[$model->alias]['virtualFields'] = $model->virtualFields;
$locale = $this->_getLocale($model);
if (empty($locale)) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public function beforeFind(&$model, $query) {
* @param boolean $primary Did the find originate on $model.
* @return array Modified results
*/
public function afterFind(&$model, $results, $primary) {
public function afterFind($model, $results, $primary) {
$model->virtualFields = $this->runtime[$model->alias]['virtualFields'];
$this->runtime[$model->alias]['virtualFields'] = $this->runtime[$model->alias]['fields'] = array();
$locale = $this->_getLocale($model);
Expand Down Expand Up @@ -242,7 +242,7 @@ public function afterFind(&$model, $results, $primary) {
* @param Model $model Model invalidFields was called on.
* @return boolean
*/
public function beforeValidate(&$model) {
public function beforeValidate($model) {
$locale = $this->_getLocale($model);
if (empty($locale)) {
return true;
Expand Down Expand Up @@ -276,15 +276,15 @@ public function beforeValidate(&$model) {
* @param boolean $created Whether or not the save created a record.
* @return void
*/
public function afterSave(&$model, $created) {
public function afterSave($model, $created) {
if (!isset($this->runtime[$model->alias]['beforeSave'])) {
return true;
}
$locale = $this->_getLocale($model);
$tempData = $this->runtime[$model->alias]['beforeSave'];
unset($this->runtime[$model->alias]['beforeSave']);
$conditions = array('model' => $model->alias, 'foreign_key' => $model->id);
$RuntimeModel =& $this->translateModel($model);
$RuntimeModel = $this->translateModel($model);

foreach ($tempData as $field => $value) {
unset($conditions['content']);
Expand Down Expand Up @@ -319,8 +319,8 @@ public function afterSave(&$model, $created) {
* @param Model $model Model the callback was run on.
* @return void
*/
public function afterDelete(&$model) {
$RuntimeModel =& $this->translateModel($model);
public function afterDelete($model) {
$RuntimeModel = $this->translateModel($model);
$conditions = array('model' => $model->alias, 'foreign_key' => $model->id);
$RuntimeModel->deleteAll($conditions);
}
Expand All @@ -331,12 +331,12 @@ public function afterDelete(&$model) {
* @param Model $model Model the locale needs to be set/get on.
* @return mixed string or false
*/
protected function _getLocale(&$model) {
protected function _getLocale($model) {
if (!isset($model->locale) || is_null($model->locale)) {
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
$I18n =& I18n::getInstance();
$I18n = I18n::getInstance();
$I18n->l10n->get(Configure::read('Config.language'));
$model->locale = $I18n->l10n->locale;
}
Expand All @@ -353,7 +353,7 @@ protected function _getLocale(&$model) {
* @param Model $model Model to get a translatemodel for.
* @return object
*/
public function &translateModel(&$model) {
public function translateModel($model) {
if (!isset($this->runtime[$model->alias]['model'])) {
if (!isset($model->translateModel) || empty($model->translateModel)) {
$className = 'I18nModel';
Expand All @@ -380,12 +380,12 @@ public function &translateModel(&$model) {
* @param boolean $reset
* @return bool
*/
function bindTranslation(&$model, $fields, $reset = true) {
function bindTranslation($model, $fields, $reset = true) {
if (is_string($fields)) {
$fields = array($fields);
}
$associations = array();
$RuntimeModel =& $this->translateModel($model);
$RuntimeModel = $this->translateModel($model);
$default = array('className' => $RuntimeModel->alias, 'foreignKey' => 'foreign_key');

foreach ($fields as $key => $value) {
Expand Down Expand Up @@ -453,7 +453,7 @@ function bindTranslation(&$model, $fields, $reset = true) {
* unbind all original translations
* @return bool
*/
function unbindTranslation(&$model, $fields = null) {
function unbindTranslation($model, $fields = null) {
if (empty($fields) && empty($this->settings[$model->alias])) {
return false;
}
Expand All @@ -464,7 +464,7 @@ function unbindTranslation(&$model, $fields = null) {
if (is_string($fields)) {
$fields = array($fields);
}
$RuntimeModel =& $this->translateModel($model);
$RuntimeModel = $this->translateModel($model);
$associations = array();

foreach ($fields as $key => $value) {
Expand Down Expand Up @@ -499,15 +499,13 @@ function unbindTranslation(&$model, $fields = null) {
return true;
}
}
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {

/**
* @package cake
* @subpackage cake.cake.libs.model.behaviors
*/
class I18nModel extends AppModel {
public $name = 'I18nModel';
public $useTable = 'i18n';
public $displayField = 'field';
}
class I18nModel extends AppModel {
public $name = 'I18nModel';
public $useTable = 'i18n';
public $displayField = 'field';
}
34 changes: 1 addition & 33 deletions cake/tests/cases/libs/model/models.php
Expand Up @@ -2591,38 +2591,6 @@ class MyCategoriesMyProduct extends CakeTestModel {
public $name = 'MyCategoriesMyProduct';
}

/**
* I18nModel class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class I18nModel extends CakeTestModel {

/**
* name property
*
* @var string 'I18nModel'
* @access public
*/
public $name = 'I18nModel';

/**
* useTable property
*
* @var string 'i18n'
* @access public
*/
public $useTable = 'i18n';

/**
* displayField property
*
* @var string 'field'
* @access public
*/
public $displayField = 'field';
}

/**
* NumberTree class
Expand Down Expand Up @@ -2662,7 +2630,7 @@ class NumberTree extends CakeTestModel {
*/
function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parent_id = null, $prefix = '1', $hierachial = true) {
if (!$parent_id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->truncate($this->table);
$this->save(array($this->name => array('name' => '1. Root')));
$this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierachial);
Expand Down

0 comments on commit 48879f8

Please sign in to comment.