public function testCreateAndGetContactWebFormById() { $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); $this->assertTrue(ContactsModule::loadStartingData()); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = 'Test Form'; $contactWebForm->redirectUrl = 'http://google.com'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->serializedData = serialize($attributes); $contactWebForm->defaultOwner = Yii::app()->user->userModel; $this->assertTrue($contactWebForm->save()); $id = $contactWebForm->id; unset($contactWebForm); $contactWebForm = ContactWebForm::getById($id); $this->assertEquals('Test Form', $contactWebForm->name); $this->assertEquals('http://google.com', $contactWebForm->redirectUrl); $this->assertEquals('Save', $contactWebForm->submitButtonLabel); $this->assertEquals('New', $contactWebForm->defaultState->name); $this->assertEquals($attributes, unserialize($contactWebForm->serializedData)); }
public static function getContactWebFormAttributes() { $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); return $attributes; }
public function testCreateAndGetContactWebFormEntryById() { $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); $this->assertTrue(ContactsModule::loadStartingData()); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = 'Test Form'; $contactWebForm->redirectUrl = 'http://google.com'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->defaultOwner = Yii::app()->user->userModel; $contactWebForm->serializedData = serialize($attributes); $contactWebForm->save(); $contact = new Contact(); $contact->owner = $contactWebForm->defaultOwner; $contact->state = $contactWebForm->defaultState; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->jobTitle = 'Superhero'; $contact->companyName = 'Test Inc.'; if ($contact->validate()) { $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_SUCCESS; $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_SUCCESS_MESSAGE; } else { $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_ERROR; $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_ERROR_MESSAGE; } $contact->save(); foreach ($contactFormAttributes as $attributeName => $attributeValue) { $contactFormAttributes[$attributeName] = $contact->{$attributeName}; } $contactFormAttributes['owner'] = $contactWebForm->defaultOwner->id; $contactFormAttributes['state'] = $contactWebForm->defaultState->id; $contactWebFormEntry = new ContactWebFormEntry(); $contactWebFormEntry->serializedData = serialize($contactFormAttributes); $contactWebFormEntry->status = $contactWebFormEntryStatus; $contactWebFormEntry->message = $contactWebFormEntryMessage; $contactWebFormEntry->contactWebForm = $contactWebForm; $contactWebFormEntry->contact = $contact; $this->assertTrue($contactWebFormEntry->save()); $contactWebFormEntryId = $contactWebFormEntry->id; unset($contactWebFormEntry); $contactWebFormEntry = ContactWebFormEntry::getById($contactWebFormEntryId); $this->assertEquals('Test Form', $contactWebFormEntry->contactWebForm->name); $this->assertEquals('Super', $contactWebFormEntry->contact->firstName); $this->assertEquals('Man', $contactWebFormEntry->contact->lastName); $contactFormAttributes = unserialize($contactWebFormEntry->serializedData); $this->assertEquals('Super', $contactFormAttributes['firstName']); $this->assertEquals('Man', $contactFormAttributes['lastName']); $this->assertEquals('Superhero', $contactFormAttributes['jobTitle']); $this->assertEquals('Test Inc.', $contactFormAttributes['companyName']); }
/** * @param Contact $contact * @return string */ public static function resolveModuleIdWithLinkContentForContactOrLead(Contact $contact) { $linkContent = null; if (ActionSecurityUtil::canCurrentUserPerformAction('Details', $contact)) { $moduleClassName = $contact->getModuleClassName(); $moduleId = ContactWebFormsUtil::getResolvedModuleIdForContactWebFormEntry($contact); $linkRoute = '/' . $moduleId . '/default/details'; $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser(strval($contact), $contact, $moduleClassName, $linkRoute); if ($link != null) { $linkContent = $link; } return ZurmoHtml::tag('div', array(), $linkContent); } }
/** * @return string */ protected function renderControlEditable() { $attributes = ContactWebFormsUtil::getAllAttributes(); $contactWebFormAttributes = array(); if (isset($this->model->serializedData)) { $contactWebFormAttributes = unserialize($this->model->serializedData); } $clip = $this->form->checkBoxList($this->model, $this->attribute, ContactWebFormsUtil::getAllNonPlacedAttributes($attributes, $contactWebFormAttributes), $this->getEditableHtmlOptions()); $title = ZurmoHtml::tag('h3', array(), Zurmo::t('ContactWebFormModule', 'Available Fields')); $content = ZurmoHtml::tag('span', array('class' => 'row-description'), Zurmo::t('ContactWebFormModule', 'Check the fields that you like to add to your form, you can then change their order or remove them')); $content .= ZurmoHtml::tag('div', array('class' => 'third'), $title . $clip); $cClipWidget = new CClipWidget(); $cClipWidget->beginClip("attributesList"); $cClipWidget->widget('application.core.widgets.JuiSortable', array('itemTemplate' => $this->renderItemTemplate(), 'items' => ContactWebFormsUtil::getAllPlacedAttributes($attributes, $contactWebFormAttributes))); $cClipWidget->endClip(); $clip = $cClipWidget->getController()->clips['attributesList']; $title = ZurmoHtml::tag('h3', array(), Zurmo::t('ContactWebFormModule', 'Chosen Fields')); $content .= ZurmoHtml::tag('div', array('class' => 'twoThirds'), $title . $clip); $this->registerScript(); return $content; }
public function testGetEmbedScript() { $embedScript = ContactWebFormsUtil::getEmbedScript(1); $this->assertNotEmpty($embedScript); $this->assertTrue(strpos($embedScript, 'zurmoExternalWebForm') !== false); }
/** * @param RedBeanModel $model */ public function populateModel(&$model) { assert('$model instanceof ContactWebForm'); parent::populateModel($model); if (empty($this->seedData)) { $this->seedData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('ContactWebFormsModule', 'ContactWebForm'); } $model->name = $this->seedData['name'][$this->index]; $model->redirectUrl = $this->seedData['redirectUrl'][$this->index]; $model->submitButtonLabel = $this->seedData['submitButtonLabel'][$this->index]; $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); $model->serializedData = serialize($attributes); }
public function testGetEmbedScript() { $embedScript = ContactWebFormsUtil::getEmbedScript(1); $this->assertNotEmpty($embedScript); $this->assertContains('zurmoExternalWebForm', $embedScript); }
public static function getMetadataByWebForm(ContactWebForm $contactWebForm) { assert('$contactWebForm instanceof ContactWebForm'); $contactWebFormAttributes = array_keys(ContactWebFormsUtil::getPlacedAttributes($contactWebForm)); $contactWebFormAttributes = ContactWebFormsUtil::excludeHiddenAttributes($contactWebForm, $contactWebFormAttributes); $viewClassName = 'ContactExternalEditAndDetailsView'; $moduleClassName = 'ContactsModule'; $modelClassName = $moduleClassName::getPrimaryModelName(); $editableMetadata = $viewClassName::getMetadata(); $designerRules = new EditAndDetailsViewDesignerRules(); $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName); $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName); $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(), $derivedAttributesAdapter->getAttributes()); $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($attributeCollection, $designerRules, $editableMetadata); $layoutMetadataAdapter = new LayoutMetadataAdapter($viewClassName, $moduleClassName, $editableMetadata, $designerRules, $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()); $metadata = $layoutMetadataAdapter->resolveMetadataFromSelectedListAttributes($viewClassName, $contactWebFormAttributes); foreach ($metadata['global']['panels'][0]['rows'] as $index => $data) { if ($data['cells'][0]['elements'][0]['type'] == 'EmailAddressInformation') { $metadata['global']['panels'][0]['rows'][$index]['cells'][0]['elements'][0]['hideOptOut'] = true; } if ($data['cells'][0]['elements'][0]['type'] == 'TagCloud') { $metadata['global']['panels'][0]['rows'][$index]['cells'][0]['elements'][0]['type'] = 'MultiSelectDropDown'; } } return $metadata; }
/** * @param $postVariableName * @param $contactWebForm */ public static function resolveHiddenAttributesForContactModel($postVariableName, ContactWebForm $contactWebForm) { $ContactWebFormAttributes = unserialize($contactWebForm->serializedData); foreach ($ContactWebFormAttributes as $attributeName => $attribute) { if (isset($attribute['hidden']) && $attribute['hidden'] == true && isset($attribute['hiddenValue']) && !empty($attribute['hiddenValue'])) { $dropDownAttributeTypes = array('CheckBox', 'RadioDropDown', 'DropDown'); $allAttributes = ContactWebFormsUtil::getAllAttributes(); $attributeData = $allAttributes[$attributeName]; if (in_array($attributeData['elementType'], $dropDownAttributeTypes)) { $_POST[$postVariableName][$attributeName]['value'] = $attribute['hiddenValue']; } else { $_POST[$postVariableName][$attributeName] = $attribute['hiddenValue']; } } } }
/** * @return string */ protected function renderItemTemplate() { $attributeData = array(); $attributeData['{attributeName}'] = '{id}'; $attributeData['{isRequiredElement}'] = '{isRequiredElement}'; $attributeData['{isHiddenElement}'] = '{isHiddenElement}'; $attributeData['{attributeLabelElement}'] = '{attributeLabelElement}'; $attributeData['{hideHiddenAttributeElementStyle}'] = '{hideHiddenAttributeElementStyle}'; $attributeData['{renderHiddenAttributeElement}'] = '{renderHiddenAttributeElement}'; $attributeData['{removePlacedAttributeLink}'] = '{removePlacedAttributeLink}'; $content = ContactWebFormsUtil::getPlacedAttributeContent($attributeData); return $content; }
public function actionGetPlacedAttributeByName($attributeName, $attributeLabel) { $model = new ZurmoActiveForm(false); $webFormAttributeForm = new ContactWebFormAttributeForm(); $webFormAttributeForm->label = $attributeLabel; $allAttributes = ContactWebFormsUtil::getAllAttributes(); $attributeData = $allAttributes[$attributeName]; $resolvedPlacedAttribute = ContactWebFormsUtil::resolvePlacedAttributeByName($webFormAttributeForm, $model, $attributeName, $attributeData); $content = ContactWebFormsUtil::getPlacedAttributeContent($resolvedPlacedAttribute); Yii::app()->getClientScript()->setToAjaxMode(); Yii::app()->getClientScript()->render($content); echo $content; }
public static function resolveWebFormWithAllRequiredAttributes($contactWebFormAttributes) { $attributes = ContactWebFormsUtil::getAllAttributes(); foreach ($attributes as $attributeName => $attributeData) { if (!$attributeData['isReadOnly'] && $attributeData['isRequired'] && !in_array($attributeName, $contactWebFormAttributes)) { $contactWebFormAttributes[] = $attributeName; } } return $contactWebFormAttributes; }