|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00028 require_once 'Zend/Service/Flickr/Result.php'; 00029 00030 00038 class Zend_Service_Flickr_ResultSet implements SeekableIterator 00039 { 00045 public $totalResultsAvailable; 00046 00052 public $totalResultsReturned; 00053 00059 public $firstResultPosition; 00060 00066 protected $_results = null; 00067 00073 private $_flickr; 00074 00080 private $_currentIndex = 0; 00081 00089 public function __construct(DOMDocument $dom, Zend_Service_Flickr $flickr) 00090 { 00091 $this->_flickr = $flickr; 00092 00093 $xpath = new DOMXPath($dom); 00094 00095 $photos = $xpath->query('//photos')->item(0); 00096 00097 $page = $photos->getAttribute('page'); 00098 $pages = $photos->getAttribute('pages'); 00099 $perPage = $photos->getAttribute('perpage'); 00100 $total = $photos->getAttribute('total'); 00101 00102 $this->totalResultsReturned = ($page == $pages || $pages == 0) ? ($total - ($page - 1) * $perPage) : (int) $perPage; 00103 $this->firstResultPosition = ($page - 1) * $perPage + 1; 00104 $this->totalResultsAvailable = (int) $total; 00105 00106 if ($total > 0) { 00107 $this->_results = $xpath->query('//photo'); 00108 } 00109 } 00110 00116 public function totalResults() 00117 { 00118 return $this->totalResultsReturned; 00119 } 00120 00126 public function current() 00127 { 00128 return new Zend_Service_Flickr_Result($this->_results->item($this->_currentIndex), $this->_flickr); 00129 } 00130 00136 public function key() 00137 { 00138 return $this->_currentIndex; 00139 } 00140 00146 public function next() 00147 { 00148 $this->_currentIndex += 1; 00149 } 00150 00156 public function rewind() 00157 { 00158 $this->_currentIndex = 0; 00159 } 00160 00168 public function seek($index) 00169 { 00170 $indexInt = (int) $index; 00171 if ($indexInt >= 0 && (null === $this->_results || $indexInt < $this->_results->length)) { 00172 $this->_currentIndex = $indexInt; 00173 } else { 00174 throw new OutOfBoundsException("Illegal index '$index'"); 00175 } 00176 } 00177 00183 public function valid() 00184 { 00185 return null !== $this->_results && $this->_currentIndex < $this->_results->length; 00186 } 00187 } 00188