jquery gantt plugin - php

Situation
I'm using a jQuery gantt plugin from here and integrating it with a PHP site I have. In terms of setting up the demo there are no problems; however when I try to feed the plugin some of my own data, it will throw up the following error:
TypeError: e is undefined
Now, I believe the above error is thrown due to the JSON object being unfamiliar to the plugin but, I just can't seem to package it correctly.
My JSON Data
Demo JSON Data
Now, you can see other than a few differences, I am pretty close to the mark. Up next is the PHP code I use to generate this.
$aryOutput = array('source' => array());
if($aryTasks) {
foreach($aryTasks as $aryTask) {
$aryOutput['source'][] = array(
'name' => $aryTask['task_stage'],
'desc' => $aryTask['task_title'],
'values' => array(array(
'to' => '/Date('.time($aryTask['task_projected_end_timestamp']).')',
'from' => '/Date('.time($aryTask['task_projected_start_timestamp']).')',
'desc' => $aryTask['task_description'],
'label' => $aryTask['task_description']
))
);
}
}
$strJSON = json_encode($aryOutput, JSON_UNESCAPED_SLASHES);
Please can anyone offer some pearls of wisdom to resolve this matter. On a side note, from another question, I saw that the class has to be gantt. This is not a problem, I can get the plugin working with a different data set.
Thank you
Edit
I noticed a small difference with the date field having an extra slash on it. After editing the code to add it, the error still occurs

Check the complete delivered JSON is structure as needs be. In the above example, it is likely this is the output:
source : { source : { ... } }
This causes confusion with the plugin as it is unexpected data.

Related

Pootle exports incorrect PHP array files

I've been using Pootle recently for translating a small PHP project. Our i18n files are as php arrays, example:
return array(
'word.in' => 'en',
'word.yes' => 'Sí',
'word.no' => 'No',
'word.with' => 'con',
);
So I created a Project in Pootle's admin panel and set the source files are PHP arrays. I can upload and translate files perfectly fine afterwards.
The problem comes when I try to export, the file rendered has the following syntax:
return array->'word.in'='for';
return array->'word.yes'='Yes';
return array->'word.no'='No';
return array->'word.with'='with';
Which afaik isn't even valid PHP syntax.
I've read through the Pootle and Translation Toolkit's documentations and I've found that it passes through some sort of 'template' to generate that crappy output.
Any ideas how I can fix this and be able to export my PHP array with exactly the same syntax I uploaded it? Any help greatly appreciated!
Any ideas how I can fix this and be able to export my PHP array with exactly the same syntax I uploaded it?
Before return statement, if You need to actually write that array to file and read it later again, I would do something like this ..
$arrayExport = var_export(
array(
'word.in' => 'en',
'word.yes' => 'Sí',
'word.no' => 'No',
'word.with' => 'con',
), true);
Than write down $arrayExport .. for example:
file_put_contents($filePathName,
'<?php $exportedArrayName = '.$arrayExport.";\n ?>",
LOCK_EX);
...than goes the rest of weird Pootle and translation ...
But if You need to read it again after a while without storing it, use $_SESSIONS and serialization.
$_SESSION['exportedArray'] = serialize(array(
'word.in' => 'en',
'word.yes' => 'Sí',
'word.no' => 'No',
'word.with' => 'con',
));
To read from session ..
$exportedArray = unserialize($_SESSION['exportedArray']);

How to use: sonata_type_model_list

