Issue with Background Events FullCalendar from php script JSON string - php

I'm trying to include a list of holidays as Background Events from a separate event source. "holidays.php" is one of my event sources. In month view, when I reach one of the holidays dates, there is no background event and my other events from different sources disappear! When I comment out "holidays.php" as an event source, there is no issues with other events. I'm guessing there's an issue with my json string?
holidays.php
<?php
$record[0]["title"]="Halloween Holiday";
$record[1]["title"]="Birthday";
$record[2]["title"]="December Day!";
$record[0]["date"]="2016-10-31T09:00:00";
$record[1]["date"]="2016-11-23T09:00:00";
$record[2]["date"]="2016-12-01T09:00:00";
for ($i=0; $i<3; $i++) {
$event_array[] = array(
'title' => $record[$i]['title'],
'start' => $record[$i]['date'],
'rendering' => 'background',
'allDay' => false
);
}
echo json_encode($event_array);
exit;
?>
JSON string from holidays.php
[{
"title": "Halloween Holiday",
"start": "2016-10-31T09:00:00",
"rendering": "background",
"allDay": false
}, {
"title": "Birthday",
"start": "2016-11-23T09:00:00",
"rendering": "background",
"allDay": false
}, {
"title": "December Day!",
"start": "2016-12-01T09:00:00",
"rendering": "background",
"allDay": false
}]

You can only have an event with no end date if "allDay" is true.
If you want an event to run all day, then either
a) remove the time element from the start date and set allDay: true, OR
b) If the event genuinely starts at 09:00, as you've put in the data, then you'll need to add a corresponding end date before it will work. Note though that "background" events where allDay : false is set will not show up in the "Month" view, only in the week and day views.
Also, if you're still using the eventRender functionality from your previous question, any events with no end date will probably cause it to crash, because it checks every event and tries to use the "end" property in the calculation.

Related

Should I create new smaller array from decoded JSON or use the whole JSON array as is?

My API call returns a pretty big JSON result and my initial thought was to parse out the two pieces of data I need for each event and create my own array. Does it make more sense to pass around the returned JSON or clean it up for my use throughout the application.
Which is more efficient?
Below is an example of one "Event" each result may have 20-50 events in the data. All I need is the ['resultsPage']['results']['event']['location']['lng'] and ['resultsPage']['results']['event']['location']['lat']:
{
"resultsPage": {
"results": {
"event": [
{
"id":11129128,
"type":"Concert",
"uri":"http://www.songkick.com/concerts/11129128-wild-flag-at-fillmore?utm_source=PARTNER_ID&utm_medium=partner",
"displayName":"Wild Flag at The Fillmore (April 18, 2012)",
"start": {
"time":"20:00:00",
"date":"2012-04-18",
"datetime":"2012-04-18T20:00:00-0800"
},
"performance": [
{
"artist": {
"id":29835,
"uri":"http://www.songkick.com/artists/29835-wild-flag?utm_source=PARTNER_ID&utm_medium=partner",
"displayName":"Wild Flag",
"identifier": []
},
"id":21579303,
"displayName":"Wild Flag",
"billingIndex":1,
"billing":"headline"
}
],
"location": {
"city":"San Francisco, CA, US",
"lng":-122.4332937,
"lat":37.7842398
},
"venue": {
"id":6239,
"displayName":"The Fillmore",
"uri":"http://www.songkick.com/venues/6239-fillmore?utm_source=PARTNER_ID&utm_medium=partner",
"lng":-122.4332937,
"lat":37.7842398,
"metroArea": {
"id":26330,
"uri":"http://www.songkick.com/metro_areas/26330-us-sf-bay-area?utm_source=PARTNER_ID&utm_medium=partner",
"displayName":"SF Bay Area",
"country": { "displayName":"US" },
"state": { "displayName":"CA" }
}
},
"status":"ok",
"popularity":0.012763
}, ....
]
},
"totalEntries":24,
"perPage":50,
"page":1,
"status":"ok"
}
}
My subjective answer is to just use the entire response in your application, grabbing only what you need when you need it. Taking the time to extract only the data you need might be an unnecessary optimization, and your time could be better spent elsewhere.
Optimize only what you measure. If you can measure your application execution time, perhaps with the help of a profiler, like this one with Xdebug, then you can use data to make an informed decision to optimize in this way. My guess is that your application could use optimizations elsewhere before you make this one, but again, without data, it's just a guess.

Elasticsearch query date sorting parent-child relation (recurring events)

I’m currently working on an app where we are handling events.
So, in Elasticsearch, we do have a document named Event.
Previously, we only had one kind of event (unique event happening the 13 May from 9 AM to 11 AM), the sorting was simple (sort by start_date with an order)
We recently added a new feature that allows us to create recurring events, that means that we now have 2 levels inside Elasticsearch (parent-child relation).
We can have a parent event that is from the 12 May from 2 PM to the 14 May from 6 PM, linked to that event, we have the children that are daily, for example. So we’d have: 12 May 2PM-6PM, 13 May 2PM-6PM, 14 May 2PM-6PM.
The problem with the actual sort is that when we are the 12 May at 10 PM, we’ll find the recurring event on top of the list and after that, will come the unique event.
I’d like to have a sorting where the nearest date has a higher priority. In that case, the unique event should have been the first on the list.
To make that happen, I have indexed node children on recurring event parent, in order to have the children start_date.
The idea would be to get the nearest date out of the children node for every recurring event and sort that one with the start_date of every unique event.
I do not have a big experience with elasticsearch, so I’m kind of stuck, I saw a lot of information in the documentation (parent-child, nested objects, scripts, etc.) but I don’t know how to handle this case.
I hope that I have explained myself correctly if you have any questions, feel free to ask them, I would be happy to provide you with additional information.
For the future googlers, here's how I fixed it.
Had to use scripts and sort with it, here's a partial exemple of the request I'm using
GET /event/_search
{
"query" : {
"match_all": {}
},
"sort" : {
"_script" : {
"type" : "number",
"script": {
"lang": "painless",
"params": {
"currentDate": 1560230000
},
"source": """
def isRecurrenceParent = params._source.is_recurrence_parent;
def countChildren = params._source.children.length;
def currentDate = params.currentDate;
if (isRecurrenceParent === false) {
return params._source.timestamp;
}
def nearest = 0;
def lowestDiff = currentDate;
for (int i = 0; i < countChildren; i++) {
def child = params._source.children[i];
def diff = child.timestamp - currentDate;
if (diff > 0 && diff < lowestDiff) {
lowestDiff = diff;
nearest = child.timestamp;
}
}
return nearest;
"""
},
"order" : "asc"
}
}
}
First thing you should consider is parent and child docs are saved separately. It means Parent-Event::1 and Child-Event::1 are saved in a same shard (ES routes to shard where parent located by its id hash) but document types are different. So, you should fetch Parent and Children documents separately by query and sort by date.
(You can make following queries in php if works)
P.S: I have also same situation but I had to implement in Java. So, I made a ES query builder (https://github.com/mashhur/java-elasticsearch-querybuilder) which supports parent-child relationship queries too, you can take a look for the reference.
// search child events and sort by date
GET events/_search {
"query": {
"has_parent": {
"parent_type": "parent-event",
"query": {
"match_all": {}
}
},
"sort": [{"start_date": {"desc"}}]
}
}
// search parent events and sort by date
GET events/_search {
"query": {
"has_child": {
"type": "child-event",
"query": {
"match_all": {}
}
},
"sort": [{"start_date": {"desc"}}]
}
}

Jit.js, Jquery Json & PHP json_encode odd issues

I chose to use JIT.js rgraph for a project I am working on. What I've done was taken the examples and began slowly merging the js into the projects core files. Simple! The hang up I've run into has me literally stumped.
example.js has (assumed to be hand written at some point) json like so.
var json = {
id: "190_0",
name: "Pearl Jam",
children: [{
id: "306208_1",
name: "Pearl Jam & Cypress Hill",
data: {
relation: "<h4>Pearl Jam & Cypress Hill</h4><b>Connections:</b><ul><li>Pearl Jam <div>(relation: collaboration)</div></li><li>Cypress Hill <div>(relation: collaboration)</div></li></ul>"
},
children: [{
id: "84_2",
name: "Cypress Hill",
data: {
relation: "<h4>Cypress Hill</h4><b>Connections:</b><ul><li>Pearl Jam & Cypress Hill <div>(relation: collaboration)</div></li></ul>"
},
children: []
}]
},...
I need the json file dynamically generated in a sense and the most productive way for me to use the json is to create a static file if/when relative parts of the project are updated instead of generating json every time the page loads. Makes sense right?
json.php looks like this
$project = array(
"id" => "1",
"name" => "Testing Project",
"children" => array (
"id" => "2",
"name" => "Sub 1",
"data" => array(
"relation" => "<h4>Testing Project</h4><b>Structure:</b><ul><li>Sub1</li><li>Section 1</li></ul>"
),
"children" => array(
"id" => "3",
"name" => "Section 1",
"data" => array(
"relation" => "<h4>Section 1</h4><b>Structure:</b><ul><li>Testing Project</li><li>Sub 1</li></ul>"
),
"children" => ''
)
)
);
// header('Content-type: application/json'); /* DOES NOTHING */
echo json_encode($project);
my Arrays are hand written at the moment to make sure the process works as intended before programmatically generating the arrays from the database. There are other pieces to the puzzle I do not believe are at all involved at this time but the next piece we need to look at is the ajax call to fetch json.php which is in my custom.js file.
function init() {
var json = (function () {
var json = null;
$.ajax({
'async': false,
'global': true,
'url': 'js/json.php',
'dataType': "json",
'success': function (data) {
json = data;
console.log(data);
}
});
return json;
})(); ... continue with JIT.js functions
I added console.log(data) to see if the json was coming back formatted and this is what that looks like console.log screenshot using custom.js ajax call So then I reused the example.js file and console.log(data) give us console.log screenshot using example.js
The only obvisou difference is that the example.js json is be represented as an array, not an object. Even stranger still is that when I run the example using the custom.js file with the ajax call "Testing Project" does appear on the graph but no children elements. In the screenshot for custom.js console.log shows all the children elements as children: object, not children:Array[] like example.js
My first thought was to see if I can ensure that all json_encoding forced the associative arrays into "arrays". And yea... lots of time wasted looking at the obvious. So my next thought was it must be in the formatting. example.js used [{ for each child element but json_encode does not. I cannot locate any information to confirm if that really is the problem or not, but, none the less I cant rule that out. I also checked into sequential indexes. example.js certainly does not have sequential indexes. I even went ahead and sorted the arrays before encoding json_encode(array_values($project)); to see what happens and while it outputs to a browser with indexes it of course shows nothing in the graph.
I feel like im spinning in circles ( not in the good eagle circling prey kinda way ) but getting to far off focus to figure this out. I need some fresh perspective and ideas what might be going wrong.
**Edit
I've also tried to convert the strings manually with PHP. still not working. Any ideas?
WOW, Just over 24 hours and I end up doing something like this. It works by making each child with content an array of arrays.
$test = array(
'id' => "1",
'name' => "testing sample",
'children' => array(
array(
...
),array(
...
'children' =>array(),
),
)
);
echo json_encode($test);

How to update mongodb document

Hi i'm really mongodb newbie.
I have a document like this:
{
"_id": ObjectId("53182e32e4b0feedb1dea751"),
"solutions": [
[
{
"solution": "Double Room Economy (Without Breakfast)",
"board": "Room Only",
"id": "HK-15501871",
"price": 5000,
"available": "1",
"CXL": "[]",
"unique": 0
},
{
"solution": "Double Room Economy (With Breakfast)",
"board": "Room Only",
"id": "HK-15501871",
"price": 4600,
"available": "1",
"CXL": "[]",
"unique": 1
},
{
"solution": "Double Room Economy (Room Only)",
"board": "Room Only",
"id": "HK-15501871",
"price": 5500,
"available": "1",
"CXL": "[]",
"unique": 2
}
]
]
}
And i need to update the field CXL inside the second array of solutions.
so solutions.1.CXL
This is how i take document:
$collection = $this->getCollection();
$query = array("_id"=>new MongoId($id));
$document = $collection->findOne($query);
now i need to update that field without touch the other.
How can i do?
Thanks!
SOLVED THANKS TO #Sammaye
i solved in this way:
$collection->update(
array('_id' => new MongoId('..')),
array('$set' => array('solutions.0.1.CXL' => 'something'))
);
Edit
To actually update by the first index then you can do:
$db->collection->update(
['_id' => new \MongoId($id)],
['$set' => ['solutions.0.1.CLX' => 'whatever']]
);
I misread the question in posting the information below:
So what you wanna update all CXL fields in the document (since you are only searching by top level document _id)?
That isn't possible without manually pulling this document out and iterating the subdocuments in the solutions field and then resaving it.
This is becausde there is currently no way of saying, "Update all that match"
This, however, is most likely the JIRA you would want to look for: https://jira.mongodb.org/browse/SERVER-1243
As long as you know you are going to update the second element then use the index of the array to do so. But that problem next. First you need the $set operator in order not to blow away your document and just set the field value:
db.collection.update(
{ _id: ObjectId("53182e32e4b0feedb1dea751") },
{ $set: { "solutions.0.1.CXL": [ 1, 2, 3 ] } }
)
If you just want to add to the array rather than replace the whole thing, then just use $push instead:
db.collection.update(
{ _id: ObjectId("53182e32e4b0feedb1dea751") },
{ $push: { "solutions.0.1.CXL": 4 } }
)
If you are paying attention to the notation, then you will notice that the array index values are present in the field to be updated. There is a very good reason for this, which can be read on the documentation for the positional $ operator.
The issue is that you have a nested array, which as the documentation refers to, causes a problem if you try to match items within that nested array. That problem is, if you try to use the "positional" operator to find the matched index of something you look for in a query, then it will contain the value of the first array index match that it finds.
In this case that would be your "top level" array and the "found" index is 0 and not 1 as you may expect.
Please be aware of this issue if you intend to use nested arrays.
You can update like this:
update({
_id: ObjectId("53182e32e4b0feedb1dea751"),
solutions.id: HK-15501871,
solutions.CLX: "Whatever!",")
},{
$set: {"comments.$.type": abc}
}, false, true
);
You may want to go through this once
http://docs.mongodb.org/manual/reference/method/db.collection.update/

FullCalendar not displaying time from JSON events when allday is false

I am using FullCalendar and populate the calendar from an ajax call.
But I can not get the times to display if the allday is set to false
I was looking at FullCalendar not displaying time from JSON events but did not seem to help.
This is the JSON I am sending back:
][{"id":"18","title":"r2222","start":"2012-10-02
08:00:00","end":"2012-10-02
11:00:00","textColor":"#000000","allday":false,"color":"#ffffff"},
{"id":"1","title":"Test
123","start":"2012-10-16","end":null,"textColor":"#000000","allday":false,"color":"#ffffff"},
{"id":"16","title":"happy
gallown","start":"2012-10-31","end":"2012-10-31","textColor":"#fffcfc","allday":true,"color":"#d92727"},
{"id":"17","title":"recur","start":"2012-10-03
19:00:00","end":"2012-10-03
21:00:00","textColor":"#000000","allday":false,"color":"#ff56ff"}]
allDay is case sensitive; change it from allday to allDay - I just spent 25 minutes myself hunting this one down.
You can follow this allday to allDay and Time should be start: 2010-01-09T12:30:00 need to add T between date and time .
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09T12:30:00',
allDay : false // will make the time show
}
]

Categories