Skip to content

Instantly share code, notes, and snippets.

@jaredhoyt
Created January 7, 2011 18:45
Show Gist options
  • Save jaredhoyt/769900 to your computer and use it in GitHub Desktop.
Save jaredhoyt/769900 to your computer and use it in GitHub Desktop.
<?php
function _findAccessible($state, $query, $results = array()) {
if ($state == 'before') {
if (isset($query[0]) && is_numeric($query[0])) {
$query['conditions'][$this->alias . '.id'] = $query[0];
}
$query['fields'] = $this->primaryKey;
$query['recursive'] = -1;
return $query;
} elseif ($state == 'after') {
$results = Set::extract('/' . $this->alias . '/id', $results);
foreach ($results as $id) {
$results = array_merge($results, $this->find('accessible', array(
'conditions' => array($this->alias . '.supervisor_id' => $id)
)));
}
return array_unique($results);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment