Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Service/Delicious/Post.php
Go to the documentation of this file.
00001 <?php
00002 
00028 require_once 'Zend/Date.php';
00029 
00033 require_once 'Zend/Service/Delicious/SimplePost.php';
00034 
00035 
00045 class Zend_Service_Delicious_Post extends Zend_Service_Delicious_SimplePost
00046 {
00052     protected $_service;
00053 
00057     protected $_others;
00058 
00062     protected $_date;
00063 
00067     protected $_shared = true;
00068 
00072     protected $_hash;
00073 
00082     public function __construct(Zend_Service_Delicious $service, $values)
00083     {
00084         $this->_service = $service;
00085 
00086         if ($values instanceof DOMElement) {
00087             $values = self::_parsePostNode($values);
00088         }
00089 
00090         if (!is_array($values) || !isset($values['url']) || !isset($values['title'])) {
00094             require_once 'Zend/Service/Delicious/Exception.php';
00095             throw new Zend_Service_Delicious_Exception("Second argument must be array with at least 2 keys ('url' and"
00096                                                      . " 'title')");
00097         }
00098 
00099         if (isset($values['date']) && ! $values['date'] instanceof Zend_Date) {
00103             require_once 'Zend/Service/Delicious/Exception.php';
00104             throw new Zend_Service_Delicious_Exception("Date has to be an instance of Zend_Date");
00105         }
00106 
00107         foreach (array('url', 'title', 'notes', 'others', 'tags', 'date', 'shared', 'hash') as $key) {
00108             if (isset($values[$key])) {
00109                 $this->{"_$key"}  = $values[$key];
00110             }
00111         }
00112     }
00113 
00120     public function setTitle($newTitle)
00121     {
00122         $this->_title = (string) $newTitle;
00123 
00124         return $this;
00125     }
00126 
00133     public function setNotes($newNotes)
00134     {
00135         $this->_notes = (string) $newNotes;
00136 
00137         return $this;
00138     }
00139 
00146     public function setTags(array $tags)
00147     {
00148         $this->_tags = $tags;
00149 
00150         return $this;
00151     }
00152 
00159     public function addTag($tag)
00160     {
00161         $this->_tags[] = (string) $tag;
00162 
00163         return $this;
00164     }
00165 
00172     public function removeTag($tag)
00173     {
00174         $this->_tags = array_diff($this->_tags, array((string) $tag));
00175 
00176         return $this;
00177     }
00178 
00184     public function getDate()
00185     {
00186         return $this->_date;
00187     }
00188 
00198     public function getOthers()
00199     {
00200         return $this->_others;
00201     }
00202 
00208     public function getHash()
00209     {
00210         return $this->_hash;
00211     }
00212 
00218     public function getShared()
00219     {
00220         return $this->_shared;
00221     }
00222 
00229     public function setShared($isShared)
00230     {
00231         $this->_shared = (bool) $isShared;
00232 
00233         return $this;
00234     }
00235 
00241     public function delete()
00242     {
00243         return $this->_service->deletePost($this->_url);
00244     }
00245 
00251     public function save()
00252     {
00253         $parms = array(
00254             'url'        => $this->_url,
00255             'description'=> $this->_title,
00256             'extended'   => $this->_notes,
00257             'shared'     => ($this->_shared ? 'yes' : 'no'),
00258             'tags'       => implode(' ', (array) $this->_tags),
00259             'replace'    => 'yes'
00260         );
00261         /*
00262         if ($this->_date instanceof Zend_Date) {
00263             $parms['dt'] = $this->_date->get('Y-m-d\TH:i:s\Z');
00264         }
00265         */
00266 
00267         return $this->_service->makeRequest(Zend_Service_Delicious::PATH_POSTS_ADD, $parms);
00268     }
00269 
00276     protected static function _parsePostNode(DOMElement $node)
00277     {
00278         return array(
00279             'url'    => $node->getAttribute('href'),
00280             'title'  => $node->getAttribute('description'),
00281             'notes'  => $node->getAttribute('extended'),
00282             'others' => (int) $node->getAttribute('others'),
00283             'tags'   => explode(' ', $node->getAttribute('tag')),
00287             'date'   => new Zend_Date(strtotime($node->getAttribute('time'))),
00288             'shared' => ($node->getAttribute('shared') == 'no' ? false : true),
00289             'hash'   => $node->getAttribute('hash')
00290         );
00291     }
00292 }
 All Data Structures Namespaces Files Functions Variables Enumerations