setInstance() public static method

Set an instance of ServiceRequestInterface
public static setInstance ( Google\Spreadsheet\ServiceRequestInterface $instance = null )
$instance Google\Spreadsheet\ServiceRequestInterface
Ejemplo n.º 1
0
 /**
  * @param GoogleDriveAuth @auth
  */
 private function authenticate(GoogleDriveAuth $auth)
 {
     $token = json_decode($auth->auth()->getAccessToken());
     $accessToken = $token->access_token;
     $serviceRequest = new DefaultServiceRequest($accessToken);
     ServiceRequestFactory::setInstance($serviceRequest);
 }
 public function testInsert()
 {
     $mockServiceRequest = $this->getMockBuilder("Google\\Spreadsheet\\DefaultServiceRequest")->setMethods(array("post"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method("post")->with($this->equalTo("https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full"), $this->stringContains("<gsx:occupation>software engineer</gsx:occupation>"));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $this->listFeed->insert(["name" => "asim", "occupation" => "software engineer"]);
 }
Ejemplo n.º 3
0
 /**
  *
  * @param string $format
  */
 public function write(Table $table, OutputInterface $output)
 {
     $serviceRequest = new DefaultServiceRequest();
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new SpreadsheetService();
     $spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();
 }
 public function testUpdate()
 {
     $mockRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(["post"])->disableOriginalConstructor()->getMock();
     $mockRequest->expects($this->once())->method("post")->with($this->equalTo("https://spreadsheets.google.com/feeds/cells/15L06yklgflGRDjnN-VvhGYOoVLCH40DJoW5fFiqSTc5U/od6/private/full"), $this->stringContains("MyVal"))->willReturn("<entry/>");
     ServiceRequestFactory::setInstance($mockRequest);
     $this->cellEntry->update("MyVal");
 }
 public function testInsert()
 {
     $mockServiceRequest = $this->getMockBuilder('Google\\Spreadsheet\\DefaultServiceRequest')->setMethods(array("post"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method('post')->with($this->equalTo('https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'), $this->stringContains('<gsx:occupation><![CDATA[software engineer]]></gsx:occupation>'));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $listFeed = new ListFeed(file_get_contents(__DIR__ . '/xml/list-feed.xml'));
     $listFeed->insert(["name" => "asim", "occupation" => "software engineer"]);
 }
 public function testDelete()
 {
     $mockServiceRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(["delete"])->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method("delete")->with($this->equalTo("https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cokwr/bnkj8i7jo6c"));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $listFeed = new ListFeed($this->getSimpleXMLElement("list-feed"));
     $entry = current($listFeed->getEntries());
     $entry->delete();
 }
/**
 * Returns a list feed of the specified worksheet.
 * 
 * @param string $accessToken Google Auth Access Token
 * @param string $sheetTitle  title of spreadsheet
 * 
 * @return object $result
 */
function getSpreadsheet($accessToken, $sheetTitle)
{
    $serviceRequest = new DefaultServiceRequest($accessToken);
    ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
    $result = $spreadsheetFeed->getByTitle($sheetTitle);
    return $result;
}
 public function testGetListFeedWithQuery()
 {
     $feedUrl = "https://spreadsheets.google.com/feeds/list/tA3TdJ0RIVEem3xQZhG2Ceg/od8/private/full?reverse=true&sq=age+%3E+45";
     $mockServiceRequest = $this->getMockBuilder('Google\\Spreadsheet\\DefaultServiceRequest')->setMethods(array("get"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method('get')->with($this->equalTo($feedUrl))->willReturn(file_get_contents(__DIR__ . '/xml/list-feed.xml'));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $worksheet = new Worksheet(new SimpleXMLElement(file_get_contents(__DIR__ . '/xml/worksheet.xml')));
     $worksheet->getListFeed(array("reverse" => "true", "sq" => "age > 45"));
 }
 /**
  * @expectedException Google\Spreadsheet\Exception\ResourceNotFoundException
  */
 public function testGetResourceByIdException()
 {
     $resourceId = "http://resource";
     $mockRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(["get"])->disableOriginalConstructor()->getMock();
     $mockRequest->expects($this->once())->method("get")->with($this->equalTo($resourceId))->will($this->throwException(new BadRequestException()));
     ServiceRequestFactory::setInstance($mockRequest);
     $spreadsheetService = new SpreadsheetService();
     $spreadsheet = $spreadsheetService->getResourceById(Spreadsheet::class, $resourceId);
 }
Ejemplo n.º 10
0
 protected function setServiceRequest($return, $simpleXml = false)
 {
     $serviceRequest = new TestServiceRequest(new Request('accesstoken'));
     $xml = file_get_contents(__DIR__ . '/xml/' . $return);
     if ($simpleXml) {
         $xml = new SimpleXMLElement($xml);
     }
     $serviceRequest->setExecuteReturn($xml);
     ServiceRequestFactory::setInstance($serviceRequest);
 }
 /**
  * @return \Google\Spreadsheet\SpreadsheetFeed
  */
 public static function getSpreadsheetFeed()
 {
     if (isset(static::$spreadsheetFeed)) {
         return static::$spreadsheetFeed;
     }
     $token = static::getToken();
     $serviceRequest = new \Google\Spreadsheet\DefaultServiceRequest($token['access_token']);
     \Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new \Google\Spreadsheet\SpreadsheetService();
     return static::$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
 }
 public function testUpdate()
 {
     $mockServiceRequest = $this->getMockBuilder('Google\\Spreadsheet\\DefaultServiceRequest')->setMethods(array("put"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method('put')->with($this->equalTo('https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full/cokwr/bnkj8i7jo6c'), $this->stringContains('<gsx:nname><![CDATA[Asim]]></gsx:nname>'));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $listFeed = new ListFeed(file_get_contents(__DIR__ . '/xml/list-feed.xml'));
     $entry = current($listFeed->getEntries());
     $data = $entry->getValues();
     $data["nname"] = "Asim";
     $entry->update($data);
 }
 public function testInsertBatch()
 {
     $mockBatchRequest = $this->getMockBuilder(BatchRequest::class)->setMethods(["createRequestXml"])->disableOriginalConstructor()->getMock();
     $mockBatchRequest->expects($this->once())->method("createRequestXml")->will($this->returnValue(new \SimpleXMLElement("<batch/>")));
     $mockCellFeed = $this->getMockBuilder(CellFeed::class)->setMethods(["getBatchUrl"])->disableOriginalConstructor()->getMock();
     $mockCellFeed->expects($this->once())->method("getBatchUrl")->will($this->returnValue("https://spreadsheets.google.com/"));
     $mockServiceRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(array("post"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method("post")->with($this->equalTo("https://spreadsheets.google.com/"), $this->stringContains("<batch/>"))->will($this->returnValue("<response/>"));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $this->assertTrue($mockCellFeed->insertBatch($mockBatchRequest) instanceof BatchResponse);
 }
Ejemplo n.º 14
0
 public function addEntry($lead)
 {
     $serviceRequest = new DefaultServiceRequest($this->token);
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new SpreadsheetService();
     $spreadsheetFeed = $spreadsheetService->getSpreadsheetById($this->spreadsheetId);
     $worksheetFeed = $spreadsheetFeed->getWorksheets();
     $worksheet = $worksheetFeed->getByTitle($this->tabTitle);
     $listFeed = $worksheet->getListFeed();
     $result = $listFeed->insert($lead);
     return $result;
 }
 function __construct($ssName)
 {
     parent::__construct();
     // Accessing the data from the Spreadsheet
     $serviceRequest = new DefaultServiceRequest($this->accessToken);
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
     $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
     $this->spreadsheet = $spreadsheetFeed->getByTitle($ssName);
     // dd($this->spreadsheet);
     $worksheetFeed = $this->spreadsheet->getWorksheets();
     // dd($worksheetFeed);
     // foreach ($worksheetFeed as $key => $value) {
     // 	d($key, $value);
     // }
     // die();
     $worksheet = $worksheetFeed->getByTitle('Sheet1');
     // dd($worksheet);
     $this->listFeed = $worksheet->getListFeed();
     // dd($listFeed);
 }
Ejemplo n.º 16
0
 static function getWorksheet()
 {
     if (empty(self::$worksheet)) {
         $config = json_decode(file_get_contents("EG Robotics-581b91515ac6.json"));
         $user_to_impersonate = '*****@*****.**';
         $scopes = ["https://www.googleapis.com/auth/drive", "https://spreadsheets.google.com/feeds"];
         $credentials = new Google_Auth_AssertionCredentials($config->client_email, $scopes, $config->private_key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $user_to_impersonate);
         $client = new Google_Client();
         $client->setAssertionCredentials($credentials);
         if ($client->getAuth()->isAccessTokenExpired()) {
             $client->getAuth()->refreshTokenWithAssertion();
         }
         $accessToken = json_decode($client->getAuth()->getAccessToken())->access_token;
         $serviceRequest = new DefaultServiceRequest($accessToken);
         ServiceRequestFactory::setInstance($serviceRequest);
         $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
         $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
         $spreadsheet = $spreadsheetFeed->getByTitle('Employee Hour Tracking Payroll');
         $workSheetFeed = $spreadsheet->getWorksheets();
         self::$worksheet = $workSheetFeed->getByTitle("Office Hours");
         self::$archive_worksheet = $workSheetFeed->getByTitle("15-16 OH");
     }
     return self::$worksheet;
 }
Ejemplo n.º 17
0
 private function getClient()
 {
     if (!$this->client) {
         $credentials = new \Google_Auth_AssertionCredentials('*****@*****.**', array('https://www.googleapis.com/auth/drive', 'https://spreadsheets.google.com/feeds'), file_get_contents('/var/www/uwfsae-71f09e98c3c3.p12'));
         $this->client = new \Google_Client();
         $this->client->setApplicationName('application');
         $this->client->setClientId('105516445691427424805');
         $this->client->setAssertionCredentials($credentials);
         if ($this->client->getAuth()->isAccessTokenExpired()) {
             $this->client->getAuth()->refreshTokenWithAssertion();
         }
         $accessToken = json_decode($this->client->getAccessToken())->access_token;
         // for spreadsheet API
         $serviceRequest = new \Google\Spreadsheet\DefaultServiceRequest($accessToken);
         \Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
     }
     return $this->client;
 }
 public static function getEvents($user, $widget)
 {
     switch ($widget->widget_type) {
         case 'google-spreadsheet-line-cell':
             Log::info("google-spreadsheet-line-cell - widget_id - " . $widget['id']);
             $widget_source = json_decode($widget['widget_source'], true);
             $spreadsheetId = $widget_source['googleSpreadsheetId'];
             $worksheetName = $widget_source['googleWorksheetName'];
             # setup Google stuff
             $client = GooglespreadsheetHelper::setGoogleClient();
             $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user);
             # init service
             $serviceRequest = new DefaultServiceRequest($access_token);
             ServiceRequestFactory::setInstance($serviceRequest);
             $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
             # get spreadsheet
             $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId);
             $worksheetFeed = $spreadsheet->getWorksheets();
             # get worksheet
             $worksheet = $worksheetFeed->getByTitle($worksheetName);
             $listFeed = $worksheet->getListFeed();
             # get celldata (first line = header, second line = content)
             $listArray = array();
             $values = array();
             foreach ($listFeed->getEntries() as $entry) {
                 $values = $entry->getValues();
                 break;
                 # break, so we just the first line
             }
             $time = time();
             $data = new Data();
             $data->widget_id = $widget['id'];
             $data->data_object = json_encode($values);
             $data->date = date("Y-m-d", $time);
             $data->timestamp = date('Y-m-d H:i:s', $time);
             $data->save();
             $widget->widget_ready = true;
             $widget->save();
             break;
             # / case 'google-spreadsheet-line-cell'
         # / case 'google-spreadsheet-line-cell'
         case 'google-spreadsheet-line-column':
             Log::info("google-spreadsheet-line-column - widget_id - " . $widget['id']);
             $widget_source = json_decode($widget['widget_source'], true);
             $spreadsheetId = $widget_source['googleSpreadsheetId'];
             $worksheetName = $widget_source['googleWorksheetName'];
             # setup Google stuff
             $client = GooglespreadsheetHelper::setGoogleClient();
             $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user);
             # init service
             $serviceRequest = new DefaultServiceRequest($access_token);
             ServiceRequestFactory::setInstance($serviceRequest);
             $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
             # get spreadsheet
             $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId);
             $worksheetFeed = $spreadsheet->getWorksheets();
             # get worksheet
             $worksheet = $worksheetFeed->getByTitle($worksheetName);
             # get feeddata (first line = header)
             $listFeed = $worksheet->getListFeed();
             foreach ($listFeed->getEntries() as $entry) {
                 $array = $entry->getValues();
                 $date = array_values($array)[0];
                 $value = array_values($array)[1];
                 # format date (from almost everything to Y-m-d)
                 $time = strtotime(trim(str_replace('.', '-', $date), '-'));
                 # have we saved data for this date?
                 $db_data = Data::where('widget_id', '=', $widget['id'])->where('date', '=', date("Y-m-d", $time));
                 if ($db_data->count() == 0) {
                     # nope, save it
                     $data = new Data();
                     $data->widget_id = $widget['id'];
                     $data->data_object = json_encode(array("value" => $value));
                     $data->date = date("Y-m-d", $time);
                     $data->timestamp = date('Y-m-d H:i:s', $time);
                     $data->save();
                 } else {
                     # yes, update it
                     $db_data->update(['data_object' => json_encode(array("value" => $value))]);
                 }
             }
             $widget->widget_ready = true;
             $widget->save();
             break;
             # / case 'google-spreadsheet-line-column'
         # / case 'google-spreadsheet-line-column'
         case 'google-spreadsheet-text-cell':
             Log::info("google-spreadsheet-text-cell - widget_id - " . $widget['id']);
             $widget_source = json_decode($widget['widget_source'], true);
             $spreadsheetId = $widget_source['googleSpreadsheetId'];
             $worksheetName = $widget_source['googleWorksheetName'];
             # setup Google stuff
             $client = GooglespreadsheetHelper::setGoogleClient();
             $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user);
             # init service
             $serviceRequest = new DefaultServiceRequest($access_token);
             ServiceRequestFactory::setInstance($serviceRequest);
             $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
             # get spreadsheet
             $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId);
             $worksheetFeed = $spreadsheet->getWorksheets();
             # get worksheet
             $worksheet = $worksheetFeed->getByTitle($worksheetName);
             # get feeddata (first line = header)
             $listFeed = $worksheet->getListFeed();
             foreach ($listFeed->getEntries() as $entry) {
                 $array = $entry->getValues();
                 $value = array_values($array)[0];
                 $time = time();
                 # have we saved data for this widget?
                 $db_data = Data::where('widget_id', '=', $widget['id']);
                 if ($db_data->count() == 0) {
                     # nope, save it
                     $data = new Data();
                     $data->widget_id = $widget['id'];
                     $data->data_object = json_encode(array("value" => $value));
                     $data->date = date("Y-m-d", $time);
                     $data->timestamp = date('Y-m-d H:i:s', $time);
                     $data->save();
                 } else {
                     # yes, update it
                     $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time)]);
                 }
                 break;
                 # just the first line
             }
             $widget->widget_ready = true;
             $widget->save();
             break;
             # / case 'google-spreadsheet-text-cell'
         # / case 'google-spreadsheet-text-cell'
         case 'google-spreadsheet-text-column':
             Log::info("google-spreadsheet-text-column - widget_id - " . $widget['id']);
             $widget_source = json_decode($widget['widget_source'], true);
             $spreadsheetId = $widget_source['googleSpreadsheetId'];
             $worksheetName = $widget_source['googleWorksheetName'];
             # setup Google stuff
             $client = GooglespreadsheetHelper::setGoogleClient();
             $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user);
             # init service
             $serviceRequest = new DefaultServiceRequest($access_token);
             ServiceRequestFactory::setInstance($serviceRequest);
             $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
             # get spreadsheet
             $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId);
             $worksheetFeed = $spreadsheet->getWorksheets();
             # get worksheet
             $worksheet = $worksheetFeed->getByTitle($worksheetName);
             # get feeddata (first line = header)
             $listFeed = $worksheet->getListFeed();
             foreach ($listFeed->getEntries() as $entry) {
                 $array = $entry->getValues();
                 $value = array_values($array)[0];
                 $time = time();
                 # have we saved data for this widget?
                 $db_data = Data::where('widget_id', '=', $widget['id']);
                 if ($db_data->count() == 0) {
                     # nope, save it
                     $data = new Data();
                     $data->widget_id = $widget['id'];
                     $data->data_object = json_encode(array("value" => $value));
                     $data->date = date("Y-m-d", $time);
                     $data->timestamp = date('Y-m-d H:i:s', $time);
                     $data->save();
                 } else {
                     # yes, update it
                     $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time)]);
                 }
             }
             $widget->widget_ready = true;
             $widget->save();
             break;
             # / case 'google-spreadsheet-text-column'
         # / case 'google-spreadsheet-text-column'
         case 'google-spreadsheet-text-column-random':
             Log::info("google-spreadsheet-text-column-random - widget_id - " . $widget['id']);
             $widget_source = json_decode($widget['widget_source'], true);
             $spreadsheetId = $widget_source['googleSpreadsheetId'];
             $worksheetName = $widget_source['googleWorksheetName'];
             # setup Google stuff
             $client = GooglespreadsheetHelper::setGoogleClient();
             $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user);
             # init service
             $serviceRequest = new DefaultServiceRequest($access_token);
             ServiceRequestFactory::setInstance($serviceRequest);
             $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
             # get spreadsheet
             $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId);
             $worksheetFeed = $spreadsheet->getWorksheets();
             # get worksheet
             $worksheet = $worksheetFeed->getByTitle($worksheetName);
             # get feeddata (first line = header)
             $listFeed = $worksheet->getListFeed();
             $key = 0;
             foreach ($listFeed->getEntries() as $entry) {
                 $array = $entry->getValues();
                 $value = array_values($array)[0];
                 $time = time();
                 # have we saved data for this widget?
                 $db_data = Data::where('widget_id', '=', $widget['id'])->where('data_key', '=', $key);
                 if ($db_data->count() == 0) {
                     # nope, save it
                     $data = new Data();
                     $data->widget_id = $widget['id'];
                     $data->data_key = $key;
                     $data->data_object = json_encode(array("value" => $value));
                     $data->date = date("Y-m-d", $time);
                     $data->timestamp = date('Y-m-d H:i:s', $time);
                     $data->save();
                     $key++;
                 } else {
                     # yes, update it
                     $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time), 'data_key' => $key]);
                 }
             }
             $widget->widget_ready = true;
             $widget->save();
             break;
             # / case 'google-spreadsheet-text-column-random'
     }
     # / switch ($widget_type)
 }
 /**
  * @param string $accessToken The access token
  * @param string $spreadsheetTitle The exact title of the spreadsheet
  * @return null|\Google\Spreadsheet\WorksheetFeed
  */
 protected function getWorksheets($accessToken, $spreadsheetTitle)
 {
     $serviceRequest = new \Google\Spreadsheet\DefaultServiceRequest($accessToken);
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new \Google\Spreadsheet\SpreadsheetService();
     $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
     $spreadsheet = $spreadsheetFeed->getByTitle($spreadsheetTitle);
     if (!$spreadsheet || $spreadsheet === null) {
         return null;
     }
     $worksheetFeed = $spreadsheet->getWorksheets();
     return $worksheetFeed;
 }
