本文整理汇总了PHP中Chart::setGuestSession方法的典型用法代码示例。如果您正苦于以下问题:PHP Chart::setGuestSession方法的具体用法?PHP Chart::setGuestSession怎么用?PHP Chart::setGuestSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chart
的用法示例。
在下文中一共展示了Chart::setGuestSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEmptyChart
/**
* 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;
}
示例2: createEmptyChart
/**
* 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;
}