can't insert event starting on a defined date into fullCalendar - fullcalendar

I'm working on a codeIgniter project.I use fullCalendar to insert events. The concept that I want to implement is similar to google Calendar. When a user clicks on a day in the calendar, he inserts an event starting on the date of the clicked day.
I did an ajax call from my view and post the date to the controller.Once in the controller, all what I want to do is to set the start date with this value and to insert the event in the calendar. Here is my code (controller)
function add_event()
{
$click_date = $this->input->post('date');
$date= explode(" ", "$click_date ");
$month= (int)$date[1];
$day= (int)$date[2];
$year= (int)$date[3];
$date_start = $this->unix_timestamp($year.'-'.$month.'-'.$day);
$this->load->library('gcal');
$date_end = $this->unix_timestamp('2012-08-15');
$params = array(
'calendarId' => 'my Google calendar id',
'allday' => true,
'start' => $date_start,
'end' => $date_end,
'summary' => 'event',
'description' => "My first event"
);
$response = $this->gcal->eventInsert($params);
if($response)
{
echo "true";
}
}
Here is my unix_timestamp function :
function unix_timestamp($date)
{
$date = str_replace(array(' ', ':'), '-', $date);
$c = explode('-', $date);
$c = array_pad($c, 6, 0);
array_walk($c, 'intval');
return mktime($c[3], $c[4], $c[5], $c[1], $c[2], $c[0]);
}
On the calendar, the event is inserted but not on the right starting date. It starts on 2012-01-01 which is the default date I guess. I don't understand why my starting date isn't set correctly.
What I am doing wrong? Could someone please help me?

I found the answer. I should convert the fullCalendar date format into string before posting it to the controller. One line was missing :
date_format = $.fullCalendar.formatDate(date,"yyyy-MM-dd HH:mm:ss");`
Hope that it would help people who have the same problem
`

Related

Is there any way to remove "next payment date" from a subscription email?

My client wants to remove "the next payment date" from woocommerce email.
Ive been looking for hours for a solution but i didntt find one. Is there any way to manipulate that data?
The basic subscription flow is that you can set your next subscription date like this -
add_action('woocommerce_thankyou', 'update_skip_next_payment_date', 20, 1);
function update_skip_next_payment_date($subscription) {
$date = new DateTime('2024-11-21');
$date->setTime(11, 59);
$subscription_next_payment_date = date_format($date, 'Y-m-d H:i:s'); // = '2021-05-28 08:55:00'
$new_dates = array(
'start' => $subscription->get_date('start'),
'trial_end' => $subscription->get_date('trial_end'),
'next_payment' => $subscription_next_payment_date,
'last_payment' => $subscription->get_date('last_payment'),
'end' => $subscription->get_date('end'),
);
$subscription->update_dates($new_dates);
}
So you can update the next subscription date here and set it next to the next subscription date here.
The reference URL is - How to set Next Payment date in Woocommerce Subscriptions?
The woocommerce subscription reference URL is - https://docs.woocommerce.com/document/subscriptions/develop/functions/#section-4):

google calendar watch notification getting nul

Hi have setup watch on google calendar
$channelID = "my-caledar-". date('His', time());
$channel->setId($channelID);
$channel->setType('web_hook');
$channel->setAddress('xxxxx');
and getting valid params after call this method
and when I create/delete any event on calendar , I am getting null on push notification url
if($_POST){
$msg = json_encode($_POST);
pg_query($pg_conn, "INSERT INTO postdata(post_data) values ('$msg')");
} else {
$result = pg_query($pg_conn, "SELECT * FROM postdata;");
}
$result getting empty filed
Notifiction not comes on url as a POST params , We can get it via $_SERVER variable like this
$msg = json_encode(array('HTTP_X_GOOG_CHANNEL_ID' => $_SERVER['HTTP_X_GOOG_CHANNEL_ID'],
'HTTP_X_GOOG_CHANNEL_EXPIRATION' => $_SERVER['HTTP_X_GOOG_CHANNEL_EXPIRATION'],
'HTTP_X_GOOG_RESOURCE_STATE' => $_SERVER['HTTP_X_GOOG_RESOURCE_STATE'],
'HTTP_X_GOOG_MESSAGE_NUMBER' => $_SERVER['HTTP_X_GOOG_MESSAGE_NUMBER'],
'HTTP_X_GOOG_RESOURCE_ID' => $_SERVER['HTTP_X_GOOG_RESOURCE_ID'],
'HTTP_X_GOOG_RESOURCE_URI' => $_SERVER['HTTP_X_GOOG_RESOURCE_URI']
));

