All Data Structures Functions Variables Pages
AccountAccountAffiliationsRelatedListView.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 
38  {
39  public static function getDefaultMetadata()
40  {
41  $metadata = array(
42  'perUser' => array(
43  'title' => "eval:Zurmo::t('AccountAccountAffiliationsModule',
44  'AccountsModuleSingularLabel Affiliations', LabelUtil::getTranslationParamsForAllModules())",
45  ),
46  'global' => array(
47  'toolbar' => array(
48  'elements' => array(
49  array( 'type' => 'CreateFromRelatedListLink',
50  'routeModuleId' => 'eval:$this->moduleId',
51  'routeParameters' => 'eval:$this->getCreateLinkRouteParametersForPrimaryAccount()',
52  'label' => 'eval:$this->getSelectPrimaryAccountLinkLabel()',
53  ),
54  array( 'type' => 'CreateFromRelatedListLink',
55  'routeModuleId' => 'eval:$this->moduleId',
56  'routeParameters' => 'eval:$this->getCreateLinkRouteParametersForSecondaryAccount()',
57  'label' => 'eval:$this->getSelectSecondaryAccountLinkLabel()',
58  ),
59  ),
60  ),
61  'rowMenu' => array(
62  'elements' => array(
63  array('type' => 'EditLink'),
64  array('type' => 'RelatedDeleteLink'),
65  ),
66  ),
67  'derivedAttributeTypes' => array(
68  'AccountAccountAffiliationOppositeModel',
69  ),
70  'gridViewType' => RelatedListView::GRID_VIEW_TYPE_STACKED,
71  'panels' => array(
72  array(
73  'rows' => array(
74  array('cells' =>
75  array(
76  array(
77  'elements' => array(
78  array('attributeName' => 'null',
79  'type' => 'AccountAccountAffiliationOppositeModel'),
80  ),
81  ),
82  )
83  ),
84  ),
85  ),
86  ),
87  ),
88  );
89  return $metadata;
90  }
91 
95  protected function makeSearchAttributeData()
96  {
97  $searchAttributeData = array();
98  $searchAttributeData['clauses'] = array(
99  1 => array(
100  'attributeName' => 'primaryAccount',
101  'relatedAttributeName' => 'id',
102  'operatorType' => 'equals',
103  'value' => (int)$this->params['relationModel']->id,
104  ),
105  2 => array(
106  'attributeName' => 'secondaryAccount',
107  'relatedAttributeName' => 'id',
108  'operatorType' => 'equals',
109  'value' => (int)$this->params['relationModel']->id,
110  )
111  );
112  $searchAttributeData['structure'] = '(1 or 2)';
113  return $searchAttributeData;
114  }
115 
116  protected function getCreateLinkRouteParametersForPrimaryAccount()
117  {
118  return array(
119  'relationAttributeName' => 'secondaryAccount',
120  'relationModelId' => $this->params['relationModel']->id,
121  'relationModuleId' => $this->params['relationModuleId'],
122  'redirectUrl' => $this->params['redirectUrl'],
123  );
124  }
125 
126  protected function getCreateLinkRouteParametersForSecondaryAccount()
127  {
128  return array(
129  'relationAttributeName' => 'primaryAccount',
130  'relationModelId' => $this->params['relationModel']->id,
131  'relationModuleId' => $this->params['relationModuleId'],
132  'redirectUrl' => $this->params['redirectUrl'],
133  );
134  }
135 
136  protected function getSelectPrimaryAccountLinkLabel()
137  {
138  return AccountAccountAffiliationsModule::resolveAccountRelationLabel('Singular', 'primary');
139  }
140 
141  protected function getSelectSecondaryAccountLinkLabel()
142  {
143  return AccountAccountAffiliationsModule::resolveAccountRelationLabel('Singular', 'secondary');
144  }
145 
151  protected function getRelationAttributeName()
152  {
153  return 'notUsed';
154  }
155 
156  public static function getAllowedOnPortletViewClassNames()
157  {
158  return array('AccountDetailsAndRelationsView');
159  }
160 
161  public static function getModuleClassName()
162  {
163  return 'AccountAccountAffiliationsModule';
164  }
165 
166  protected function getEmptyText()
167  {
168  return Zurmo::t('AccountContactAffiliationsModule',
169  'No AccountsModuleSingularLowerCaseLabel affiliations found',
171  }
172 
177  public static function getPortletRulesType()
178  {
179  return 'AccountAccountAffiliationsRelatedList';
180  }
181 
182  public function renderPortletHeadContent()
183  {
184  return $this->renderActionContent();
185  }
186 
187  protected function renderActionContent()
188  {
189  $actionElementContent = $this->renderActionElementMenu(Zurmo::t('Core', 'Create'));
190  $content = null;
191  if ($actionElementContent != null)
192  {
193  $content .= '<div class="view-toolbar-container toolbar-mbmenu clearfix"><div class="view-toolbar">';
194  $content .= $actionElementContent;
195  $content .= '</div></div>';
196  }
197  return $content;
198  }
199 
200  public function getOppositeModelListViewString()
201  {
202  return 'AccountAccountAffiliationsRelatedListView::' .
203  'resolveOpposingAccountLinkContent($data, ' . (int)$this->params["relationModel"]->id . ')';
204  }
205 
206  public static function resolveOpposingAccountLinkContent(AccountAccountAffiliation $accountAccountAffiliation, $accountId)
207  {
208  assert('is_int($accountId)');
209  if ($accountAccountAffiliation->primaryAccount->id == $accountId)
210  {
211  $content = static::resolveAccountWithLinkContent($accountAccountAffiliation->secondaryAccount);
212  $content .= ' ' . $accountAccountAffiliation->getAttributeLabel('secondaryAccount');
213  }
214  else
215  {
216  $content = static::resolveAccountWithLinkContent($accountAccountAffiliation->primaryAccount);
217  $content .= ' ' . $accountAccountAffiliation->getAttributeLabel('primaryAccount');
218  }
219  return $content;
220  }
221 
226  public static function resolveAccountWithLinkContent(Account $account)
227  {
228  if (ActionSecurityUtil::canCurrentUserPerformAction('Details', $account))
229  {
230  $moduleClassName = $account->getModuleClassName();
231  $linkRoute = '/' . $moduleClassName::getDirectoryName() . '/default/details';
232  $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser(strval($account), $account,
233  $moduleClassName, $linkRoute);
234  if ($link != null)
235  {
236  $linkContent = $link;
237  }
238  return ZurmoHtml::tag('div', array(), $linkContent);
239  }
240  }
241  }
242 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
renderActionElementMenu($title=null, $toolbar= 'toolbar')
static canCurrentUserPerformAction($actionType, $model)
static resolveLinkToModelForCurrentUser($attributeString, $model, $moduleClassName, $linkRoute, $offset=null, $additionalParams=array())
getAttributeLabel($attributeName)
Generated on Sat Jun 6 2020 07:10:29