Ejemplo n.º 20
0
function submit_reg_form()
{
    //ReCaptcha
    $recaptcha = new ReCaptcha(RECAPTCHA_SECRET);
    $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
    if (!$resp->isSuccess()) {
        throw new Exception('Invalid captcha!');
    }
    //Get & Process form data
    $valid_inputs = 'name|email|tel|inst|std|day1|day2';
    foreach (get_presentations() as $key => $data) {
        $valid_inputs .= "|{$key}";
    }
    $form_data = getInputsWithKey($valid_inputs);
    //----Pricing
    //Count days
    $days = 0;
    for ($i = 1; $i <= 2; $i++) {
        if ($form_data["day{$i}"] != 'no') {
            $days++;
        }
    }
    $price = $days * 35;
    //    if ($days > 1)
    //        $price -= 10;
    //Discount
    $discount_rate = 0;
    if (isset($form_data['std'])) {
        switch ($form_data['std']) {
            case 'aut':
                $discount_rate = 0.6;
                break;
            case 'std':
                $discount_rate = 0.25;
                break;
        }
    }
    $price *= 1.0 - $discount_rate;
    $price = round($price);
    $form_data['price'] = $price;
    //Tel
    $form_data['tel'] = intval($form_data['tel']);
    //Generate tracking code
    $hashids = new Hashids\Hashids(HASHID_SALT);
    $tracking_code = $hashids->encode(time() . rand(0, 100));
    $form_data['code'] = $tracking_code;
    //Check Google Client Expired
    $token = json_decode(gapi_token, true);
    $client = new Google_Client();
    $client->setClientId(GAPI_CLIENT_ID);
    $client->setClientSecret(GAPI_CLIENT_SECRET);
    $client->setAccessToken(gapi_token);
    if ($client->isAccessTokenExpired()) {
        //Refresh on expire
        $client->refreshToken($client->getRefreshToken());
        foreach (json_decode($client->getAccessToken(), true) as $k => $v) {
            $token[$k] = $v;
        }
        file_put_contents(GAPI_TOKEN_LOCATION, "<?php define('gapi_token','" . json_encode($token) . "');");
    }
    //Get Registration sheet
    $serviceRequest = new DefaultServiceRequest($token['access_token']);
    ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $sheet = $spreadsheetService->getSpreadsheets()->getByTitle('linuxfest_2015')->getWorksheets()->getByTitle('List');
    //Insert Submitted data
    $sheet->getListFeed()->insert($form_data);
    //Message
    $msg = "\n<div dir='rtl'>\n\n       با تشکر، ثبت نام آنلاین شما با موفقیت انجام شد و مورد بررسی قرار خواهد گرفت.\n        <br>\n        هزینه ی ثبت نام شما : <b>{$price}</b> هزار تومان\n                <br>\n        کد رهگیری شما : <b>{$tracking_code}</b>\n        (این کد را برای مراحل بعدی حتما نگهدارید)<br>\n        <br>\n                لطفا در اسرع وقت با مراجعه‌ی حضوری به دفتر انجمن علمی دانشکده هزینه‌ی دوره‌هایی را که در آن‌ها ثبت نام کرده‌اید پرداخت نمایید. در صورتی که مراجعه‌ی حضوری برایتان مقدور نیست هزینه‌ی ثبت نام را به کارت 5022291100266525 (بانک پاسارگاد به نام آرمین باشی‌زاده) واریز نمایید و کد رهگیری و شماره کارت خود را به آدرس hello@linuxfest.ir ارسال کنید. به دلیل محدود بودن ظرفیت کارگاه‌ها، اولویت با کسانی است که زودتر ثبت نام خود را نهایی کنند.\n<br>\nتهران، چهارراه ولی عصر، روبه‌روی خیابان بزرگمهر، دانشگاه صنعتی امیرکبیر ، دانشکده مهندسی کامپیوتر و فناوری اطلاعات ، دفتر انجمن علمی\n\t<br>\n     در صورت تمایل به ایجاد هرگونه تغییر در وضعیت ثبت نام خود از ثبت نام مجدد <b> جدا خودداری فرمایید</b>. در غیر این صورت ثبت نام شما تایید نخواهد شد.<br>\n      می‌توانید این تغییرات را از دو طریق ایمیل جشنواره hello@linuxfest.ir یا مراجعه‌ی حضوری اعلام فرمایید.\n\n</div>\n    ";
    $msg_2 = "جشنواره لینوکس امیرکبیر\n    هزینه ی ثبت نام : {$price} هزار تومان\n    کد رهگیری شما : {$tracking_code}\n    جهت ثبت نام نهایی در اسرع وقت به دفتر انجمن علمی دانشکده مراجعه فرمایید\n    ";
    //Email
    if (isset($form_data['email'])) {
        sendmail($form_data['email'], $msg);
    }
    //SMS
    if (isset($form_data['tel'])) {
        sendsms($form_data['tel'], $msg_2);
    }
    return $msg;
}
Ejemplo n.º 21
0
    $client->setClientId(GOOGLE_CLIENT_ID);
    $key = file_get_contents(GOOGLE_KEY_FILE);
    $cred = new Google_Auth_AssertionCredentials(GOOGLE_CLIENT_EMAIL, array(GOOGLE_SPREADSHEETS_SCOPE), $key);
    $client->setAssertionCredentials($cred);
    if ($client->getAuth()->isAccessTokenExpired()) {
        $client->getAuth()->refreshTokenWithAssertion($cred);
    }
    $service_token = json_decode($client->getAccessToken());
    return $service_token->access_token;
}
require '../vendor/autoload.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
$_SESSION['access_token'] = getToken();
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($_SESSION['access_token']);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle('planilha_teste');
$worksheetFeed = $spreadsheet->getWorksheets();
$worksheet = $worksheetFeed->getByTitle('Sheet1');
$listFeed = $worksheet->getListFeed();
foreach ($listFeed->getEntries() as $entry) {
    $values = $entry->getValues();
}
var_dump($values);
// $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
// $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
// $spreadsheet = $spreadsheetFeed->getByTitle('planilha_teste');
// $worksheetFeed = $spreadsheet->getWorksheets();
// $worksheet = $worksheetFeed->getByTitle('Sheet1');
 public function __construct($accessToken)
 {
     $serviceRequest = new DefaultServiceRequest($accessToken);
     ServiceRequestFactory::setInstance($serviceRequest);
     $this->client = new SpreadsheetService();
 }
