30 $viewKey = $widget->getViewKey();
31 $view = ViewProvider::getViewByViewKey($viewKey);
32 $resultWidget = $view->prepareWidgetContent($widget, $withCalculatedData);
45 $widget->loadAttribute(
'reports');
47 $reports = $widget->getReports();
48 $reportsCount =
count($widget->getReports());
49 if ($reportsCount > $view::MAX_RENDER_REPORT_COUNT)
51 $result[
'errors'][] =
'View with key:' . $view->getKey() .
'can\'t render this count(' . $reportsCount .
') of reports';
55 $handledReportData =
array();
56 foreach ($reports as $reportId => $report)
59 $reportDispatcher->setReport($report);
60 $reportDispatcher->setView($view);
61 $data = $reportDispatcher->getReportCompatibleData();
64 $errors = $reportDispatcher->getErrors();
75 if (!$reportDispatcher->getErrors())
77 if ($view::MAX_RENDER_REPORT_COUNT == 1)
79 $handledReportData =
$data;
81 elseif ($view::MAX_RENDER_REPORT_COUNT > 1)
83 $handledReportData[] =
$data;
88 foreach ($reportDispatcher->getErrors() as
$error)
94 return $handledReportData;
104 public static function prepareBoardWithEntitiesByBoardId($boardKey)
106 $dashboard = self::getDashboard($boardKey);
109 $rows = $dashboard->getRows();
110 $resultRows =
array();
114 foreach (
$rows as $row)
117 'id' => $row->getGId(),
118 'layoutMap' => $row->getLayoutMap(),
119 'weight' => $row->getWeight(),
122 foreach ($row->getWidgets() as $widget)
127 $resultRows[] = $resultRow;
132 'boardId' => $dashboard->getBoardKey(),
133 'boardKey' => $dashboard->getBoardKey(),
134 'userId' => $dashboard->getUserId(),
135 'rows' => $resultRows
150 private static function getDashboard($boardKey)
155 $dashboardForUser = DashboardEntity::loadByBoardKeyAndUserId($boardKey,
$USER->getid());
156 if ($dashboardForUser)
158 $dashboard = DashboardEntity::getBoardWithRowsAndWidgetsByBoardKeyUserId($boardKey,
$USER->getId());
162 $dashboard = DashboardEntity::getBoardWithRowsAndWidgetsByBoardKeyUserId($boardKey, 0);
175 public static function constructPseudoWidgetByParams(
$params)
177 if (!isset(
$params[
'viewType']))
179 throw new ArgumentException(
'viewType argument not exist');
182 if (!isset(
$params[
'widgetId']))
184 throw new ArgumentException(
'widgetId argument not exist');
187 if (!isset(
$params[
'boardId']))
189 throw new ArgumentException(
'boardId argument not exist');
192 if (!isset(
$params[
'categoryKey']) ||
$params[
'categoryKey'] ===
'myWidgets')
198 $categoryKey =
$params[
'categoryKey'];
201 $viewKey =
$params[
'viewType'];
202 $widgetGId =
$params[
'widgetId'];
204 $widgetConfigurations = !empty(
$params[
'widget'][$widgetGId][
'configurations']) ?
$params[
'widget'][$widgetGId][
'configurations'] :
array();
205 $reportsConfigurationsFromForm = !empty(
$params[
'widget'][$widgetGId][
'reports']) ?
$params[
'widget'][$widgetGId][
'reports'] :
array();
207 $viewController = ViewProvider::getViewByViewKey($viewKey);
208 $widgetHandler = $viewController->buildWidgetHandlerForBoard($boardId);
209 $widget = $widgetHandler->getWidget();
210 $widget->setCategoryKey($categoryKey);
212 if (!empty($widgetConfigurations[
'old']))
214 foreach ($widgetConfigurations[
'old'] as $configurationGid => $configuration)
216 foreach ($configuration as
$key => $value)
218 $widgetHandler->getFormElement(
$key)->setValue($value);
223 if (!empty($widgetConfigurations[
'new']))
225 foreach ($widgetConfigurations[
'new'] as
$key => $value)
227 $widgetHandler->getFormElement(
$key)->setValue($value);
231 foreach ($reportsConfigurationsFromForm as $reportId=> $report)
233 if (!empty(
$params[
'deletedReports']) && in_array($reportId,
$params[
'deletedReports']))
238 if (!empty($report[
'configurations'][
'new'][
'reportHandler']))
241 $reportHandler = $viewController->getReportHandler($report[
'configurations'][
'new'][
'reportHandler'], $widgetHandler);
243 elseif (!empty($report[
'configurations'][
'old']))
245 foreach ($report[
'configurations'][
'old'] as $configuration)
247 foreach ($configuration as
$key => $value)
249 if (
$key ===
'reportHandler')
252 $reportHandler = $viewController->getReportHandler($value, $widgetHandler);
263 if (isset($reportHandler) && $reportHandler instanceof BaseReport)
265 if (!empty($report[
'configurations'][
'old']))
267 foreach ($report[
'configurations'][
'old'] as $configuration)
269 foreach ($configuration as
$key => $value)
271 $reportHandler->getFormElement(
$key)->setValue($value);
276 if (!empty($report[
'configurations'][
'new']))
278 foreach ($report[
'configurations'][
'new'] as
$key => $value)
280 $reportHandler->getFormElement(
$key)->setValue($value);
284 $widgetHandler->addReportHandler($reportHandler);
285 $reportHandler->getReport()->setConfigurations($reportHandler->getConfigurations());
286 $reportHandler->getReport()->setWidget($widget);
289 $widget->setConfigurations($widgetHandler->getConfigurations());
303 if (!isset(
$params[
'viewType']))
308 if (!isset(
$params[
'widgetId']))
313 if (!isset(
$params[
'boardId']))
318 if (!isset(
$params[
'categoryKey']) ||
$params[
'categoryKey'] ===
'myWidgets')
324 $categoryKey =
$params[
'categoryKey'];
327 $viewKey =
$params[
'viewType'];
329 $viewController = ViewProvider::getViewByViewKey($viewKey);
330 $widgetHandler = $viewController->buildWidgetHandlerForBoard($boardId);
331 $widgetHandler = $viewController->addDefaultReportHandlersToWidgetHandler($widgetHandler);
332 $widget = $widgetHandler->getWidget();
333 $widget->setCategoryKey($categoryKey);
334 $widget->setConfigurations($widgetHandler->getConfigurations());
350 $patternWidget = $widget->getCopyForCurrentUser();
351 $patternWidget->setIsPattern(
true);
353 $patternWidget->setRowId(0);
354 $patternWidget->setCategoryKey($categoryKey);
355 $patternWidget->save();
356 return $patternWidget;
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)