Skip to content

Commit

Permalink
Removing now dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 25, 2011
1 parent 4073584 commit 1ffa736
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 175 deletions.
155 changes: 0 additions & 155 deletions lib/Cake/View/Helper.php
Expand Up @@ -447,147 +447,6 @@ public function setEntity($entity, $setScope = false) {

$view->entityPath = $entity;
return;

// old implementation.
if ($setScope) {
$view->modelScope = false;
} elseif (!empty($view->entityPath) && $view->entityPath == $entity) {
return;
}

if ($entity === null) {
$view->model = null;
$view->association = null;
$view->modelId = null;
$view->modelScope = false;
$view->entityPath = null;
return;
}

$view->entityPath = $entity;
$model = $view->model;
$sameScope = $hasField = false;
$parts = array_values(Set::filter(explode('.', $entity), true));

if (empty($parts)) {
return;
}

$count = count($parts);
if ($count === 1) {
$sameScope = true;
} else {
if (is_numeric($parts[0])) {
$sameScope = true;
}
$reverse = array_reverse($parts);
$field = array_shift($reverse);
while(!empty($reverse)) {
$subject = array_shift($reverse);
if (is_numeric($subject)) {
continue;
}
if (ClassRegistry::isKeySet($subject)) {
$model = $subject;
break;
}
}
}

if (ClassRegistry::isKeySet($model)) {
$ModelObj = ClassRegistry::getObject($model);
for ($i = 0; $i < $count; $i++) {
if (
is_a($ModelObj, 'Model') &&
($ModelObj->hasField($parts[$i]) ||
array_key_exists($parts[$i], $ModelObj->validate))
) {
$hasField = $i;
if ($hasField === 0 || ($hasField === 1 && is_numeric($parts[0]))) {
$sameScope = true;
}
break;
}
}

if ($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) {
$sameScope = false;
}
}

if (!$view->association && $parts[0] == $view->field && $view->field != $view->model) {
array_unshift($parts, $model);
$hasField = true;
}
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;

switch (count($parts)) {
case 1:
if ($view->modelScope === false) {
$view->model = $parts[0];
} else {
$view->field = $parts[0];
if ($sameScope === false) {
$view->association = $parts[0];
}
}
break;
case 2:
if ($view->modelScope === false) {
list($view->model, $view->field) = $parts;
} elseif ($sameScope === true && $hasField === 0) {
list($view->field, $view->fieldSuffix) = $parts;
} elseif ($sameScope === true && $hasField === 1) {
list($view->modelId, $view->field) = $parts;
} else {
list($view->association, $view->field) = $parts;
}
break;
case 3:
if ($sameScope === true && $hasField === 1) {
list($view->modelId, $view->field, $view->fieldSuffix) = $parts;
} elseif ($hasField === 2) {
list($view->association, $view->modelId, $view->field) = $parts;
} else {
list($view->association, $view->field, $view->fieldSuffix) = $parts;
}
break;
case 4:
if ($parts[0] === $view->model) {
list($view->model, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
} else {
list($view->association, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
}
break;
default:
$reverse = array_reverse($parts);

if ($hasField) {
$view->field = $field;
if (!is_numeric($reverse[1]) && $reverse[1] != $model) {
$view->field = $reverse[1];
$view->fieldSuffix = $field;
}
}
if (is_numeric($parts[0])) {
$view->modelId = $parts[0];
} elseif ($view->model == $parts[0] && is_numeric($parts[1])) {
$view->modelId = $parts[1];
}
$view->association = $model;
break;
}

if (!isset($view->model) || empty($view->model)) {
$view->model = $view->association;
$view->association = null;
} elseif ($view->model === $view->association) {
$view->association = null;
}

if ($setScope) {
$view->modelScope = true;
}
}

/**
Expand All @@ -603,15 +462,6 @@ public function model() {
return $this->_View->modelScope;
}

/**
* Gets the ID of the currently-used model of the rendering context.
*
* @return mixed
*/
public function modelID() {
return $this->_View->modelId;
}

/**
* Gets the currently-used model field of the rendering context.
*
Expand Down Expand Up @@ -766,11 +616,6 @@ public function value($options = array(), $field = null, $key = 'value') {
$result = $this->__selectedArray($data[$habtmKey], $model->primaryKey);
}
}
if (is_array($result)) {
if (array_key_exists($this->_View->fieldSuffix, $result)) {
$result = $result[$this->_View->fieldSuffix];
}
}

if (is_array($options)) {
if ($result === null && isset($options['default'])) {
Expand Down
20 changes: 0 additions & 20 deletions lib/Cake/View/View.php
Expand Up @@ -552,26 +552,6 @@ public function uuid($object, $url) {
*/
public function entity() {
return explode('.', $this->entityPath);

// old implementation.
$assoc = ($this->association) ? $this->association : $this->model;
if (!empty($this->entityPath)) {
$path = explode('.', $this->entityPath);
$count = count($path);
if (
($count == 1 && !empty($this->association)) ||
($count == 1 && $this->model != $this->entityPath) ||
($count == 1 && empty($this->association) && !empty($this->field)) ||
($count == 2 && !empty($this->fieldSuffix)) ||
is_numeric($path[0]) && !empty($assoc)
) {
array_unshift($path, $assoc);
}
return Set::filter($path);
}
return array_values(Set::filter(
array($assoc, $this->modelId, $this->field, $this->fieldSuffix)
));
}

/**
Expand Down

0 comments on commit 1ffa736

Please sign in to comment.