Exemplo n.º 1
0
 /**
  * @param RedBeanModel $model
  * @return string
  */
 protected static function resolveModelContent(RedBeanModel $model)
 {
     $security = new DetailsActionSecurity(Yii::app()->user->userModel, $model);
     if ($security->canUserPerformAction()) {
         $params = array('label' => strval($model), 'wrapLabel' => false);
         if (get_class($model) == 'Contact') {
             $moduleClassName = ContactsStateMetadataAdapter::getModuleClassNameByModel($model);
         } else {
             $moduleClassName = $model->getModuleClassName();
         }
         $moduleId = $moduleClassName::getDirectoryName();
         $relatedModelElement = new DetailsLinkActionElement('default', $moduleId, $model->id, $params);
         return $relatedModelElement->render();
     }
 }
 public static function getRecipientsContent(RedBeanOneToManyRelatedModels $recipients, $type = null, $additionalParams = array())
 {
     assert('$type == null || $type == EmailMessageRecipient::TYPE_TO ||
                 EmailMessageRecipient::TYPE_CC || EmailMessageRecipient::TYPE_BCC');
     $existingModels = array();
     if ($recipients->count() == 0) {
         return;
     }
     foreach ($recipients as $recipient) {
         if ($type == null || $recipient->type == $type) {
             $existingPersonsOrAccounts = array();
             if ($recipient->personsOrAccounts->count() == 0) {
                 $existingPersonsOrAccounts[] = $recipient->toAddress . ' ' . $recipient->toName;
             } else {
                 foreach ($recipient->personsOrAccounts as $personOrAccount) {
                     try {
                         $castedDownModel = self::castDownItem($personOrAccount);
                         if (strval($castedDownModel) != null) {
                             $params = array('label' => strval($castedDownModel), 'wrapLabel' => false);
                             if (get_class($castedDownModel) == 'Contact') {
                                 $moduleClassName = ContactsStateMetadataAdapter::getModuleClassNameByModel($castedDownModel);
                             } else {
                                 $moduleClassName = $castedDownModel->getModuleClassName();
                             }
                             $moduleId = $moduleClassName::getDirectoryName();
                             $element = new DetailsLinkActionElement('default', $moduleId, $castedDownModel->id, array_merge($params, $additionalParams));
                             $existingPersonsOrAccounts[] = $element->render();
                         }
                     } catch (AccessDeniedSecurityException $e) {
                         $existingPersonsOrAccounts[] = $recipient->toAddress . ' ' . $recipient->toName;
                     } catch (NotSupportedException $e) {
                         //If the personOrAccount no longer exists or something else isn't right with the model
                         $existingPersonsOrAccounts[] = $recipient->toAddress . ' ' . $recipient->toName;
                     }
                 }
             }
             $recipientString = self::resolveStringValueModelsDataToStringContent($existingPersonsOrAccounts);
             if (count($existingPersonsOrAccounts) > 1) {
                 $existingModels[] = $recipient->toAddress . '(' . $recipientString . ')';
             } else {
                 $existingModels[] = $recipientString;
             }
         }
     }
     return self::resolveStringValueModelsDataToStringContent($existingModels);
 }