Skip to content

Commit

Permalink
sco->find('content') now respects recursive option
Browse files Browse the repository at this point in the history
now distinguishes between recursive finds and non-recursive finds
  • Loading branch information
zeroasterisk committed Oct 22, 2012
1 parent 8e7e854 commit 239a301
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions models/adobe_connect_sco.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class AdobeConnectSco extends AdobeConnectAppModel {
public $_findMethods = array(
'search' => true,
'contents' => true,
'contents' => true,
'contents_recursive' => true,
'contents_non_recursive' => true,
'info' => true,
'path' => true,
);
Expand Down Expand Up @@ -348,13 +349,28 @@ protected function _findSearch($state, $query = array(), $results = array()) {

/**
* Custom Find: akin to 'all', searches within a sco, optionally filter with conditions
* routes to recursive or non-recursive
* $this->AdobeConnectSco->find('contents', 12345);
* $this->AdobeConnectSco->find('contents', array('sco-id' => 12345, 'conditions' => array('icon' => 'archive')));
* @param string $state
* @param array $query
* @param array $results
*/
protected function _findContents($state, $query = array(), $results = array()) {
if (isset($query['recursive']) && !empty($query['recursive'])) {
return $this->_findContentsRecursive($state, $query, $results);
}
return $this->_findContentsNonRecursive($state, $query, $results);
}
/**
* Custom Find: akin to 'all', searches within a sco, optionally filter with conditions Recursive
* $this->AdobeConnectSco->find('contents', 12345);
* $this->AdobeConnectSco->find('contents', array('sco-id' => 12345, 'conditions' => array('icon' => 'archive')));
* @param string $state
* @param array $query
* @param array $results
*/
protected function _findContentsRecursive($state, $query = array(), $results = array()) {
if ($state == 'before') {
$this->request = array("action" => "sco-expanded-contents");
if (isset($query['sco-id']) && !empty($query['sco-id']) && is_numeric($query['sco-id'])) {
Expand Down Expand Up @@ -384,6 +400,43 @@ protected function _findContents($state, $query = array(), $results = array()) {
}
}

/**
* Custom Find: akin to 'all', searches within a sco, optionally filter with conditions Non Recursive
* $this->AdobeConnectSco->find('contents', 12345);
* $this->AdobeConnectSco->find('contents', array('sco-id' => 12345, 'conditions' => array('icon' => 'archive')));
* @param string $state
* @param array $query
* @param array $results
*/
protected function _findContentsNonRecursive($state, $query = array(), $results = array()) {
if ($state == 'before') {
$this->request = array("action" => "sco-contents");
if (isset($query['sco-id']) && !empty($query['sco-id']) && is_numeric($query['sco-id'])) {
$this->request["sco-id"] = $query['sco-id'];
unset($query['sco-id']);
} elseif (isset($query['conditions']['sco-id']) && !empty($query['conditions']['sco-id']) && is_numeric($query['conditions']['sco-id'])) {
$this->request["sco-id"] = $query['conditions']['sco-id'];
unset($query['conditions']['sco-id']);
} elseif (isset($query[0]) && !empty($query[0]) && is_numeric($query[0])) {
$this->request["sco-id"] = $query[0];
unset($query[0]);
}
if (!isset($this->request["sco-id"]) || empty($this->request["sco-id"])) {
die("ERROR: you must include a value for to find('contents', \$options['sco-id'])");
}
$this->request = set::merge($this->request, $this->parseFiltersFromQuery($query));
$query = $this->_paginationParams($query);
return $query;
} else {
$unformatted = set::extract($results, "/Scos/Sco/.");
$results = array();
foreach ( $unformatted as $node ) {
$results[] = array($this->alias => $node);
}
return $results;
}
}

/**
* Custom Find: akin to 'all', allows a simple search, globally. Seems to require two search parameters in the query, optionally filter with conditions
*
Expand Down Expand Up @@ -425,7 +478,7 @@ protected function _findSearchcontent($state, $query = array(), $results = array
return $results;
}
}

/**
* Custom Find: path (folder heirarchy)
*
Expand All @@ -451,8 +504,8 @@ protected function _findPath($state, $query = array(), $results = array()) {
}
return $return;
}


/**
* A jankity overwrite of the _findCount method
* Needed to clean saves
Expand Down

0 comments on commit 239a301

Please sign in to comment.