I'm trying to run this code:
if(!$this->isChild()) {
$formMapper->add('post', 'sonata_type_model', array(), array('edit' => 'list'));
From this tutorial: http://sonata-project.org/bundles/doctrine-orm-admin/2-1/doc/tutorial/creating_your_first_admin_class/defining_admin_class.html
I'm aware that you have to use sonata_type_model_list as of 2.1
sonata_type_model_list : this type replaces the option edit = list provided as a 4th argument on the sonata_type_model
The problem is that I have absolutely no idea how to do that. I have found ZERO examples anywhere after a whole day of google searches. All I want to do is replace the edit=>list with sonata_type_model_list.
Can you please tell me how to do that in the code above?
This is how I used it in my code. However it's not working in all browsers. When I select the taget entity the form value in the parent view doesn't get updated (FireFox and IE).
$formMapper->
...
->add('image', 'sonata_type_model_list',
array(
'compound' => true,
'by_reference' => true
)
)
...
I also find it very hard to find some tutorials/examples on how to use this type. Best thing you can do is to go through their source code. Which is awful time consuming.
One way I found out how to configure these form types is to provide a wrong argument.
e.g. 'my_compound' => true,
This will result in an error telling you that 'my_compound' isn't a valid parameter and also will show you a list of valid parameters.
Hope this helps!

How am I supposed to be using filter_xss? Even though I'm using it, coder gives me an issue

+269: [critical] Potential problem: drupal_set_message
http://api.drupal.org/api/function/drupal_set_message/() only accepts
filtered text, be sure all !placeholders for $variables in t
http://api.drupal.org/api/function/t/() are fully sanitized using
check_plain http://api.drupal.org/api/function/check_plain/(),
filter_xss http://api.drupal.org/api/function/filter_xss/() or
similar.
Which pertains to this code:
drupal_set_message(t('Batch complete! View/Download !results', array(
'!results' => filter_xss(l(t('simple results'), file_create_url($filename))),
)), 'info');
What's going wrong?
The method you're using is under the 'DO NOT DO THESE THINGS' portion of Dynamic or static links in translatable strings. You need to change it to one of the approved methods. For reference:
<?php
// DO NOT DO THESE THINGS
$BAD_EXTERNAL_LINK = t('Look at Drupal documentation at !handbook.', array('!handbook' => ''. t('the Drupal Handbooks') .''));
$ANOTHER_BAD_EXTERNAL_LINK = t('Look at Drupal documentation at the Drupal Handbooks.');
$BAD_INTERNAL_LINK = t('To get an overview of your administration options, go to !administer in the main menu.', array('!administer' => l(t('the Administer screen'), 'admin'));
// Do this instead.
$external_link = t('Look at Drupal documentation at the Drupal Handbooks.', array('#drupal-handbook' => 'http://drupal.org/handbooks'));
$internal_link = t('To get an overview of your administration options, go to the Administer screen in the main menu.', array('#administer-page' => url('admin')));
?>

How do I get FullCalendar to display information from my JSON feed?

I'm setting up an app using FullCalendar (http://arshaw.com/fullcalendar/) that will allow the user to see client scheduling information as well as schedule clients through a management interface.
I want to use a MySQL database to populate an array, and then pass that array in the form of a JSON feed to FullCalendar on an HTML page. Ideally, then, the client information would show up on the HTML page. However, even though my JSON feed is being passed, there are no events on my FullCalendar.
Example JSON feed being passed:
[{"title":"Watson","start":"1333976400","end":"1333980000","allDay":false}]
I'm fairly new to these languages and I would not be surprised if this mistake turn out to be simple.
I would deeply appreciate any help or insight on having these events show up. When I manually feed an array into FullCalendar, it does show the events, but so far my JSON feed has resulted in no information being displayed.
Thank you
For reference:
HTML:
$(document).ready(function() {
$('#calendar').fullCalendar({
events: '/json-events.php'
});
});
PHP:
while ($record = mysql_fetch_array($result)) {
$event_array[] = array(
'id' => $record['id'],
'title' => $record['title'],
'start' => $record['start_date'],
'end' => $record['end_date'],
'allDay' => false
);
}
echo json_encode($event_array);
So the problem, for those searchers that come after me, was that my PHP file had HTML head and body tags. I'm a PHP noob and so I didn't know that would cause it not to work. In order for FullCalendar to display the JSON feed, it must ONLY have PHP code, no HTML. JSONLint.com was invaluable in figuring that out.
I set up a quick example and didn't have any trouble getting this to work:
PHP:
<?php
$record[0]["title"]="Test 1";
$record[1]["title"]="Test 2";
$record[2]["title"]="Test 3";
$record[0]["start_date"]="1333976400";
$record[1]["start_date"]="1333976401";
$record[2]["start_date"]="1333976402";
$record[0]["end_date"]="1333980000";
$record[1]["end_date"]="1333980001";
$record[2]["end_date"]="1333980002";
$record[0]["id"]="1";
$record[1]["id"]="2";
$record[2]["id"]="3";
for ($i=0; $i<3; $i++) {
$event_array[] = array(
'id' => $record[$i]['id'],
'title' => $record[$i]['title'],
'start' => $record[$i]['start_date'],
'end' => $record[$i]['end_date'],
'allDay' => false
);
}
echo json_encode($event_array);
exit;
?>
HTML:
events: '/events.php'
Sample output from the PHP script:
[{"id":"1","title":"Test 1","start":"1333976400","end":"1333980000","allDay":false},{"id":"2","title":"Test 2","start":"1333976401","end":"1333980001","allDay":false},{"id":"3","title":"Test 3","start":"1333976402","end":"1333980002","allDay":false}]
So given that the above works for me and it's really no different to what you have above, you might need to check that the PHP script is actually getting called correctly. Check the Javascript console in Mozilla Firefox or Google Chrome to see if there are any errors thrown when Fullcalendar tries to load the events. Check your web server access/error logs for any mention of the PHP script.
events: '/json-events.php'
should be either
events: './json-events.php'
or
events: 'json-events.php'
Let me know if this helps...
EDIT
I also noticed that in the Json that your are receiving there is no id in the line. There may be something going on between the nameing of you id within the DB comparitively to the name your using in the array. Check it out and see if that is what is going on, because that is one of the properties that are required to pass the event.
EDIT
Try removing the [] from $event_array[] and see what happens... If that doesn't work than I am stumpped... sorry

JSON code for my radio station website?

This is part of my radio station website's PHP coding:
http://pastebin.com/D1TUMNSc
I've got the PHP to work; but getting the JSON to work is a problem, I'm not sure how to do it with the variables I've got...
Currently the schedule page shows as blank, since I'm not sure what to do.
The Javascript is here: http://pastebin.com/P1ydnVCK
Basically, I'm having trouble trying to create a JSON to fit within the variables of the Javascript, it's new to me, this area of programming...
What would you suggest?
I've had a look around the net at JSON resources but am not quite sure what to do for this one!
Just a quick look so this may not be everything you need, but.... You need to do something like this....
$json->schedule = array();
// Loop Here
$show = array(
'longname' => 'xxxxx',
'description' => 'xxxxxx',
'weblink' => 'http://xxxx.com',
'showimage' => 'xxxx',
'startminutes' => '0000000',
'endminutes' => '000000',
);
// End Loop
$json->schedule[] = $show;
echo json_encode($json);
In your javascript anything prefixed with _s needs to be a variable... Ex: this._s.longname

Categories