getInstance() public static method

[getInstance description]
public static getInstance ( ) : Google\Spreadsheet\ServiceRequestInterface
return Google\Spreadsheet\ServiceRequestInterface
 /**
  * Insert a new row into this feed
  * 
  * @param array $row
  * 
  * @return void
  */
 public function insert($row)
 {
     $entry = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">';
     foreach ($row as $colName => $value) {
         $entry .= sprintf('<gsx:%s><![CDATA[%s]]></gsx:%s>', $colName, $value, $colName);
     }
     $entry .= '</entry>';
     ServiceRequestFactory::getInstance()->post($this->getPostUrl(), $entry);
 }
Exemplo n.º 2
0
 /**
  * Insert a new row into this feed
  * 
  * @param array $row
  * 
  * @return void
  */
 public function insert($row)
 {
     $entry = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">';
     foreach ($row as $colName => $value) {
         # added by @aravindanve
         $value = preg_replace('#(?:\\<\\!\\[CDATA\\[|\\]\\]\\>)#i', '*removed*', $value);
         $colName = strtolower(preg_replace('#[^a-z0-9\\-]#i', '', $colName));
         $entry .= sprintf('<gsx:%s><![CDATA[%s]]></gsx:%s>', $colName, $value, $colName);
     }
     $entry .= '</entry>';
     ServiceRequestFactory::getInstance()->post($this->getPostUrl(), $entry);
 }
 /**
  * Delete this worksheet
  *
  * @return null
  */
 public function delete()
 {
     ServiceRequestFactory::getInstance()->delete($this->getEditUrl());
 }
Exemplo n.º 4
0
 /**
  *
  * @param \Google\Spreadsheet\Batch\BatchRequest $batchRequest
  *
  * @return \Google\Spreadsheet\Batch\BatchResponse
  */
 public function insertBatch(BatchRequest $batchRequest)
 {
     $xml = $batchRequest->createRequestXml($this);
     $response = ServiceRequestFactory::getInstance()->addHeader("If-Match", "*")->post($this->getBatchUrl(), $xml);
     ServiceRequestFactory::getInstance()->removeHeader("If-Match");
     return new BatchResponse(new SimpleXMLElement($response));
 }
Exemplo n.º 5
0
 /**
  * Returns a cell feed of the specified worksheet.
  * 
  * @see \Google\Spreadsheet\Worksheet::getWorksheetId()
  * 
  * @param string $worksheetId
  * 
  * @return \Google\Spreadsheet\CellFeed
  */
 public function getCellFeed($worksheetId)
 {
     return new CellFeed(ServiceRequestFactory::getInstance()->get("feeds/cells/{$worksheetId}/od6/private/full"));
 }
 /**
  * @expectedException Exception
  */
 public function testGetInstanceException()
 {
     ServiceRequestFactory::setInstance(null);
     ServiceRequestFactory::getInstance();
 }