Open a specific day using FullCalendar package

I wonder if someone has already figured my problem out.
I'm using Laravel 5 Full Calendar Helper in order to create a booking app.
What I want to achieve is to render the calendar on an specific day which is the booking date
For example if someone wants to book a room for 12/31/2015, he will be able to see the calendar on that date (day view), before book their room.
So far I got this
ConsultController
<?php
namespace App\Http\Controllers;
use App\Booking;
use App\Http\Requests\BookingRequest;
use App\Room;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
class ConsultController extends Controller
{
public function consult(BookingRequest $request){
// Look for the booking which matches with our search
$seek = Booking::where('room_id','=',$request->room)
->where('day','=',$request->day)
->where('start','=',$request->start)->first();
// If no booking matches, then book
if(is_null($seek)){
$book = $request;
// Get all the bookings on day requested
$bookings = Booking::where('day','=',$request->day)->get();
// creating events for the calendar
$events = [];
foreach($bookings as $booking){
$events[] = \Calendar::event(
''.$booking->room->name, //event title
false, //full day event?
$booking->day->format('Y-m-d').$booking->start, //start time (you can also use Carbon instead of DateTime)
$booking->day->format('Y-m-d').$booking->end, //end time (you can also use Carbon instead of DateTime)
$booking->id //optionally, you can specify an event ID
);
}
$events [] = \Calendar::event(
''.Room::find($book->room)->name, //event title
false,
$book->day.$book->start,
$book->day.$book->end,
0,
[
'backgroundColor' => '#ff5722'
]
);
// Adding event for the calendar
$calendar = \Calendar::addEvents($events);
return view('consult.book')->with(['calendar' => $calendar,'book'=>$book]);
}
// If a record matches then redirect back
else{
Session::flash('flash_message','Lo sentimos ese horario está ocupado');
return redirect()->back();
}
}
}
I have this view
but what I want is this view
Taking a detailed review to the documentation I found out that this helper class has a setOptions method which allows to have more control when rendering the calendar
I just added that method and reached what I was looking for
$calendar = \Calendar::addEvents($events)->setOptions([ 'defaultDate' => $book->day,'defaultView' => 'agendaDay']);

send POST data from calendar to json_events.php

I imagine this is simple but I can't quite get the concept clear.
Basically I am working on loading events on prev/next click
viewDisplay: function(view) { var next = view.title; }, //alert(next);
gives me "November 2012"
split this
then
events: {
url: 'json-events.php',
type: 'POST', <br/>
data: { month: month,
year: year } },
So, how to read the POST val in json-events.php
Assuming I am on the right track here. [super newbie]
use as object reference http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
<?php
//obtain params
$month = $_POST["month"];
$year = $_POST["year"];
//... get the list of events due to month and year
//create an events array due to docs
$events = array(array('id' => 1, 'title' => 'Event', 'allDay' => true));
//return json feed
echo json_encode($events);
?>

Yii update input field with wrong date outputed - where to control it?

The user inserts a date like: 06/11/2012.
To insert into the database I use:
protected function beforeSave ()
{
if($this->date <> '')
{
list($d, $m, $y) = explode('/', $this->date);
$mk=mktime(0, 0, 0, $m, $d, $y);
$this->date = date ('Y-m-d', $mk);
}
return parent::beforeSave ();
}
Question 1) Isn't there a shorter approach ?
Anyway, it works, so I have a date in string format coming from the database date type field:
$date = '2012-11-06'
Then I use date format correctly, and I get the day and the month
yii::app()->dateFormatter->format('dd', $date);
yii::app()->dateFormatter->format('MMMM', $date);
All this seems to work fine.
However, on my update form, I get a date like this:
"20/12/1106"
On the form input field, the date should be converted to:
dd/mm/yyyy
when displayed.
On my model rules here's what I have:
array('date', 'type', 'type' => 'date', 'message' => '{attribute}: Invalid Date!', 'dateFormat' => 'dd/mm/yyyy'),
Where can we control this on Yii, so that on our input field of the date appears as dd/mm/yyyy ?
I've done this, but ofcourse if we later have other controller then update, we have to change this. This seems NOT a good approach. :(
protected function afterFind ()
{
if(Yii::app()->controller->action->id == 'update')
{
if($this->date <> '')
{
Yii::app()->dateFormatter->formatDatetime($this->date,'short');
}
return parent::afterFind ();
}
}
You can do a little workout before rendering the update form. this should work but not tested
in your action Update before $this->render(....);
$model->date = assign your required format here;
but if you need to keep this format you should avoid converting date at every place. Just save date in required format in database directly.

Resources