00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 class ReportDetailsView extends DetailsView
00041 {
00042 protected $savedReport;
00043
00047 public function __construct($controllerId, $moduleId, Report $model, $title = null, SavedReport$savedReport)
00048 {
00049 parent::__construct($controllerId, $moduleId, $model);
00050 $this->savedReport = $savedReport;
00051 }
00052
00056 public static function assertModelIsValid($model)
00057 {
00058 assert('$model instanceof Report');
00059 }
00060
00064 public static function getDefaultMetadata()
00065 {
00066 $metadata = array(
00067 'global' => array(
00068 'toolbar' => array(
00069 'elements' => array(
00070 array('type' => 'ReportOptionsMenu',
00071 'iconClass' => 'icon-options',
00072 'htmlOptions' => array('id' => 'ListViewOptionsActionMenu'),
00073 ),
00074 array('type' => 'ReportExportMenu',
00075 'iconClass' => 'icon-export',
00076 'htmlOptions' => array('id' => 'ListViewExportActionMenu'),
00077 ),
00078 array('type' => 'ReportTogglePortletsLink',
00079 'htmlOptions' => array('class' => 'hasCheckboxes'),
00080 'hasRuntimeFilters' => 'eval:$this->model->hasRuntimeFilters()',
00081 'hasChart' => 'eval:$this->model->hasChart()'
00082 ),
00083 ),
00084 ),
00085 ),
00086 );
00087 return $metadata;
00088 }
00089
00094 public function getTitle()
00095 {
00096 if ($this->model->id > 0)
00097 {
00098 $moduleClassName = $this->model->moduleClassName;
00099 $moduleLabel = $this->getPuralModuleLabelForReportTitle($moduleClassName);
00100 $typesAndLabels = Report::getTypeDropDownArray();
00101 $title = strval($this->model) . ' - ' .
00102 Zurmo::t('ReportsModule', '{moduleLabel} {typeLabel} Report',
00103 array('{moduleLabel}' => $moduleLabel,
00104 '{typeLabel}' => $typesAndLabels[$this->model->type]));
00105 return $title;
00106 }
00107 else
00108 {
00109 throw new NotSupportedException();
00110 }
00111 }
00112
00113 public function getPuralModuleLabelForReportTitle($moduleClassName)
00114 {
00115 $moduleLabels = Report::getReportableModulesAndLabelsForCurrentUser();
00116 $moduleLabel = $moduleClassName::getModuleLabelByTypeAndLanguage('Plural');
00117 if (isset($moduleLabels[$moduleClassName]))
00118 {
00119 $moduleLabel = $moduleLabels[$moduleClassName];
00120 }
00121 return $moduleLabel;
00122 }
00123
00124 public function registerScripts()
00125 {
00126 $script = '$(".ReportSQLForPortletView").hide();';
00127 Yii::app()->getClientScript()->registerScript('ReportPortletsDefaultHideScript', $script);
00128 Yii::app()->getClientScript()->registerCoreScript('bbq');
00129 }
00130
00134 protected function renderContent()
00135 {
00136 $content = $this->renderTitleContent();
00137 $content .= '<div class="view-toolbar-container clearfix"><nav class="pillbox clearfix">';
00138 $content .= $this->renderActionElementBar(false);
00139 $content .= '</nav></div>';
00140 $this->registerScripts();
00141 return $content;
00142 }
00143
00144 public function getPostTruncatedTitleContent()
00145 {
00146 return StarredUtil::getToggleStarStatusLink($this->savedReport, null);
00147 }
00148
00149 protected function shouldRenderToolBarElement($element, $elementInformation)
00150 {
00151 if (get_class($element) == 'ReportExportLinkActionElement' &&
00152 !$this->userCanExportReport())
00153 {
00154 return false;
00155 }
00156 if (get_class($element) == 'ReportOptionsLinkActionElement')
00157 {
00158 $userCanEditReport = $this->userCanEditReport();
00159 $userCanDeleteReport = $this->userCanDeleteReport();
00160 $userCanCreateReport = $this->userCanCreateReport();
00161 if (!$userCanEditReport && !$userCanDeleteReport && !$userCanCreateReport)
00162 {
00163 return false;
00164 }
00165 if (!$userCanEditReport)
00166 {
00167 $element->setHideEdit();
00168 }
00169 if (!$userCanDeleteReport)
00170 {
00171 $element->setHideDelete();
00172 }
00173 if (!$userCanCreateReport)
00174 {
00175 $element->setHideCopy();
00176 }
00177 }
00178 return true;
00179 }
00180
00181 protected function userCanCreateReport()
00182 {
00183 return ActionSecurityUtil::canCurrentUserPerformAction('Create', $this->savedReport);
00184 }
00185
00186 protected function userCanEditReport()
00187 {
00188 return ActionSecurityUtil::canCurrentUserPerformAction('Edit', $this->savedReport);
00189 }
00190
00191 protected function userCanDeleteReport()
00192 {
00193 return ActionSecurityUtil::canCurrentUserPerformAction('Delete', $this->savedReport);
00194 }
00195
00196 protected function userCanExportReport()
00197 {
00198 return ActionSecurityUtil::canCurrentUserPerformAction('Export', $this->savedReport);
00199 }
00200 }
00201 ?>