Exemplo n.º 7
0
 /**
  * Update the cell value
  *
  * @param string $value
  * 
  * @return null
  */
 public function update($value)
 {
     $entry = sprintf('
         <entry xmlns="http://www.w3.org/2005/Atom"
             xmlns:gs="http://schemas.google.com/spreadsheets/2006">
           <gs:cell row="%u" col="%u" inputValue="%s"/>
         </entry>', $this->row, $this->column, $value);
     $res = ServiceRequestFactory::getInstance()->post($this->postUrl, $entry);
     $this->xml = new SimpleXMLElement($res);
 }
Exemplo n.º 8
0
 /**
  * Add a new worksheet to this spreadsheet
  *
  * @param string $title
  * @param int    $rowCount default is 100
  * @param int    $colCount default is 10
  *
  * @return \Google\Spreadsheet\Worksheet
  */
 public function addWorksheet($title, $rowCount = 100, $colCount = 10)
 {
     $entry = sprintf('
         <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gs="http://schemas.google.com/spreadsheets/2006">
             <title>%s</title>
             <gs:rowCount>%u</gs:rowCount>
             <gs:colCount>%u</gs:colCount>
         </entry>', $title, $rowCount, $colCount);
     $response = ServiceRequestFactory::getInstance()->post($this->getWorksheetsFeedUrl(), $entry);
     return new Worksheet(new SimpleXMLElement($response));
 }
 /**
  * Update the cell value
  *
  * @param string $value Can be a simple constant value or a formula
  * 
  * @return null
  */
 public function update($value)
 {
     $entry = new \SimpleXMLElement("\n            <entry\n                xmlns=\"http://www.w3.org/2005/Atom\"\n                xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">\n            </entry>\n        ");
     $child = $entry->addChild("xmlns:gs:cell");
     $child->addAttribute("row", $this->row);
     $child->addAttribute("col", $this->column);
     $child->addAttribute("inputValue", $value);
     $res = ServiceRequestFactory::getInstance()->post($this->postUrl, $entry->asXML());
     $this->xml = new \SimpleXMLElement($res);
 }
Exemplo n.º 10
0
    if ($method === "post") {
        $values = array();
        $parentPropertiesToCopy = array("fathersfirstname", "fatherslastname", "fathersemail", "fathersphone", "mothersfirstname", "motherslastname", "mothersemail", "mothersphone", "comments", "centercommunication");
        $childPropertiesToCopy = array("firstnameofchild", "lastnameofchild", "ssegroupofchild", "schoolgradeofchild", "allergiesofchild");
        for ($i = 1; $i < 3; ++$i) {
            if (empty($_REQUEST["firstnameofchild{$i}"])) {
                break;
            }
            $value = array();
            $value["timestamp"] = date("n/j/Y H:i:s");
            foreach ($parentPropertiesToCopy as $parentProperty) {
                $value[$parentProperty] = trim($_REQUEST[$parentProperty]);
            }
            foreach ($childPropertiesToCopy as $childProperty) {
                $value[$childProperty] = trim($_REQUEST["{$childProperty}{$i}"]);
            }
            array_push($values, $value);
        }
        foreach ($values as $value) {
            $combinedKey = strtolower(sprintf("%s-%s", $value["firstnameofchild"], $value["lastnameofchild"]));
            if ($rows[$combinedKey] && $rows[$combinedKey]["url"] && $rows[$combinedKey]["sheetTitle"] === "2015 Registration") {
                ServiceRequestFactory::getInstance()->delete($rows[$combinedKey]["url"]);
            }
            $registrationFeed->insert($value);
        }
        echo json_encode(true);
    }
}
?>

 /**
  * test the instantiation of the service request object
  */
 public function testSettingOfServiceRequestInstance()
 {
     $this->assertEquals($this->mockServiceRequest, ServiceRequestFactory::getInstance());
 }
 /**
  * Returns a cell feed of the specified worksheet.
  * 
  * @see \Google\Spreadsheet\Worksheet::getWorksheetId()
  * 
  * @param string $spreadsheetId
  * @param string $worksheetId
  * 
  * @return \Google\Spreadsheet\CellFeed
  */
 public function getCellFeed($spreadsheetId, $worksheetId = 'od6')
 {
     return new CellFeed(ServiceRequestFactory::getInstance()->get('feeds/cells/' . $spreadsheetId . '/' . $worksheetId . '/private/full'));
 }
 /**
  * Fetches a single spreadsheet from google drive by id if you decide
  * to store the id locally. This can help reduce api calls.
  *
  * @param string $id the url of the spreadsheet
  *
  * @return \Google\Spreadsheet\Spreadsheet
  */
 public function getSpreadsheetById($id)
 {
     return new Spreadsheet(new SimpleXMLElement(ServiceRequestFactory::getInstance()->get('feeds/spreadsheets/private/full/' . $id)));
 }
 /**
  * Add a new worksheet to this spreadsheet
  * 
  * @param string $title
  * @param int    $rowCount default is 100
  * @param int    $colCount default is 10
  *
  * @return Worksheet
  */
 public function addWorksheet($title, $rowCount = 100, $colCount = 10)
 {
     $entry = new \SimpleXMLElement("\n            <entry\n                xmlns=\"http://www.w3.org/2005/Atom\"\n                xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">\n            </entry>\n        ");
     $entry->title = $title;
     $entry->addChild("xmlns:gs:rowCount", (int) $rowCount);
     $entry->addChild("xmlns:gs:colCount", (int) $colCount);
     $response = ServiceRequestFactory::getInstance()->post($this->getWorksheetsFeedUrl(), $entry->asXML());
     return new Worksheet(new \SimpleXMLElement($response));
 }
Exemplo n.º 15
0
 /**
  * 
  * @param \Google\Spreadsheet\Batch\BatchRequest $batchRequest
  * 
  * @return \Google\Spreadsheet\Batch\BatchResponse
  */
 public function updateBatch(BatchRequest $batchRequest)
 {
     $xml = $batchRequest->createRequestXml($this);
     $response = ServiceRequestFactory::getInstance()->post($this->getBatchUrl(), $xml);
     return new BatchResponse(new SimpleXMLElement($response));
 }
 /**
  * Get public spreadsheet
  * 
  * @param string $id Only the actual id and not the full url
  * 
  * @return WorksheetFeed
  */
 public function getPublicSpreadsheet($id)
 {
     $serviceRequest = ServiceRequestFactory::getInstance();
     $url = sprintf("%sfeeds/worksheets/%s/public/full", $serviceRequest->getServiceUrl(), $id);
     return $this->getResourceById(WorksheetFeed::class, $url);
 }