|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00034 class Zend_Service_Delicious_PostList implements Countable, Iterator, ArrayAccess 00035 { 00039 protected $_posts = array(); 00040 00044 protected $_service; 00045 00049 protected $_iteratorKey = 0; 00050 00056 public function __construct(Zend_Service_Delicious $service, $posts = null) 00057 { 00058 $this->_service = $service; 00059 if ($posts instanceof DOMNodeList) { 00060 $this->_constructFromNodeList($posts); 00061 } else if (is_array($posts)) { 00062 $this->_constructFromArray($posts); 00063 } 00064 } 00065 00072 private function _constructFromNodeList(DOMNodeList $nodeList) 00073 { 00074 for ($i = 0; $i < $nodeList->length; $i++) { 00075 $curentNode = $nodeList->item($i); 00076 if($curentNode->nodeName == 'post') { 00077 $this->_addPost(new Zend_Service_Delicious_Post($this->_service, $curentNode)); 00078 } 00079 } 00080 } 00081 00088 private function _constructFromArray(array $postList) 00089 { 00090 foreach ($postList as $f_post) { 00091 $this->_addPost(new Zend_Service_Delicious_SimplePost($f_post)); 00092 } 00093 } 00094 00101 protected function _addPost(Zend_Service_Delicious_SimplePost $post) 00102 { 00103 $this->_posts[] = $post; 00104 00105 return $this; 00106 } 00107 00114 public function withTags(array $tags) 00115 { 00116 $postList = new self($this->_service); 00117 00118 foreach ($this->_posts as $post) { 00119 if (count(array_diff($tags, $post->getTags())) == 0) { 00120 $postList->_addPost($post); 00121 } 00122 } 00123 00124 return $postList; 00125 } 00126 00133 public function withTag($tag) 00134 { 00135 return $this->withTags(func_get_args()); 00136 } 00137 00144 public function withUrl($regexp) 00145 { 00146 $postList = new self($this->_service); 00147 00148 foreach ($this->_posts as $post) { 00149 if (preg_match($regexp, $post->getUrl())) { 00150 $postList->_addPost($post); 00151 } 00152 } 00153 00154 return $postList; 00155 } 00156 00164 public function count() 00165 { 00166 return count($this->_posts); 00167 } 00168 00176 public function current() 00177 { 00178 return $this->_posts[$this->_iteratorKey]; 00179 } 00180 00188 public function key() 00189 { 00190 return $this->_iteratorKey; 00191 } 00192 00200 public function next() 00201 { 00202 $this->_iteratorKey += 1; 00203 } 00204 00212 public function rewind() 00213 { 00214 $this->_iteratorKey = 0; 00215 } 00216 00224 public function valid() 00225 { 00226 $numItems = $this->count(); 00227 00228 if ($numItems > 0 && $this->_iteratorKey < $numItems) { 00229 return true; 00230 } else { 00231 return false; 00232 } 00233 } 00234 00243 public function offsetExists($offset) 00244 { 00245 return ($offset < $this->count()); 00246 } 00247 00257 public function offsetGet($offset) 00258 { 00259 if ($this->offsetExists($offset)) { 00260 return $this->_posts[$offset]; 00261 } else { 00262 throw new OutOfBoundsException('Illegal index'); 00263 } 00264 } 00265 00275 public function offsetSet($offset, $value) 00276 { 00280 require_once 'Zend/Service/Delicious/Exception.php'; 00281 throw new Zend_Service_Delicious_Exception('You are trying to set read-only property'); 00282 } 00283 00292 public function offsetUnset($offset) 00293 { 00297 require_once 'Zend/Service/Delicious/Exception.php'; 00298 throw new Zend_Service_Delicious_Exception('You are trying to unset read-only property'); 00299 } 00300 }