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
00037 class AccountAccountAffiliationsRelatedListView extends SecuredRelatedListView
00038 {
00039 public static function getDefaultMetadata()
00040 {
00041 $metadata = array(
00042 'perUser' => array(
00043 'title' => "eval:Zurmo::t('AccountAccountAffiliationsModule',
00044 'AccountsModuleSingularLabel Affiliations', LabelUtil::getTranslationParamsForAllModules())",
00045 ),
00046 'global' => array(
00047 'toolbar' => array(
00048 'elements' => array(
00049 array( 'type' => 'CreateFromRelatedListLink',
00050 'routeModuleId' => 'eval:$this->moduleId',
00051 'routeParameters' => 'eval:$this->getCreateLinkRouteParametersForPrimaryAccount()',
00052 'label' => 'eval:$this->getSelectPrimaryAccountLinkLabel()',
00053 ),
00054 array( 'type' => 'CreateFromRelatedListLink',
00055 'routeModuleId' => 'eval:$this->moduleId',
00056 'routeParameters' => 'eval:$this->getCreateLinkRouteParametersForSecondaryAccount()',
00057 'label' => 'eval:$this->getSelectSecondaryAccountLinkLabel()',
00058 ),
00059 ),
00060 ),
00061 'rowMenu' => array(
00062 'elements' => array(
00063 array('type' => 'EditLink'),
00064 array('type' => 'RelatedDeleteLink'),
00065 ),
00066 ),
00067 'derivedAttributeTypes' => array(
00068 'AccountAccountAffiliationOppositeModel',
00069 ),
00070 'gridViewType' => RelatedListView::GRID_VIEW_TYPE_STACKED,
00071 'panels' => array(
00072 array(
00073 'rows' => array(
00074 array('cells' =>
00075 array(
00076 array(
00077 'elements' => array(
00078 array('attributeName' => 'null',
00079 'type' => 'AccountAccountAffiliationOppositeModel'),
00080 ),
00081 ),
00082 )
00083 ),
00084 ),
00085 ),
00086 ),
00087 ),
00088 );
00089 return $metadata;
00090 }
00091
00095 protected function makeSearchAttributeData()
00096 {
00097 $searchAttributeData = array();
00098 $searchAttributeData['clauses'] = array(
00099 1 => array(
00100 'attributeName' => 'primaryAccount',
00101 'relatedAttributeName' => 'id',
00102 'operatorType' => 'equals',
00103 'value' => (int)$this->params['relationModel']->id,
00104 ),
00105 2 => array(
00106 'attributeName' => 'secondaryAccount',
00107 'relatedAttributeName' => 'id',
00108 'operatorType' => 'equals',
00109 'value' => (int)$this->params['relationModel']->id,
00110 )
00111 );
00112 $searchAttributeData['structure'] = '(1 or 2)';
00113 return $searchAttributeData;
00114 }
00115
00116 protected function getCreateLinkRouteParametersForPrimaryAccount()
00117 {
00118 return array(
00119 'relationAttributeName' => 'secondaryAccount',
00120 'relationModelId' => $this->params['relationModel']->id,
00121 'relationModuleId' => $this->params['relationModuleId'],
00122 'redirectUrl' => $this->params['redirectUrl'],
00123 );
00124 }
00125
00126 protected function getCreateLinkRouteParametersForSecondaryAccount()
00127 {
00128 return array(
00129 'relationAttributeName' => 'primaryAccount',
00130 'relationModelId' => $this->params['relationModel']->id,
00131 'relationModuleId' => $this->params['relationModuleId'],
00132 'redirectUrl' => $this->params['redirectUrl'],
00133 );
00134 }
00135
00136 protected function getSelectPrimaryAccountLinkLabel()
00137 {
00138 return AccountAccountAffiliationsModule::resolveAccountRelationLabel('Singular', 'primary');
00139 }
00140
00141 protected function getSelectSecondaryAccountLinkLabel()
00142 {
00143 return AccountAccountAffiliationsModule::resolveAccountRelationLabel('Singular', 'secondary');
00144 }
00145
00151 protected function getRelationAttributeName()
00152 {
00153 return 'notUsed';
00154 }
00155
00156 public static function getAllowedOnPortletViewClassNames()
00157 {
00158 return array('AccountDetailsAndRelationsView');
00159 }
00160
00161 public static function getModuleClassName()
00162 {
00163 return 'AccountAccountAffiliationsModule';
00164 }
00165
00166 protected function getEmptyText()
00167 {
00168 return Zurmo::t('AccountContactAffiliationsModule',
00169 'No AccountsModuleSingularLowerCaseLabel affiliations found',
00170 LabelUtil::getTranslationParamsForAllModules());
00171 }
00172
00177 public static function getPortletRulesType()
00178 {
00179 return 'AccountAccountAffiliationsRelatedList';
00180 }
00181
00182 public function renderPortletHeadContent()
00183 {
00184 return $this->renderActionContent();
00185 }
00186
00187 protected function renderActionContent()
00188 {
00189 $actionElementContent = $this->renderActionElementMenu(Zurmo::t('Core', 'Create'));
00190 $content = null;
00191 if ($actionElementContent != null)
00192 {
00193 $content .= '<div class="view-toolbar-container toolbar-mbmenu clearfix"><div class="view-toolbar">';
00194 $content .= $actionElementContent;
00195 $content .= '</div></div>';
00196 }
00197 return $content;
00198 }
00199
00200 public function getOppositeModelListViewString()
00201 {
00202 return 'AccountAccountAffiliationsRelatedListView::' .
00203 'resolveOpposingAccountLinkContent($data, ' . (int)$this->params["relationModel"]->id . ')';
00204 }
00205
00206 public static function resolveOpposingAccountLinkContent(AccountAccountAffiliation $accountAccountAffiliation, $accountId)
00207 {
00208 assert('is_int($accountId)');
00209 if ($accountAccountAffiliation->primaryAccount->id == $accountId)
00210 {
00211 $content = static::resolveAccountWithLinkContent($accountAccountAffiliation->secondaryAccount);
00212 $content .= ' ' . $accountAccountAffiliation->getAttributeLabel('secondaryAccount');
00213 }
00214 else
00215 {
00216 $content = static::resolveAccountWithLinkContent($accountAccountAffiliation->primaryAccount);
00217 $content .= ' ' . $accountAccountAffiliation->getAttributeLabel('primaryAccount');
00218 }
00219 return $content;
00220 }
00221
00226 public static function resolveAccountWithLinkContent(Account $account)
00227 {
00228 if (ActionSecurityUtil::canCurrentUserPerformAction('Details', $account))
00229 {
00230 $moduleClassName = $account->getModuleClassName();
00231 $linkRoute = '/' . $moduleClassName::getDirectoryName() . '/default/details';
00232 $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser(strval($account), $account,
00233 $moduleClassName, $linkRoute);
00234 if ($link != null)
00235 {
00236 $linkContent = $link;
00237 }
00238 return ZurmoHtml::tag('div', array(), $linkContent);
00239 }
00240 }
00241 }
00242 ?>