search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How I can modify resources? If I don’t need group?

Related article: HTML5 Scheduler
Asked by m3ddo
10 months ago.

Hi, i tried to modify resources on db (MySQL with XAMPP) but now events are strange; when I create events they appear on db, but if I reload the page on planner there are only events on group. How I can modify all resources and even if I don’t need group, how I can modify code for no group? I tried by myself

Answer posted by Dan Letecky [DayPilot]
10 months ago.

If the events don’t display correctly, you should check the id of the resources (resources[].id) and the resource of events (event.list[].resource). Events are only displayed in a row if these value match exactly, including their type. Note that 1 !== "1" (number vs string). In PHP, some DB drivers convert number values to strings.

In order to display a flat list of resources (without parents), you should modify the backend_resources.php script to return a flat array without children. In the HTML5 Scheduler tutorial, this script returns a JSON array that looks like this:

[
  {"id":"group_1","name":"People","expanded":true,"children":
    [
      {"id":"1","name":"Person 1"},
      {"id":"2","name":"Person 2"},
      {"id":"3","name":"Person 3"},
      {"id":"4","name":"Person 4"}
    ]
  },
  {"id":"group_2","name":"Tools","expanded":true,"children":
    [
      {"id":"5","name":"Tool 1"},
      {"id":"6","name":"Tool 2"},
      {"id":"7","name":"Tool 3"},
      {"id":"8","name":"Tool 4"}
    ]
  }
]

You need to modify the script to return only the items from the resources table:

<?php
require_once '_db.php';

class Resource {}

$resources = array();

$stmt = $db->prepare('SELECT * FROM resources ORDER BY name');
$stmt->execute();
$scheduler_resources = $stmt->fetchAll();  

foreach($scheduler_resources as $resource) {
  $r = new Resource();
  $r->id = $resource['id'];
  $r->name = $resource['name'];
  $resources[] = $r;
}

header('Content-Type: application/json');
echo json_encode($resources);
Comment posted by m3ddo
10 months ago.

I will try, thanks a lot.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.