Ejemplo n.º 1
0
 /**
  * creates a new empty chart
  */
 public function createEmptyChart($user)
 {
     $cfg = $GLOBALS['dw_config'];
     $defaults = isset($cfg['defaults']) ? $cfg['defaults'] : array();
     $chart = new Chart();
     $chart->setId($this->getUnusedRandomId());
     $chart->setCreatedAt(time());
     $chart->setLastModifiedAt(time());
     if ($user->isLoggedIn()) {
         $chart->setAuthorId($user->getId());
     } else {
         // remember session id to be able to assign this chart
         // to a newly registered user
         $chart->setGuestSession(session_id());
     }
     // find a nice, more or less unique title
     $untitled = __('Untitled');
     $title = '[' . $untitled;
     $untitledCharts = $this->filterByAuthorId($user->getId())->filterByTitle('[' . $untitled . '%')->filterByDeleted(false)->find();
     if (count($untitledCharts) > 0) {
         $title .= '-' . count($untitledCharts);
     }
     $chart->setTitle($title . ']');
     // todo: use global default theme
     $chart->setTheme(isset($defaults['theme']) ? $defaults['theme'] : 'default');
     $chart->setLocale('');
     // no default locale
     $chart->setType(isset($defaults['vis']) ? $defaults['vis'] : 'bar-chart');
     $defaultMeta = Chart::defaultMetaData();
     $chart->setMetadata(json_encode($defaultMeta));
     // $chart->setLanguage($user->getLanguage());  // defaults to user language
     $chart->setShowInGallery(isset($defaults['show_in_gallery']) ? $defaults['show_in_gallery'] : false);
     $chart->save();
     return $chart;
 }
Ejemplo n.º 2
0
 /**
  * creates a new empty chart
  */
 public function createEmptyChart($user)
 {
     $cfg = $GLOBALS['dw_config'];
     $defaults = isset($cfg['defaults']) ? $cfg['defaults'] : array();
     $chart = new Chart();
     $chart->setId($this->getUnusedRandomId());
     $chart->setCreatedAt(time());
     $chart->setLastModifiedAt(time());
     if ($user->isLoggedIn()) {
         $chart->setAuthorId($user->getId());
         $org = $user->getCurrentOrganization();
         if (!empty($org)) {
             $chart->setOrganization($org);
         }
     } else {
         // remember session id to be able to assign this chart
         // to a newly registered user
         $chart->setGuestSession(session_id());
     }
     // find a nice, more or less unique title
     $untitled = __('Insert title here');
     $title = '[ ' . $untitled . ' ]';
     $chart->setTitle($title);
     // todo: use global default theme
     $chart->setTheme(isset($defaults['theme']) ? $defaults['theme'] : 'default');
     // use organization default theme if possible
     if ($user->isLoggedIn()) {
         $org = $user->getCurrentOrganization();
         if (!empty($org)) {
             $def_org_theme = $org->getDefaultTheme();
             if (!empty($def_org_theme) && DatawrapperTheme::get($def_org_theme)) {
                 $chart->setTheme($def_org_theme);
                 $theme = DatawrapperTheme::get($def_org_theme);
                 if (isset($theme['default_width'])) {
                     $def_org_theme_default_width = $theme['default_width'];
                 }
                 if (isset($theme['default_height'])) {
                     $def_org_theme_default_height = $theme['default_height'];
                 }
             }
         }
     }
     $chart->setLocale('');
     // no default locale
     $chart->setType(isset($defaults['vis']) ? $defaults['vis'] : 'bar-chart');
     $chart->setPublicUrl($chart->getLocalUrl());
     $defaultMeta = Chart::defaultMetaData();
     if (isset($def_org_theme_default_width)) {
         $defaultMeta['publish']['embed-width'] = $def_org_theme_default_width;
     }
     if (isset($def_org_theme_default_height)) {
         $defaultMeta['publish']['embed-height'] = $def_org_theme_default_height;
     }
     $chart->setMetadata(json_encode($defaultMeta));
     // $chart->setLanguage($user->getLanguage());  // defaults to user language
     $chart->setShowInGallery(isset($defaults['show_in_gallery']) ? $defaults['show_in_gallery'] : false);
     $chart->save();
     return $chart;
 }
Ejemplo n.º 3
0
 /**
  * returns the chart meta data
  */
 public function getMetadata($key = null)
 {
     $default = Chart::defaultMetaData();
     $meta = json_decode(parent::getMetadata(), true);
     if (!is_array($meta)) {
         $meta = array();
     }
     $meta = array_merge_recursive_simple($default, $meta);
     if (empty($key)) {
         return $meta;
     }
     $keys = explode('.', $key);
     $p = $meta;
     foreach ($keys as $key) {
         $p = $p[$key];
     }
     return $p;
 }