<?php

session_start();
/**
 * Created by PhpStorm.
 * User: hungnguyen
 * Date: 02/03/16
 * Time: 4:06 PM
 */
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../GoogleSheet.php';
require_once __DIR__ . '/../Config.php';
$feedTitle = $_GET['feedTitle'];
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
use Lib\Common;
$serviceRequest = new DefaultServiceRequest(Common::getGoogleTokenFromKeyFile());
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle($feedTitle);
$worksheetFeed = $spreadsheet->getWorksheets();
foreach ($worksheetFeed as $key => $value) {
    $sheet[] = $worksheetFeed[$key]->getTitle();
}
echo json_encode($sheet);
 /**
  * @param OAuth2ServiceRequest $oAuth2ServiceRequest
  */
 public function __construct(OAuth2ServiceRequest $oAuth2ServiceRequest)
 {
     ServiceRequestFactory::setInstance($oAuth2ServiceRequest);
 }
 /**
  * @expectedException Exception
  */
 public function testGetInstanceException()
 {
     ServiceRequestFactory::setInstance(null);
     ServiceRequestFactory::getInstance();
 }
Ejemplo n.º 26
0
 public function sheet_service()
 {
     $serviceRequest = new DefaultServiceRequest($this->get_token());
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
     return $spreadsheetService;
 }
