Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JSON提要检索资源的Fullcalendar计划程序_Json_Fullcalendar - Fatal编程技术网

使用JSON提要检索资源的Fullcalendar计划程序

使用JSON提要检索资源的Fullcalendar计划程序,json,fullcalendar,Json,Fullcalendar,我刚刚开始使用Jquery Full Calendar的调度程序插件,但是在检索作为JSON提要的资源时遇到了问题,这是从数据库获取资源所必需的。以下是我试图实现的一个示例: 基本上,资源是左边的名称,但是对于我的日历,我总是需要parent->children视图,因为我有包含单位的属性 目前,我正在根据需要从数据库中获取数据,这是我获取的数组(请记住,这些只是我测试时使用的完全随机的示例): 当我在检索这些资源后转换为JSON时,我会将其保存到一个文件中,该文件是使用我的get resou

我刚刚开始使用Jquery Full Calendar的调度程序插件,但是在检索作为JSON提要的资源时遇到了问题,这是从数据库获取资源所必需的。以下是我试图实现的一个示例:

基本上,资源是左边的名称,但是对于我的日历,我总是需要parent->children视图,因为我有包含单位的属性

目前,我正在根据需要从数据库中获取数据,这是我获取的数组(请记住,这些只是我测试时使用的完全随机的示例):


当我在检索这些资源后转换为JSON时,我会将其保存到一个文件中,该文件是使用我的
get resources.php

<?php
// Require our Event class and datetime utilities
require dirname(__FILE__) . '/utils.php';

// Read and parse our events JSON file into an array of event data arrays.
$json = file_get_contents(dirname(__FILE__) . '/booking_json/resources.json');

// Send JSON to the client.
echo $json;
但是,当试图在javascript初始化中检索时,这总是抛出异常错误:

$('#availability-calendar').fullCalendar( {
    schedulerLicenseKey: '0409344942-fcs-1497004132',
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaDay,agendaWeek'
    },
    defaultDate: TODAY,
    defaultView: 'timelineMonth',
    editable: true,
    navLinks: true,
    eventLimit: true,
    timeFormat: 'hh:mma',
    resourceAreaWidth: '25%',
    resourceLabelText: 'Property / Units',
    resources: {
        url: '/get-resources.php',
        error: function() {
            $('#resource-warning').show();
        }
    },
    events: {
        url: '/get-bookings.php',
        error: function() {
            $('#script-warning').show();
        }
    },
    loading: function(bool) {
        $('#loading').toggle(bool);
    },
    eventRender: function(event, element) {
    }
});
(这里具体指参考资料部分)。我只是想澄清一下,我获得预订的方式基本相同,但因为没有像资源那样的嵌套值,所以它们可以工作

在此方面的任何帮助都是非常感谢的,因为完整日历网站上的文档并没有详细介绍此方法

编辑:我已经设法修复了它。基本上,这是孩子们在字符串中被格式化的方式,所以我现在这样做:

foreach ($prop_units as $v) {
    $id = $v['prop_id'];
    $record = array_diff_key($v, $exclude);

    if (!isset($result[$id])) {
        $result[$id] = $record;
        $result[$id]['units'] = [];
    }

    $unit = array_diff_key($v, $record);
    $result[$id]['units'][$x]['id'] = $unit['unit_id'];
    $result[$id]['units'][$x]['title'] = $unit['unitName'];
    $x ++;
}


if (!empty($result)) {

    $resources = array();
    foreach ($result as $propId => $row) {
        $resource = array();
        $resource['id'] = $propId;
        $resource['title'] = $row['propertyName'];
        $resource['children'] = [ ];

        foreach($row['units'] as $unit_row) {
            array_push($resource['children'],(object) $unit_row);
        }

        $obj = (object) $resource;

        array_push($resources, $obj);

        $obj = false;
    }
}

主要的变化是,现在我不再将单元数组分配给
$resource
对象的子部分,而是循环遍历每一个对象,并将其放入
array\u push()。然后以正确的格式返回JSON,使其能够正确呈现。感谢@ADyson对此的帮助。

“检索这些资源后,我将其保存到一个文件中,该文件是使用get resources.php获得的:”。为什么不让get-resources.php直接检索数据?这将节省时间和精力。无论如何,第二个资源的“children”是错误的JSON格式。它需要更像
的“children”:[{“id”:5,“title”:“公寓号1”},{“id”:6,“title”:“2床公寓”},{“id”:11,“title”:“Jamie”}]
是的,我同意第二组孩子不正确。我确实做了进一步的分析,但我不明白为什么它会这样做。我现在已经把第一个属性放出来了,但是第二个属性没有子属性……如果你展示了用PHP构建整个资源数组的代码,它可能是可以修复的。嗨,我实际上刚刚根据你对错误格式的推断,找到了解决方法。似乎因为每个单元数组是独立的,所以它在每个子元素之前添加了ID。因此,如果你在我的问题中看到,我已经添加了解决方案。
$('#availability-calendar').fullCalendar( {
    schedulerLicenseKey: '0409344942-fcs-1497004132',
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaDay,agendaWeek'
    },
    defaultDate: TODAY,
    defaultView: 'timelineMonth',
    editable: true,
    navLinks: true,
    eventLimit: true,
    timeFormat: 'hh:mma',
    resourceAreaWidth: '25%',
    resourceLabelText: 'Property / Units',
    resources: {
        url: '/get-resources.php',
        error: function() {
            $('#resource-warning').show();
        }
    },
    events: {
        url: '/get-bookings.php',
        error: function() {
            $('#script-warning').show();
        }
    },
    loading: function(bool) {
        $('#loading').toggle(bool);
    },
    eventRender: function(event, element) {
    }
});
foreach ($prop_units as $v) {
    $id = $v['prop_id'];
    $record = array_diff_key($v, $exclude);

    if (!isset($result[$id])) {
        $result[$id] = $record;
        $result[$id]['units'] = [];
    }

    $unit = array_diff_key($v, $record);
    $result[$id]['units'][$x]['id'] = $unit['unit_id'];
    $result[$id]['units'][$x]['title'] = $unit['unitName'];
    $x ++;
}


if (!empty($result)) {

    $resources = array();
    foreach ($result as $propId => $row) {
        $resource = array();
        $resource['id'] = $propId;
        $resource['title'] = $row['propertyName'];
        $resource['children'] = [ ];

        foreach($row['units'] as $unit_row) {
            array_push($resource['children'],(object) $unit_row);
        }

        $obj = (object) $resource;

        array_push($resources, $obj);

        $obj = false;
    }
}