Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Gdata/Spreadsheets.php
Go to the documentation of this file.
00001 <?php
00002 
00027 require_once('Zend/Gdata.php');
00028 
00032 require_once('Zend/Gdata/Spreadsheets/SpreadsheetFeed.php');
00033 
00037 require_once('Zend/Gdata/Spreadsheets/WorksheetFeed.php');
00038 
00042 require_once('Zend/Gdata/Spreadsheets/CellFeed.php');
00043 
00047 require_once('Zend/Gdata/Spreadsheets/ListFeed.php');
00048 
00052 require_once('Zend/Gdata/Spreadsheets/SpreadsheetEntry.php');
00053 
00057 require_once('Zend/Gdata/Spreadsheets/WorksheetEntry.php');
00058 
00062 require_once('Zend/Gdata/Spreadsheets/CellEntry.php');
00063 
00067 require_once('Zend/Gdata/Spreadsheets/ListEntry.php');
00068 
00072 require_once('Zend/Gdata/Spreadsheets/DocumentQuery.php');
00073 
00077 require_once('Zend/Gdata/Spreadsheets/ListQuery.php');
00078 
00082 require_once('Zend/Gdata/Spreadsheets/CellQuery.php');
00083 
00095 class Zend_Gdata_Spreadsheets extends Zend_Gdata
00096 {
00097     const SPREADSHEETS_FEED_URI = 'http://spreadsheets.google.com/feeds/spreadsheets';
00098     const SPREADSHEETS_POST_URI = 'http://spreadsheets.google.com/feeds/spreadsheets/private/full';
00099     const WORKSHEETS_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#worksheetsfeed';
00100     const LIST_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#listfeed';
00101     const CELL_FEED_LINK_URI = 'http://schemas.google.com/spreadsheets/2006#cellsfeed';
00102     const AUTH_SERVICE_NAME = 'wise';
00103 
00109     public static $namespaces = array(
00110         array('gs', 'http://schemas.google.com/spreadsheets/2006', 1, 0),
00111         array(
00112             'gsx', 'http://schemas.google.com/spreadsheets/2006/extended', 1, 0)
00113     );
00114 
00122     public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
00123     {
00124         $this->registerPackage('Zend_Gdata_Spreadsheets');
00125         $this->registerPackage('Zend_Gdata_Spreadsheets_Extension');
00126         parent::__construct($client, $applicationId);
00127         $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
00128         $this->_server = 'spreadsheets.google.com';
00129     }
00130 
00137     public function getSpreadsheetFeed($location = null)
00138     {
00139         if ($location == null) {
00140             $uri = self::SPREADSHEETS_FEED_URI;
00141         } else if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
00142             if ($location->getDocumentType() == null) {
00143                 $location->setDocumentType('spreadsheets');
00144             }
00145             $uri = $location->getQueryUrl();
00146         } else {
00147             $uri = $location;
00148         }
00149 
00150         return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_SpreadsheetFeed');
00151     }
00152 
00159     public function getSpreadsheetEntry($location)
00160     {
00161         if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
00162             if ($location->getDocumentType() == null) {
00163                 $location->setDocumentType('spreadsheets');
00164             }
00165             $uri = $location->getQueryUrl();
00166         } else {
00167             $uri = $location;
00168         }
00169 
00170         return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_SpreadsheetEntry');
00171     }
00172 
00179     public function getWorksheetFeed($location)
00180     {
00181         if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
00182             if ($location->getDocumentType() == null) {
00183                 $location->setDocumentType('worksheets');
00184             }
00185             $uri = $location->getQueryUrl();
00186         } else if ($location instanceof Zend_Gdata_Spreadsheets_SpreadsheetEntry) {
00187             $uri = $location->getLink(self::WORKSHEETS_FEED_LINK_URI)->href;
00188         } else {
00189             $uri = $location;
00190         }
00191 
00192         return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_WorksheetFeed');
00193     }
00194 
00201     public function GetWorksheetEntry($location)
00202     {
00203         if ($location instanceof Zend_Gdata_Spreadsheets_DocumentQuery) {
00204             if ($location->getDocumentType() == null) {
00205                 $location->setDocumentType('worksheets');
00206             }
00207             $uri = $location->getQueryUrl();
00208         } else {
00209             $uri = $location;
00210         }
00211 
00212         return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_WorksheetEntry');
00213     }
00214 
00221     public function getCellFeed($location)
00222     {
00223         if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
00224             $uri = $location->getQueryUrl();
00225         } else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
00226             $uri = $location->getLink(self::CELL_FEED_LINK_URI)->href;
00227         } else {
00228             $uri = $location;
00229         }
00230         return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_CellFeed');
00231     }
00232 
00239     public function getCellEntry($location)
00240     {
00241         if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
00242             $uri = $location->getQueryUrl();
00243         } else {
00244             $uri = $location;
00245         }
00246 
00247         return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_CellEntry');
00248     }
00249 
00256     public function getListFeed($location)
00257     {
00258         if ($location instanceof Zend_Gdata_Spreadsheets_ListQuery) {
00259             $uri = $location->getQueryUrl();
00260         } else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
00261             $uri = $location->getLink(self::LIST_FEED_LINK_URI)->href;
00262         } else {
00263             $uri = $location;
00264         }
00265 
00266         return parent::getFeed($uri, 'Zend_Gdata_Spreadsheets_ListFeed');
00267     }
00268 
00275     public function getListEntry($location)
00276     {
00277         if ($location instanceof Zend_Gdata_Spreadsheets_ListQuery) {
00278             $uri = $location->getQueryUrl();
00279         } else {
00280             $uri = $location;
00281         }
00282 
00283         return parent::getEntry($uri, 'Zend_Gdata_Spreadsheets_ListEntry');
00284     }
00285 
00296     public function updateCell($row, $col, $inputValue, $key, $wkshtId = 'default')
00297     {
00298         $cell = 'R'.$row.'C'.$col;
00299 
00300         $query = new Zend_Gdata_Spreadsheets_CellQuery();
00301         $query->setSpreadsheetKey($key);
00302         $query->setWorksheetId($wkshtId);
00303         $query->setCellId($cell);
00304 
00305         $entry = $this->getCellEntry($query);
00306         $entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
00307         $response = $entry->save();
00308         return $response;
00309     }
00310 
00319     public function insertRow($rowData, $key, $wkshtId = 'default')
00320     {
00321         $newEntry = new Zend_Gdata_Spreadsheets_ListEntry();
00322         $newCustomArr = array();
00323         foreach ($rowData as $k => $v) {
00324             $newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom();
00325             $newCustom->setText($v)->setColumnName($k);
00326             $newEntry->addCustom($newCustom);
00327         }
00328 
00329         $query = new Zend_Gdata_Spreadsheets_ListQuery();
00330         $query->setSpreadsheetKey($key);
00331         $query->setWorksheetId($wkshtId);
00332 
00333         $feed = $this->getListFeed($query);
00334         $editLink = $feed->getLink('http://schemas.google.com/g/2005#post');
00335 
00336         return $this->insertEntry($newEntry->saveXML(), $editLink->href, 'Zend_Gdata_Spreadsheets_ListEntry');
00337     }
00338 
00345     public function updateRow($entry, $newRowData)
00346     {
00347         $newCustomArr = array();
00348         foreach ($newRowData as $k => $v) {
00349             $newCustom = new Zend_Gdata_Spreadsheets_Extension_Custom();
00350             $newCustom->setText($v)->setColumnName($k);
00351             $newCustomArr[] = $newCustom;
00352         }
00353         $entry->setCustom($newCustomArr);
00354 
00355         return $entry->save();
00356     }
00357 
00363     public function deleteRow($entry)
00364     {
00365         $entry->delete();
00366     }
00367 
00374     public function getSpreadsheetListFeedContents($location)
00375     {
00376         $listFeed = $this->getListFeed($location);
00377         $listFeed = $this->retrieveAllEntriesForFeed($listFeed);
00378         $spreadsheetContents = array();
00379         foreach ($listFeed as $listEntry) {
00380             $rowContents = array();
00381             $customArray = $listEntry->getCustom();
00382             foreach ($customArray as $custom) {
00383                 $rowContents[$custom->getColumnName()] = $custom->getText();
00384             }
00385             $spreadsheetContents[] = $rowContents;
00386         }
00387         return $spreadsheetContents;
00388     }
00389 
00403     public function getSpreadsheetCellFeedContents($location, $range = null, $empty = false)
00404     {
00405         $cellQuery = null;
00406         if ($location instanceof Zend_Gdata_Spreadsheets_CellQuery) {
00407             $cellQuery = $location;
00408         } else if ($location instanceof Zend_Gdata_Spreadsheets_WorksheetEntry) {
00409             $url = $location->getLink(self::CELL_FEED_LINK_URI)->href;
00410             $cellQuery = new Zend_Gdata_Spreadsheets_CellQuery($url);
00411         } else {
00412             $url = $location;
00413             $cellQuery = new Zend_Gdata_Spreadsheets_CellQuery($url);
00414         }
00415 
00416         if ($range != null) {
00417             $cellQuery->setRange($range);
00418         }
00419         $cellQuery->setReturnEmpty($empty);
00420 
00421         $cellFeed = $this->getCellFeed($cellQuery);
00422         $cellFeed = $this->retrieveAllEntriesForFeed($cellFeed);
00423         $spreadsheetContents = array();
00424         foreach ($cellFeed as $cellEntry) {
00425             $cellContents = array();
00426             $cell = $cellEntry->getCell();
00427             $cellContents['formula'] = $cell->getInputValue();
00428             $cellContents['value'] = $cell->getText();
00429             $spreadsheetContents[$cellEntry->getTitle()->getText()] = $cellContents;
00430         }
00431         return $spreadsheetContents;
00432     }
00433 
00440     public function getSpreadsheets($location = null)
00441     {
00442         return $this->getSpreadsheetFeed($location = null);
00443     }
00444 
00445 }
 All Data Structures Namespaces Files Functions Variables Enumerations