Ejemplo n.º 27
0
 private function google_connect($key, $spreadsheet, $worksheet)
 {
     //Get access token from DB using $key
     $accessToken = $this->get_key($key);
     $serviceRequest = new DefaultServiceRequest($accessToken);
     ServiceRequestFactory::setInstance($serviceRequest);
     $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
     $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
     $spreadsheet = $spreadsheetFeed->getByTitle(urldecode($spreadsheet));
     $worksheetFeed = $spreadsheet->getWorksheets();
     $worksheet = $worksheetFeed->getByTitle(urldecode($worksheet));
     return $worksheet;
 }
 /**
  * Single worksheet
  */
 public function singleWorksheet(Request $request, $spreadsheet_id, $id)
 {
     $access_token = $request->session()->get('access_token');
     $serviceRequest = new DefaultServiceRequest($access_token);
     ServiceRequestFactory::setInstance($serviceRequest);
     //retrieve list of worksheets
     $spreadsheetService = new SpreadsheetService();
     $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheet_id);
     $data['spreadsheet_title'] = $spreadsheet->getTitle();
     $data['spreadsheet_id'] = $spreadsheet_id;
     $worksheets = $spreadsheet->getWorksheets();
     $i = $id - 1;
     $worksheet = $worksheets[$i];
     $data['worksheet_title'] = $worksheet->getTitle();
     //get content
     $listFeed = $worksheet->getListFeed();
     $entries = $listFeed->getEntries();
     //get column names
     $column_names = array();
     foreach ($entries as $entry) {
         $keys = array_keys($entry->getValues());
         foreach ($keys as $key) {
             if (!in_array($key, $column_names)) {
                 $column_names[] = $key;
             }
         }
     }
     //column names in 'create table' string format
     $formatted_names = "";
     foreach ($column_names as $column_name) {
         $column_name = str_replace(".", "_", $column_name);
         $formatted_names .= " `{$column_name}` TEXT NULL,";
     }
     //generate table name
     $table_name = $this->generateRandomString();
     $sql = "CREATE TABLE `{$table_name}` ( `id` INT NOT NULL AUTO_INCREMENT ,{$formatted_names} PRIMARY KEY (`id`))";
     if (DB::statement($sql)) {
         /*//insert values
                     foreach ($entries as $entry) {
         
                         DB::table($table_name)->insert($entry->getValues());
                     }*/
         foreach ($entries as $entry) {
             $insert_kv = array();
             foreach ($entry->getValues() as $k => $v) {
                 $k = str_replace(".", "_", $k);
                 $insert_kv[$k] = $v;
             }
             DB::table($table_name)->insert($insert_kv);
         }
     }
     $data['table'] = $table_name;
     return View::make('add_tracker_details')->with("data", $data);
 }
 public function testDelete()
 {
     $mockRequest = $this->getMockBuilder(DefaultServiceRequest::class)->setMethods(["delete"])->disableOriginalConstructor()->getMock();
     $mockRequest->expects($this->once())->method("delete")->with($this->equalTo("https://spreadsheets.google.com/feeds/worksheets/tA3TdJ0RIVEem3xQZhG2Ceg/private/full/od8/0"));
     ServiceRequestFactory::setInstance($mockRequest);
     $this->worksheet->delete();
 }
Ejemplo n.º 30
0
 public function __construct(Helper $helper, $sheet_name = null, $worksheet_name = null, $sheet_destination = null)
 {
     parent::__construct($helper);
     # init sheet name
     isset($sheet_name) or $sheet_name = $this->h->_client_app_name;
     $this->sheet_name = $sheet_name;
     # init worksheet name
     isset($worksheet_name) or $worksheet_name = 'Sheet1';
     $this->worksheet_name = $worksheet_name;
     # init spreadsheet service
     $service_request = new \Google\Spreadsheet\DefaultServiceRequest($this->h->current_token->access_token, 'Bearer');
     \Google\Spreadsheet\ServiceRequestFactory::setInstance($service_request);
     $this->service = new \Google\Spreadsheet\SpreadsheetService();
 }