public static function import_from_json_to_group($json, $group_id = NULL) { $result = true; $json_array = json_decode($json, TRUE); if (!empty($json_array)) { if (array_key_exists("name", $json_array)) { // In this case, we only have a dashboard, not an array of dashboard // We convert it into an array $json_array = array($json_array); } foreach ($json_array as $dashboard_to_create) { $column_to_ignore = array('dashboard_id', 'group_id', 'graphs'); $new_dashboard = fActiveRecord::array_to_dbentry($dashboard_to_create, __CLASS__, $column_to_ignore); if ($new_dashboard !== NULL) { $new_dashboard->setGroupId(empty($group_id) ? $GLOBALS['DEFAULT_GROUP_ID'] : $group_id); $new_dashboard->setUserId(fSession::get('user_id', 1)); $new_dashboard->store(); if (in_array('graphs', array_keys($dashboard_to_create))) { $new_dashboard_id = $new_dashboard->getDashboardId(); foreach ($dashboard_to_create['graphs'] as $graph) { $result_graph = Graph::import_from_array_to_dashboard($graph, $new_dashboard_id); $result = $result && $result_graph; } } } else { $result = false; } } } else { fMessaging::create('error', "/" . Dashboard::makeUrl('list'), "Empty or malformed file"); $result = false; } return $result; }