Exemplo n.º 1
0
 /**
  * Create or edit a form.
  *
  * @param array $variables
  */
 public function actionEditForm(array $variables = array())
 {
     // Do we have a form model?
     if (!isset($variables['form'])) {
         // Get form if available
         if (!empty($variables['formId'])) {
             $variables['form'] = craft()->amForms_forms->getFormById($variables['formId']);
             if (!$variables['form']) {
                 throw new Exception(Craft::t('No form exists with the ID “{id}”.', array('id' => $variables['formId'])));
             }
         } else {
             $variables['form'] = new AmForms_FormModel();
         }
     }
     // Fields per set setting
     $fieldsPerSet = craft()->amForms_settings->getSettingsByHandleAndType('fieldsPerSet', AmFormsModel::SettingGeneral);
     $fieldsPerSet = $fieldsPerSet && is_numeric($fieldsPerSet->value) ? (int) $fieldsPerSet->value : 8;
     // Get available fields with our context
     $groupId = 1;
     $counter = 1;
     $variables['groups'] = array();
     $fields = craft()->fields->getAllFields('id', AmFormsModel::FieldContext);
     foreach ($fields as $field) {
         if ($counter % $fieldsPerSet == 1) {
             $groupId++;
             $counter = 1;
         }
         $variables['groups'][$groupId]['fields'][] = $field;
         $counter++;
     }
     // Get redirectEntryId elementType
     $variables['entryElementType'] = craft()->elements->getElementType(ElementType::Entry);
     // Get available attributes
     $variables['availableAttributes'] = array();
     $submission = new AmForms_SubmissionModel();
     $ignoreAttributes = array('slug', 'uri', 'root', 'lft', 'rgt', 'level', 'searchScore', 'localeEnabled', 'archived', 'spamFree');
     foreach ($submission->getAttributes() as $attribute => $value) {
         if (!in_array($attribute, $ignoreAttributes)) {
             $variables['availableAttributes'][] = $attribute;
         }
     }
     foreach ($fields as $field) {
         $variables['availableAttributes'][] = $field['handle'];
     }
     $this->renderTemplate('amforms/forms/_edit', $variables);
 }
 /**
  * Get submission email body.
  *
  * @param AmForms_SubmissionModel $submission
  *
  * @return string
  */
 public function getSubmissionEmailBody(AmForms_SubmissionModel $submission)
 {
     // Get form if not already set
     $submission->getForm();
     $form = $submission->form;
     // Get email body
     $variables = array('tabs' => $form->getFieldLayout()->getTabs(), 'form' => $form, 'submission' => $submission);
     return craft()->amForms->renderDisplayTemplate('email', $form->notificationTemplate, $variables);
 }
 /**
  * Do redirect with {placeholders} support.
  *
  * @param AmForms_SubmissionModel $submission
  * @param boolean $submitted
  */
 private function _doRedirect(AmForms_SubmissionModel $submission, $submitted)
 {
     $vars = array_merge(array('siteUrl' => craft()->getSiteUrl(), 'submitted' => $submitted), $submission->getContent()->getAttributes(), $submission->getAttributes());
     $url = null;
     $redirectUrl = $submission->getForm()->getRedirectUrl();
     if (empty($redirectUrl)) {
         $url = craft()->request->getPath() . '?submitted=' . ($submitted ? $submission->getForm()->handle : 0);
     }
     $this->redirectToPostedUrl($vars, $url);
 }
 /**
  * Populates an element model based on a query result.
  *
  * @param array $row
  *
  * @return array
  */
 public function populateElementModel($row)
 {
     return AmForms_SubmissionModel::populateModel($row);
 }