Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelsToMergeListAndChartView.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  protected $dupeModels;
43 
44  protected $colorsArray = array('#315AB0', '#66367b', '#2c3e50', '#269a55', '#c0392b',
45  '#e67e22', '#3498db', '#501a27', '#0c5b3f', '#c05d91');
46 
47  public function __construct($controllerId, $moduleId, $model, $dupeModels)
48  {
49  $this->assertModelIsValid($model);
50  $this->controllerId = $controllerId;
51  $this->moduleId = $moduleId;
52  $this->model = $model;
53  $this->modelClassName = get_class($model);
54  $this->modelId = $model->id;
55  $this->dupeModels = $dupeModels;
56  }
57 
63  protected function renderContent()
64  {
65  $leftContent = $this->renderSelectedContactsListWithCardView();
66  $rightContent = $this->renderRightSideContent();
67  return ZurmoHtml::tag('div', array('class' => 'chosen-entries'), $leftContent . $rightContent);
68  }
69 
70  protected function renderSelectedContactsListWithCardView()
71  {
72  $title = $this->getTitleBar();
73  $preparedContent = $this->renderBeforeListContent();
74  $modelsToShow = $this->dupeModels;
75  $this->resolveMaxModelsToShow($modelsToShow);
76  $cards = null;
77  $position = 1;
78 
79  foreach ($modelsToShow as $key => $dupeModel)
80  {
81  $detailsViewContent = $this->renderDetailsViewForDupeModel($dupeModel);
82  if (!strcmp($dupeModel->id, $this->model->id))
83  {
84  $extraClass = ' selected';
85  $display = 'block';
86  }
87  else
88  {
89  $extraClass = '';
90  $display = 'none';
91  }
92  if ($this->model->id <0)
93  {
94  $display = ($key == 0) ? 'block' : 'none';
95  $extraClass = ($key == 0) ? ' selected' : '';
96  }
97  $cards .= ZurmoHtml::tag('div', array('class' => 'sliding-panel business-card showing-panel',
98  'id' => 'dupeDetailsView-' . $dupeModel->id,
99  'style' => 'display:' . $display),
100  $detailsViewContent);
101  $radio = ZurmoHtml::tag('span', array(), $this->renderRadioButtonContent($dupeModel));
102  $entryName = ZurmoHtml::tag('a', array('href' => '#'), strval($dupeModel));
103  $contactNameElement = ZurmoHtml::tag('li', array('class' => 'selectedDupe merge-color-' . $position++ . $extraClass,
104  'id' => 'selectedDupe-' . $dupeModel->id), $radio . $entryName);
105  $preparedContent .= $contactNameElement;
106  }
107  $this->registerScripts();
108  $cards = ZurmoHtml::tag('div', array('class' => 'cards'), $cards);
109  $possibleMatches = ZurmoHtml::tag('ul', array('class' => 'possible-matches'), $preparedContent);
110  return $title . $possibleMatches . $cards;
111  }
112 
113  protected function resolveMaxModelsToShow(& $models)
114  {
116  {
117  $models = array_slice($models, 0, ModelsListDuplicateMergedModelForm::MAX_SELECTED_MODELS_COUNT);
118  }
119  }
120 
121  protected function renderDetailsViewForDupeModel($model)
122  {
123  $content = null;
124  if ($model instanceof User || $model instanceof Person)
125  {
126  $layout = new PersonCardViewLayout($model, true);
127  }
128  elseif ($model instanceof Account)
129  {
130  $layout = new AccountCardViewLayout($model, true);
131  }
132  else
133  {
134  throw new NotSupportedException();
135  }
136  $content = $layout->renderContent();
137  $content .= $this->renderActivitiesTotals($model);
138  return $content;
139  }
140 
141  protected function renderRightSideContent($form = null)
142  {
143  $content = ZurmoHtml::tag('div', array('class' => 'spidergraph'), $this->renderChart());
144  return $content;
145  }
146 
147  protected function renderChart()
148  {
149  if (empty($this->dupeModels))
150  {
151  return null;
152  }
153  Yii::import('ext.amcharts.AmChartMaker');
154  $chartId = 'dedupeChart';
155  $amChart = new AmChartMaker();
156  $amChart->categoryField = 'category';
157  $this->resolveDataForChart($amChart);
158  $amChart->id = $chartId;
159  $amChart->type = ChartRules::TYPE_RADAR;
160  $amChart->addValueAxisProperties('integersOnly', 'true');
161  $this->resolveGraphsForChart($amChart);
162  $scriptContent = $amChart->javascriptChart();
163  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $chartId, $scriptContent);
164  $cClipWidget = new CClipWidget();
165  $cClipWidget->beginClip("Chart" . $chartId);
166  $cClipWidget->widget('application.core.widgets.AmChart', array('id' => $chartId, 'width' => '300px', 'height' => '250px'));
167  $cClipWidget->endClip();
168  return $cClipWidget->getController()->clips['Chart' . $chartId];
169  }
170 
171  protected function registerScripts()
172  {
173  $script = "$('body').on('click', 'li.selectedDupe',
174  function(event)
175  {
176  var id = $(this).attr('id');
177  var idArray = id.split('-');
178  $('.business-card:visible').hide();
179  $('li.selectedDupe').removeClass('selected');
180  $(this).addClass('selected');
181  $('#dupeDetailsView-' + idArray[1]).show();
182  });
183  $('body').on('change', '.dupeContactsPrimaryModel',
184  {$this->onChangeScript()}
185  );
186  ";
187  Yii::app()->clientScript->registerScript(__CLASS__ . '#selectedContactMouseOverEvents', $script);
188  }
189 
195  protected function onChangeScript()
196  {
197  throw new NotSupportedException();
198  }
199 
203  protected function getTitleBar()
204  {
205  return null;
206  }
207 
208  protected function getColorForDupe()
209  {
210  $color = array_shift($this->colorsArray);
211  $this->colorsArray[] = $color;
212  return $color;
213  }
214 
219  protected function resolveGraphsForChart(& $chart)
220  {
221  foreach ($this->dupeModels as $dupeModel)
222  {
223  $chart->addSerialGraph('model-' . $dupeModel->id,
224  'radar',
225  array('bullet' => "'round'",
226  'balloonText' => "'Quantity: [[value]]'",
227  'lineColor' => "'" . $this->getColorForDupe() . "'"
228  ));
229  }
230  }
231 
236  protected function resolveDataForChart(& $chart)
237  {
238  $notes = array('category' => NotesModule::getModuleLabelByTypeAndLanguage('Plural'));
239  $tasks = array('category' => TasksModule::getModuleLabelByTypeAndLanguage('Plural'));
240  $emails = array('category' => EmailMessagesModule::getModuleLabelByTypeAndLanguage('Plural'));
241  $meetings = array('category' => MeetingsModule::getModuleLabelByTypeAndLanguage('Plural'));
242  foreach ($this->dupeModels as $dupeModel)
243  {
244  $itemId = $dupeModel->getClassId('Item');
245  $notes ['model-' . $dupeModel->id] = LatestActivitiesUtil::
246  getCountByModelClassName('Note', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
247  $tasks ['model-' . $dupeModel->id] = LatestActivitiesUtil::
248  getCountByModelClassName('Task', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
249  $emails ['model-' . $dupeModel->id] = LatestActivitiesUtil::
250  getCountByModelClassName('EmailMessage', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
251  $meetings['model-' . $dupeModel->id] = LatestActivitiesUtil::
252  getCountByModelClassName('Meeting', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
253  }
254  $chart->data = array($notes, $tasks, $emails, $meetings);
255  }
256 
257  protected function renderActivitiesTotals($model)
258  {
259  $itemId = $model->getClassId('Item');
260  $icon = ZurmoHtml::tag('i', array('class' => 'icon-note'), '');
261  $title = Zurmo::t('NotesModule', 'Notes');
262  $num = ZurmoHtml::tag('strong', array(),
263  DedupesActivitiesUtil::getCountByModelClassName('Note', array($itemId),
264  LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL));
265  $notesTotalContent = ZurmoHtml::tag('span', array('class' => 'total-notes'), $icon . $num . ' ' . $title);
266 
267  $icon = ZurmoHtml::tag('i', array('class' => 'icon-task'), '');
268  $title = Zurmo::t('TasksModule', 'Tasks');
269  $num = ZurmoHtml::tag('strong', array(),
270  DedupesActivitiesUtil::getCountByModelClassName('Task', array($itemId),
271  LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL));
272  $tasksTotalContent = ZurmoHtml::tag('span', array('class' => 'total-tasks'), $icon . $num . ' ' . $title);
273 
274  $icon = ZurmoHtml::tag('i', array('class' => 'icon-email'), '');
275  $title = Zurmo::t('ZurmoModule', 'Emails');
276  $num = ZurmoHtml::tag('strong', array(),
277  DedupesActivitiesUtil::getCountByModelClassName('EmailMessage', array($itemId),
278  LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL));
279  $emailsTotalContent = ZurmoHtml::tag('span', array('class' => 'total-emails'), $icon . $num . ' ' . $title);
280 
281  $icon = ZurmoHtml::tag('i', array('class' => 'icon-meeting'), '');
282  $title = Zurmo::t('MeetingsModule', 'Meetings');
283  $num = ZurmoHtml::tag('strong', array(),
284  DedupesActivitiesUtil::getCountByModelClassName('Meeting', array($itemId),
285  LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL));
286  $meetingsTotalContent = ZurmoHtml::tag('span', array('class' => 'total-meetings'), $icon . $num . ' ' . $title);
287 
288  $content = $notesTotalContent . $tasksTotalContent . $emailsTotalContent . $meetingsTotalContent;
289  $label = Zurmo::t('ZurmoModule', "This {moduleLabel} has:",
290  array('{moduleLabel}' => $this->resolveRealModuleClassNameLabelByModel($model)));
291  $title = ZurmoHtml::tag('h3', array(), $label);
292  return ZurmoHtml::tag('div', array('class' => 'entry-stats'), $title . $content);
293  }
294 
295  protected function resolveRealModuleClassNameLabelByModel(RedBeanModel $model)
296  {
297  $moduleClassName = $model::getModuleClassName();
298  $stateMetadataAdapterClassName = $moduleClassName:: getStateMetadataAdapterClassName();
299  if ($stateMetadataAdapterClassName != null)
300  {
301  $moduleClassName = $stateMetadataAdapterClassName::getModuleClassNameByModel($model);
302  }
303  return $moduleClassName::getModuleLabelByTypeAndLanguage("Singular");
304  }
305 
306  protected function renderRadioButtonContent($dupeModel)
307  {
308  $checked = !strcmp($dupeModel->id, $this->model->id);
309  return ZurmoHtml::radioButton('primaryModelId', $checked,
310  array('id' => 'primaryModelId-' . $dupeModel->id,
311  'class' => 'dupeContactsPrimaryModel',
312  'value' => $dupeModel->id
313  ), null);
314  }
315 
316  protected function renderBeforeListContent()
317  {
318  return ZurmoHtml::tag('li', array(), Zurmo::t('ZurmoModule', 'Primary'));
319  }
320  }
321 ?>
Definition: User.php:37
Generated on Fri Jul 10 2020 07:10:37
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.