Anyone know how to get the colorId from google calendar events? I search a lot on web for that and I didn´t find anything that works. I need help.
My code works good but regarding the colorId always receive NULL.
I know we have the $cal->colors->get() method but it's not quite what I want. I want the colors of each the events.
Here is my code:
$client = new Google_Client();
$client->setApplicationName("Ware");
$client->setDeveloperKey('CalendarKey');
$cal = new Google_Service_Calendar($client);
$params = array(
'singleEvents' => true,
'orderBy' => 'startTime'
);
$events = $cal->events->listEvents($calendarId, $params);
$calTimeZone = $events->timeZone;
$events = $cal->events->instances($calendarId, "eventId");
date_default_timezone_set($calTimeZone);
$jsonEvents = json_encode($events->getItems());
$outerArray = array();
$innerArray = array();
foreach ($events->getItems() as $event) {
$date = $event->start->date;
if (!isset($date)) {
$date = $event->start->dateTime;
}
$endDate = $event->end->dateTime;
if (!isset($endDate)) {
$endDate = $event->end->date;
}
$array = array(
"title" => $event->summary,
"description" => $event->description,
"id" => $event->id,
"location" => $event->location,
"start" => $date,
"end" => $endDate,
"colorId" => $event->colorId
);
array_push($outerArray, $array);
}
echo json_encode($outerArray);
The "colorId" => $event->colorId is always NULL.
Public calendar is ON and I have the rights "Make changes and manage sharing".
How can fix that help?
Thanks
Related
I am using the Google API to add rows to a Google Sheet. This is all working well, but the new rows are being added to the end (using the append method).
I would like to insert the row at the top, below the heading, in my case Row 2.
This is my working code for adding to the end. How can I specify where I want to insert the row at a given position.
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $CredentialFile);
$client = new \Google_Client;
$client->useApplicationDefaultCredentials();
$client->setApplicationName("MyApp");
$client->setScopes(['https://www.googleapis.com/auth/drive','https://spreadsheets.google.com/feeds']);
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
$accessToken = $client->fetchAccessTokenWithAssertion()["access_token"];
ServiceRequestFactory::setInstance(new DefaultServiceRequest($accessToken));
$SheetId = "MySheetId";
$service = new \Google_Service_Sheets($client);
$sheet = $service->spreadsheets->get($SheetId);
$sheets = $sheet->getSheets();
$SheetTitle = $sheets[0]->properties->title;
$range = "{$SheetTitle}!A:D";
$values = [];
$row = [];
$row[] = "Tom";
$row[] = "Thumb";
$row[] = "tomthumb";
$row[] = "tom#thumb.com"
$values[] = $row;
$body = new \Google_Service_Sheets_ValueRange([
'values' => $values
]);
$params = [
'valueInputOption' => "RAW"
];
$result = $service->spreadsheets_values->append($SheetId, $range, $body, $params);
You are using values.append which by definition appends values to the first empty row
If you want to insert your values in a range that is not the first empty row of the sheet, you need to use instead the method values.batchUpdate
Sample:
$range="Sheet1!A2:D2";
$values = array(
array(
"Tom", "Thumb", "tomthumb", "tom#thumb.com"
)
);
$data = array();
$data[] = new Google_Service_Sheets_ValueRange(array(
'range' => $range,
'values' => $values
)
);
$body = new Google_Service_Sheets_BatchUpdateValuesRequest(array(
'valueInputOption' => 'RAW',
'data' => $data
)
);
$result = $service->spreadsheets_values->batchUpdate($SheetId, $body);
UPDATE
I you want to insert a row with with data rather than pasting data into an already existing row - you need to create the additional row first.
This can be done with a InsertDimensionRequest.
Sample:
$request = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
'requests' => array(
'insertDimension' => array(
'range' => array(
"startIndex": 1,
"endIndex": 2,
"dimension": "ROWS",
"sheetId": 0
)
)
)
));
$request->setRequests($body);
$result = $service->spreadsheets->batchUpdate($SheetId, $request);
Hello i need serious help cause i have tried all way and not find an answer... so i really want to display chart that count many data each month, ex january 2 data, febuary 3 data etc... pls look at this brother
public function lihatkeluhan(){
$halaman="tindaklayanan";
$keluhan_list=DB::table('keluhans')
->select(DB::raw('id,tanggal,produk,username,area,masalah,status'))->get();
$keluhan_group = keluhan::select(DB::raw('id,tanggal,produk,username,area,masalah,status'))
->get()->groupBy(function($date) {
return Carbon::parse($date->tanggal)->format('m'); // grouping by months
});
foreach ($keluhan_group as $group) {
$count[] = count($group);
}
$bulan = array("Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des");
$count = Count($keluhan_list);
$population = Lava::DataTable();
$population->addDateColumn("Month")
->addNumberColumn('Keluhan');
foreach($keluhan_group as $group){
$population->addRow(["jan",$count]);
}
Lava::LineChart('Population', $population, [
'title' => 'Tahun : 2017',
'titleTextStyle' => [
'color' => '#212F3C',
'fontSize' => 14
]
]);
$keluhan_group used to group by month
$count result is number of data each month
But idk how to display on chart...
Btw $population->addDateColumn("Month") is not work, it not display month but year T_T
Replace your code from $keluhan_group to $population with below code and check.
here you need to pass array of month and count of that month
$keluhan_group = keluhan::select(DB::raw("COUNT(*) as count , MONTHNAME(created_at) as month"))
->orderBy("created_at")
->groupBy(DB::raw("month(created_at)"))
->get()->toArray();
$chart_array = array();
foreach($keluhan_group as $data){
$n_data = [];
array_push($n_data,$data['month'],$data['count']);
array_push($chart_array,$n_data);
}
$population = Lava::DataTable();
$population->addDateColumn("Month")
->addNumberColumn('Keluhan')
->addRow($chart_array);
hope this will Help.
see i have implemented chart using my 'User' tabel,
i was not having lavachart in my project so i have update it using http://itsolutionstuff.com/post/laravel-5-geo-chart-example-and-demo-using-lavacharts-packageexample.html
here is my controller code:
$users = Users::select(DB::raw("COUNT(*) as count , MONTHNAME(created_at) as month"))
->orderBy("created_at")
->groupBy(DB::raw("month(created_at)"))
->get()->toArray();
$chart_array = array();
foreach($users as $data){
$n_data = [];
array_push($n_data,$data['month'],$data['count']);
array_push($chart_array,$n_data);
}
$lava = new Lavacharts;
$popularity = $lava->DataTable();
$popularity->addStringColumn('Country')
->addNumberColumn('Popularity')
->addRows($chart_array);
$lava->LineChart('demochart', $popularity, [
'title' => 'Demo population count',
'animation' => [
'startup' => true,
'easing' => 'inAndOut'
],
'colors' => ['blue', '#F4C1D8']
]);
return view('welcome', ['lava' => $lava]);
and in my .blade file:
<div id="temps_div"></div>
<?= $lava->render('LineChart', 'demochart' , 'temps_div') ?>
Hope this will Help.
$companies=Company::all();
$start = (new DateTime('2017-01-01'))->modify('first day of this month');
$end = (new DateTime('2022-01-01'))->modify('first day of next month');
$interval = DateInterval::createFromDateString('12 month');
$period = new DatePeriod($start, $interval, $end);
$lava = new Lavacharts; // See note below for Laravel
$finances = \Lava::DataTable();
$finances->addDateColumn('Year');
foreach($companies as $company)
{
$finances ->addNumberColumn($company->company_name." ".$company->company_location." total sales amount");
}
foreach ($period as $dt) {
$yeardate=$dt->format("Y-m-d");
$insertrow = array( $yeardate );
foreach($companies as $company)
{
$cmp= $company->company_name;
$loc= $company->company_location;
$companiesinfo[]=$cmp." ".$loc;
$databasename=$company->database_name;
\Config::set('database.connections.tenant.host', 'localhost');
\Config::set('database.connections.tenant.username','root');
\Config::set('database.connections.tenant.password', '');
\Config::set('database.connections.tenant.database', $databasename);
\Config::set('database.default', 'tenant');
DB::reconnect('tenant');
$calculatesalesofcompany=B2CFINAL::
select(DB::raw('sum(GrandTotal) as total'))
->where(DB::raw('YEAR(SaleDate)'), '=', $yeardate)
->first();
if($calculatesalesofcompany->total==null)
{
$calculatesalesofcompany->total=0;
}
array_push( $insertrow, $calculatesalesofcompany->total );
}
$finances ->addRow($insertrow);
}
\Lava::ComboChart('Finances2', $finances2, [
'title' => 'Company Performance',
'titleTextStyle' => [
'color' => 'rgb(123, 65, 89)',
'fontSize' => 16
],
'legend' => [
'position' => 'in'
],
'seriesType' => 'bars',
]);
I have a function for Paypal redirection for that I pass some values in params..
It only pass the Description field doesn't shows the amount to be paid,and rest of my order summaries..
Here is my function
public function postPayment()
{
$hot_id = \Session::get('hot_id');
$user_id = \Session::get('uid');
$check_in = \Session::get('check_in');
$check_out = \Session::get('check_out');
$mem_count = \Session::get('mem_count');
$rm_no = \Session::get('rm_no');
$check_in = strtotime($check_in);
$check_in = date('Y-m-d',$check_in);
$check_out = strtotime($check_out);
$check_out = date('Y-m-d',$check_out);
$datediff = strtotime($check_out) - strtotime($check_in);
$diff = floor($datediff/(86400));
$room_prize = \DB::select("SELECT `room_prize` FROM `abserve_hotel_rooms` WHERE `room_id` = ".$_POST['room_id']);
$arr = array();
foreach ($room_prize as $key => $value) {
$arr[]= (get_object_vars($value));
}
$room_prize = array();
foreach ($arr as $key => $value) {
$room_prize[]=($value['room_prize']);
}
if($rm_no == 1)
{
$room_prize = (int) $room_prize[0] * (int) $diff;
}
else
{
$room_prize = (int) $room_prize[0] * (int) $diff * (int) $rm_no;
}
$room_prize = number_format((float)$room_prize, 2, '.', '');
$room_id = $_POST['room_id'];
$today = new DateTime();
$created_at = $today->format('Y-m-d');
$values = array('user_id' => $user_id,'hotel_id' => $hot_id,'room_id'=>$room_id,'room_prize'=>$room_prize,'check_in'=>$check_in,'check_out'=>$check_out,'created_at'=>$created_at);
\DB::table('abserve_orders')->insert($values);
$order_id = DB::select("SELECT `id` FROM `abserve_orders` WHERE `room_id` = ".$_POST['room_id']." AND `user_id` = ".$user_id);
$arr = array();
foreach ($order_id as $key => $value) {
$arr[]= (get_object_vars($value));
}
$order_id = array();
foreach ($arr as $key => $value) {
$order_id[]=($value['id']);
}
$order_id = $order_id[0];
$params = array(
'cancelUrl' => url().'/cancel_order',
'returnUrl' => url().'/payment_success',
'name' => 'new order',
'description' => 'description1',
'amount' => $room_prize,
'currency' => 'USD',
'hot_id' => $hot_id,
'room_id' => $room_id,
'user_id' => $user_id,
'check_in' => $check_in,
'check_out' => $check_out,
'order_id' => $order_id,
'nights' => $diff,
);
// print_r($params);exit;
\Session::put('params', $params);
\Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('googley555_api1.yahoo.com');
$gateway->setPassword('3EQ6S6PB68A52JKZ');
$gateway->setSignature('AFcWxV21C7fd0v3bYYYRCpSSRl31AHaEiWOLAf5jQQ3-A9hLlhypSz9h');
$gateway->setTestMode(true);
$response = $gateway->purchase($params)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
}
I don't know what are missing in it..
Someone please help me..
You can't pass in arbitrary parameters such as hot_id, room_id, etc to PayPal (or omnipay) because it won't know what to do with them. PayPal is only intended to take certain parameters and the ones that PayPal does not take are ignored by Omnipay.
You may have to provide all of these extra parameters as part of the description parameter, which PayPal does understand.
Ideally these should be displayed by your application in some kind of useful format to the user before redirecting the user to the PayPal checkout page.
If i use an array for a meta value can i see if a value is in the array when querying it? I have a website that has events that has dates attached to it as a meta value and i need to see if an event is on a certain date through a search.
$dates[] = 05/02/2016
$dates[] = 06/02/2016
$dates[] = 06/02/2016
update_post_meta($event, 'show_dates', $dates);
if i add this to an event how could i check if the 'show_dates' contains a date searched for? below is what i have tried already
$wp_query->set('post_status', array('publish', 'future'));
$wp_query->set("meta_key", "show_dates");
$wp_query->set("orderby", "meta_value");
$wp_query->set("order", "ASC");
$startDate = parseDatePicker($_GET['StartDate'], new \DateTime());
if (!is_null($startDate)) {
$wp_query->set("meta_query", array(
array(
'key' => "show_dates",
'value' => $startDate->format("d/m/Y"),
'compare' => 'IN'
)
));
}
Ok so it turns out the answer to this was easier than i expected. As Wordpress serializes the data in the array you can use LIKE instead of IN which will check the serialized array to see if it contains that date.
$wp_query->set('post_status', array('publish', 'future'));
$wp_query->set("meta_key", "show_dates");
$wp_query->set("orderby", "meta_value");
$wp_query->set("order", "ASC");
$startDate = parseDatePicker($_GET['StartDate'], new \DateTime());
if (!is_null($startDate)) {
$wp_query->set("meta_query", array(
array(
'key' => "show_dates",
'value' => $startDate->format("d/m/Y"),
'compare' => 'LIKE'
)
));
}
my next problem was how to work with a range I managed to figure this out and have posted below incase nayone else has a similar problem
if (!is_null($startDate) && !is_null($endDate) && ($startDate->format('d/m/Y') != $endDate->format('d/m/Y'))) {
$wp_query->set("relation", "OR");
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($startDate, $interval, $endDate);
$dates[] = $startDate->format('d/m/Y');
foreach($period as $day){
$dates[] = array(
'key' => "next_showing_date",
'value' => $day->format('d/m/Y'),
'compare' => 'LIKE',
);
}
$wp_query->set("meta_query", $dates);
}
i'm trying to get the best practice to manipulate my array to get a json in a format similar to this one (better to work with charts)
{
"serieMonth":["Aug-12","Sep-12","Oct-12","Nov-12","Dec-12","Jan-13","Feb-13"],
"serieCA":[4214,10119,13325,12818,7177,20628,7664],
"serieAdwordsCA":[0,0,0,0,0,310,332],
"serieBooking":[10,28,46,34,17,51,16],
"serieAdwords":[0,0,0,0,0,1,1],
"serieTotalBooking":[10,28,46,34,17,52,17],
"serieCartRepartition":[421,361,290,377,422,397,451],
"serieTotalCart":[421,361,290,377,422,397,451]
}
Actually my output looks like this :
[
{"date_year":"2012","date_month":"08","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"09","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"10","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"11","ad_cost":"0.0","ad_clicks":"0"},
{"date_year":"2012","date_month":"12","ad_cost":"44.9","ad_clicks":"43"},
{"date_year":"2013","date_month":"01","ad_cost":"297.56","ad_clicks":"462"},
{"date_year":"2013","date_month":"02","ad_cost":"82.5","ad_clicks":"103"}
]
And I'm using javascript to change it :
var xAxisLabels = new Array(),
adClicks = new Array(),
adCost = new Array();
$.each(data, function(i,v) {
xAxisLabels.push(v["date_month"]+'/'+v["date_year"]);
adCost.push(parseInt(v["ad_cost"]));
adClicks.push(parseInt(v["ad_clicks"]));
});
I'm looking for the best way to do it in php since I get this data by the google api, here is my php.
// dimensions
$dimensions = 'ga:year,ga:month';
$_params[] = 'date_year';
$_params[] = 'date_month';
// metrics
$metrics = 'ga:adCost,ga:adClicks';
$_params[] = 'ad_cost';
$_params[] = 'ad_clicks';
$response = $service->data_ga->get('ga:' . $projectId, $from, $to, $metrics, array('dimensions' => $dimensions));
$analyticsStats = array();
foreach ($response['rows'] as $row) {
$dataRow = array();
foreach ($_params as $colNr => $column) {
$dataRow[$column] = $row[$colNr];
}
array_push($analyticsStats, $dataRow);
}
You can build an array of arrays then add items the the sub-arrays in a loop:
$output = array(
"serieMonth" => array(),
"serieCA" => array(),
"serieAdwordsCA" => array(),
"serieBooking" => array(),
"serieAdwords" => array(),
"serieTotalBooking" => array(),
"serieCartRepartition" => array(),
"serieTotalCart" => array()
);
foreach($response["rows"] as $row) {
$output["serieMonth"][] = date("Y-M", strtotime("{$row['date_year']}-{$row['date_month']}-01"));
$output["serieCA"][] = $row["ad_cost"];
$output["serieAdwordsCA"][] = $row["ad_clicks"];
// etc...
}
echo json_encode($output);