/** * @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 function testResolveFiltersForVariableStatesWithOneDisplayAttributeAndOneFilterForANonSuperUserWhoCanSeeOneState() { Yii::app()->user->userModel = User::getByUsername('sally'); $report = new Report(); $report->setType(Report::TYPE_ROWS_AND_COLUMNS); $report->setModuleClassName('AccountsModule'); $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS); $displayAttribute->attributeIndexOrDerivedType = 'contacts___officePhone'; $report->addDisplayAttribute($displayAttribute); $reportDataProvider = new RowsAndColumnsReportDataProvider($report); $filtersStructure = '1'; $filter = new FilterForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS); $filter->attributeIndexOrDerivedType = 'opportunities___contacts___website'; $filter->operator = OperatorRules::TYPE_EQUALS; $filter->value = 'Zurmo'; $filters = array($filter); $filters = $reportDataProvider->resolveFiltersForVariableStates($filters, $filtersStructure); $stateAdapter = new ContactsStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $this->assertTrue(count($stateAdapter->getStateIds()) > 0); $this->assertEquals(3, count($filters)); $this->assertEquals('contacts___state', $filters[1]->attributeIndexOrDerivedType); $this->assertEquals(OperatorRules::TYPE_ONE_OF, $filters[1]->operator); $this->assertEquals($stateAdapter->getStateIds(), $filters[1]->value); $this->assertEquals('opportunities___contacts___state', $filters[2]->attributeIndexOrDerivedType); $this->assertEquals(OperatorRules::TYPE_ONE_OF, $filters[2]->operator); $this->assertEquals($stateAdapter->getStateIds(), $filters[2]->value); $this->assertEquals('1 and (2 and 3)', $filtersStructure); }
public function testInferredRelationModelAttributeWithYetAnotherRelation() { Yii::app()->user->userModel = User::getByUsername('sally'); $stateAdapter = new ContactsStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $this->assertTrue(count($stateAdapter->getStateIds()) > 0); $filter = new FilterForReportForm('MeetingsModule', 'Meeting', Report::TYPE_ROWS_AND_COLUMNS); $filter->attributeIndexOrDerivedType = 'Account__activityItems__Inferred___contacts___officePhone'; $indexes = array(); VariableStatesForReportUtil::resolveAttributeIndexesByComponents($indexes, array($filter)); $this->assertEquals(array('Account__activityItems__Inferred___contacts___' => array('state', $stateAdapter->getStateIds())), $indexes); //Test with the super user. There shouldn't be any variable state data Yii::app()->user->userModel = User::getByUsername('super'); $filter = new FilterForReportForm('MeetingsModule', 'Meeting', Report::TYPE_ROWS_AND_COLUMNS); $filter->attributeIndexOrDerivedType = 'Account__activityItems__Inferred___contacts___name'; $indexes = array(); VariableStatesForReportUtil::resolveAttributeIndexesByComponents($indexes, array($filter)); $this->assertEquals(array(), $indexes); }
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); }
public function testContactStateAdapterReturnsCorrectStatesUponStartingStateChange() { $this->assertEquals(7, count(ContactState::GetAll())); $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = ContactsUtil::getStartingState()->id; ContactsModule::setMetadata($metadata); $metadata = array('clauses' => array(), 'structure' => ''); $adapter = new ContactsStateMetadataAdapter($metadata); $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata(); $statesToInclude = ContactsUtil::getContactStateDataFromStartingStateOnAndKeyedById(); $this->assertEquals(7, count($statesToInclude)); $compareMetadata['clauses'] = array(); $compareMetadata['structure'] = '(1 or 2 or 3 or 4 or 5 or 6 or 7)'; $index = 1; foreach ($statesToInclude as $stateId => $notUsed) { $compareMetadata['clauses'][$index] = array('attributeName' => 'state', 'operatorType' => 'equals', 'value' => $stateId); $index++; } $this->assertEquals($compareMetadata, $adaptedMetadata); }