Example #1
0
 public static function import_from_array_to_graph($input, $graph_id)
 {
     $result = true;
     if (!empty($input)) {
         $columns_to_ignore = array('line_id', 'graph_id');
         $new_line = fActiveRecord::array_to_dbentry($input, __CLASS__, $columns_to_ignore);
         if ($new_line !== NULL) {
             $new_line->setGraphId($graph_id);
             $new_line->store();
         } else {
             $result = false;
         }
     }
     return $result;
 }
Example #2
0
 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;
 }
Example #3
0
 public static function import_from_array_to_dashboard($input, $dashboard_id)
 {
     $result = true;
     if (!empty($input)) {
         $columns_to_ignore = array('graph_id', 'dashboard_id', 'lines');
         $new_graph = fActiveRecord::array_to_dbentry($input, __CLASS__, $columns_to_ignore);
         if ($new_graph !== NULL) {
             $new_graph->setDashboardId($dashboard_id);
             $new_graph->store();
             if (in_array('lines', array_keys($input))) {
                 $new_graph_id = $new_graph->getGraphId();
                 foreach ($input['lines'] as $line) {
                     $result_line = Line::import_from_array_to_graph($line, $new_graph_id);
                     $result = $result && $result_line;
                 }
             }
         } else {
             $result = false;
         }
     }
     return $result;
 }