public function getFormFieldFromEditableFormField(EditableFormField $fieldRecord)
 {
     $field = $fieldRecord->getFormField();
     // Remove templates added by EditableFormField
     $field->setFieldHolderTemplate(null);
     $field->setTemplate(null);
     // Simplify dropdown to only have options that are used
     if ($field->hasMethod('getSource')) {
         $source = $field->getSource();
         $availableSources = SubmittedFormField::get()->filter(array('ParentID' => $this->controller->data()->PublishedSubmittedFormIDs(), 'Name' => $fieldRecord->Name, 'Value' => array_keys($source)))->column('Value');
         if (!$availableSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $newSources = array();
         foreach ($availableSources as $value) {
             if (isset($source[$value])) {
                 $newSources[$value] = $source[$value];
             }
         }
         if (!$newSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $field->setSource($newSources);
     }
     if ($field->hasMethod('setHasEmptyDefault') && ($dropdownEmptyString = $this->config()->dropdown_empty_string)) {
         // Defaults to '- Please select -', configured above.
         $field->setEmptyString($dropdownEmptyString);
     }
     // Attach EditableFormField to differentiate EditableFormField fields from regular ones
     // in the form.
     $field->EditableFormField = $fieldRecord;
     return $field;
 }
示例#2
0
 /**
  * Returns the value of a relation or, in the case of this form, the value
  * of a given child {@link SubmittedFormField}
  * 
  * @param string
  * 
  * @return mixed
  */
 public function relField($fieldName)
 {
     // default case
     if ($value = parent::relField($fieldName)) {
         return $value;
     }
     // check values for a form field with the matching name.
     $formField = SubmittedFormField::get()->filter(array('ParentID' => $this->ID, 'Name' => $fieldName))->first();
     if ($formField) {
         return $formField->getFormattedValue();
     }
 }
 /**
  * Return an array containing the amount of submissions for each options
  *
  * @return array
  */
 public function data()
 {
     if (!$this->Field()->exists() || !$this->Consultation()->Submissions()->count() > 0) {
         return;
     }
     $results = [];
     $options = $this->Field()->Options();
     foreach ($options as $option) {
         $result = SubmittedFormField::get()->filter(array('ParentID' => $this->Consultation()->Submissions()->column('ID')))->filterAny(array('Value' => $option->Title, 'Value:PartialMatch' => $option->Title));
         $optionResult = [];
         $optionResult['Label'] = $option->Title;
         $optionResult['Value'] = $result->count();
         $results[] = $optionResult;
     }
     return $results;
 }
 public function updateDBFromSubmission()
 {
     if ($this->__HasUpdatedDBFromSubmission) {
         return;
     }
     $this->__HasUpdatedDBFromSubmission = true;
     $submission = $this->owner->Submission();
     if (!$submission || !$submission->exists()) {
         return;
     }
     $holderPage = $submission->Parent();
     if (!$holderPage || !$holderPage->exists()) {
         return;
     }
     // Update content field
     $content_field = $this->owner->stat('content_field');
     if ($content_field && $this->owner->hasDatabaseField($content_field)) {
         $contentValue = $this->owner->{$content_field};
         $templatePageMarkup = $this->owner->TemplatePageMarkup();
         if ($templatePageMarkup instanceof HTMLText) {
             $templatePageMarkup = $templatePageMarkup->getValue();
         }
         if ($contentValue != $templatePageMarkup) {
             $this->owner->{$content_field} = $templatePageMarkup;
         }
     }
     // Update title fields (defaults to $Title/$MenuTitle)
     $title_fields = $this->owner->stat('title_fields');
     if ($title_fields) {
         // Get form field name to use. ie. $EditableTextField_6746f
         $fieldName = $holderPage->SubmissionPageTitleField;
         if ($fieldName) {
             // Only set the value if they aren't equal. This ensures
             // that changed fields isn't updated with an identical value.
             $formFieldValue = SubmittedFormField::get()->filter(array('ParentID' => $submission->ID, 'Name' => $fieldName))->first();
             if ($formFieldValue) {
                 $title = $formFieldValue->Value;
                 if ($title !== null) {
                     $title = (string) $title;
                     foreach ($title_fields as $fieldName) {
                         if ($this->owner->hasDatabaseField($fieldName) && $this->owner->{$fieldName} !== $title) {
                             $this->owner->{$fieldName} = $title;
                         }
                     }
                 }
             }
         }
     }
 }