/** * 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; }
/** * 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; }