Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 3
0
 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']);
 }
Ejemplo n.º 4
0
 public function testGetAttributes()
 {
     $allAttributes = ContactWebFormsUtil::getAllAttributes();
     $this->assertNotEmpty($allAttributes);
     $allPlacedAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes);
     $allNonPlacedAttributes = ContactWebFormsUtil::getAllNonPlacedAttributes($allAttributes);
     $this->assertTrue(count($allPlacedAttributes) < count($allNonPlacedAttributes));
     $selectiveAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle');
     $allPlacedAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $selectiveAttributes);
     $this->assertEquals(count($selectiveAttributes), count($allPlacedAttributes));
 }
 /**
  * @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;
 }
 /**
  * @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);
 }