From 239a301eaec4f6b3c94d27f6e8e12987852195ae Mon Sep 17 00:00:00 2001 From: alan bount Date: Mon, 22 Oct 2012 15:52:08 -0400 Subject: [PATCH] sco->find('content') now respects recursive option now distinguishes between recursive finds and non-recursive finds --- models/adobe_connect_sco.php | 61 +++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/models/adobe_connect_sco.php b/models/adobe_connect_sco.php index 7bc8fe8..1fab82e 100755 --- a/models/adobe_connect_sco.php +++ b/models/adobe_connect_sco.php @@ -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, ); @@ -348,6 +349,7 @@ 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 @@ -355,6 +357,20 @@ protected function _findSearch($state, $query = array(), $results = array()) { * @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'])) { @@ -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 * @@ -425,7 +478,7 @@ protected function _findSearchcontent($state, $query = array(), $results = array return $results; } } - + /** * Custom Find: path (folder heirarchy) * @@ -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