/**
  * Return all submissions in this category
  *
  * @return DataList || empty ArrayList
  */
 public function getSubmissions()
 {
     if ($consultations = $this->getConsultations() && $consultations->count() > 0) {
         return SubmittedForm::get()->filter(array('ParentID' => $list));
     }
     return new ArrayList();
 }
 /**
  * This action handles rendering the "finished" message, which is 
  * customizable by editing the ReceivedFormSubmission template.
  *
  * @return ViewableData
  */
 public function finished()
 {
     $submission = Session::get('userformssubmission' . $this->ID);
     if ($submission) {
         $submission = SubmittedForm::get()->byId($submission);
     }
     $referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
     if (!$this->DisableAuthenicatedFinishAction) {
         $formProcessed = Session::get('FormProcessed');
         if (!isset($formProcessed)) {
             return $this->redirect($this->Link() . $referrer);
         } else {
             $securityID = Session::get('SecurityID');
             // make sure the session matches the SecurityID and is not left over from another form
             if ($formProcessed != $securityID) {
                 // they may have disabled tokens on the form
                 $securityID = md5(Session::get('FormProcessedNum'));
                 if ($formProcessed != $securityID) {
                     return $this->redirect($this->Link() . $referrer);
                 }
             }
         }
         Session::clear('FormProcessed');
     }
     return $this->customise(array('Content' => $this->customise(array('Submission' => $submission, 'Link' => $referrer))->renderWith('ReceivedFormSubmission'), 'Form' => ''));
 }
 /**
  * Get all submission for all consultation
  */
 public static function getAllSubmissions()
 {
     $consultations = self::get()->column('ID');
     return SubmittedForm::get()->filter('ParentID', $consultations);
 }
 /**
  * Action called when you want to edit an existing form submission
  *
  * @return String
  */
 public function resume()
 {
     if ($this->request->param('ID')) {
         $id = (int) $this->request->param('ID');
         $resumeSubmission = SubmittedForm::get()->byID($id);
         // if we don't have a submit button, then we can assume it's safe to re-edit the form
         // as many times as we want, so the 'editable' check can ignore the Complete status
         if ($resumeSubmission && $resumeSubmission->isReEditable($this->data()->AllowEditingComplete)) {
             $this->submission = $resumeSubmission;
         }
     }
     return parent::index();
 }
 public function doSearch($data)
 {
     $userSubmissionHolder = $this->controller->data();
     $userSubmissionHolder->SearchData = new ArrayData(array('Keywords' => 'asfaf'));
     // Get list of page IDs of approved submissions
     $submissionIDs = $userSubmissionHolder->PublishedSubmittedFormIDs();
     // If the 'Keywords' field exists, then utilize sent Keywords data.
     $keywords = '';
     if (isset($data['Keywords']) && $data['Keywords'] && $this->Fields()->dataFieldByName('Keywords')) {
         $keywords = $data['Keywords'];
     }
     // Sets up where statements to be seperated by disjunctive (OR) or conjunctive (AND) keywords.
     $wheres = array();
     foreach ($this->Fields() as $field) {
         if ($field->EditableFormField) {
             $name = $field->getName();
             if (isset($data[$name]) && ($value = $data[$name])) {
                 $nameEscaped = Convert::raw2sql($name);
                 if ($field instanceof DropdownField) {
                     // eg. (Name = 'EditableTextField_34' AND Value = 'VIC')
                     $valueEscaped = is_string($value) ? "'" . Convert::raw2sql($value) . "'" : (int) $value;
                     $wheres[$name] = array("SubmittedFormField.Name = '{$nameEscaped}'", "SubmittedFormField.Value = {$valueEscaped}");
                 } else {
                     // eg. (Name = 'EditableTextField_33' AND Value LIKE '%hello%')
                     $valueEscaped = is_string($value) ? "LIKE '%" . Convert::raw2sql($value) . "%'" : '= ' . (int) $value;
                     $wheres[$name] = array("SubmittedFormField.Name = '{$nameEscaped}'", "SubmittedFormField.Value {$valueEscaped}");
                 }
             }
         }
     }
     // Do a keyword search on each of the fields that have it enabled.
     //
     // eg: (((Name = 'EditableTextField_33' AND Value LIKE '%hello%') OR (Name = 'EditableTextField_42' AND Value LIKE '%hello%')))
     //
     if ($keywords) {
         $whereKeywords = array();
         $keywordsEscaped = Convert::raw2sql($keywords);
         foreach ($userSubmissionHolder->Fields() as $editableFormField) {
             if ($editableFormField->UseInKeywordSearch) {
                 $nameEscaped = Convert::raw2sql($editableFormField->Name);
                 $whereKeywords[$editableFormField->Name . '_keywords'] = array("SubmittedFormField.Name = '{$nameEscaped}'", "SubmittedFormField.Value LIKE '%{$keywordsEscaped}%'");
             }
         }
         if ($whereKeywords) {
             $whereKeywordsSQL = '';
             foreach ($whereKeywords as $whereGroup) {
                 $whereKeywordsSQL .= $whereKeywordsSQL ? ' OR ' : '';
                 $whereKeywordsSQL .= '(' . implode(' AND ', $whereGroup) . ')';
             }
             $wheres['_keywords'] = array($whereKeywordsSQL);
         }
     }
     // Only search form field values that belong to a SubmittedForm object that belongs to
     // a UserSubmissionPage (or page extended with UserSubmissionExtended)
     $list = SubmittedForm::get()->filter('ID', $submissionIDs)->innerJoin('SubmittedFormField', 'SubmittedForm.ID = SubmittedFormField.ParentID')->alterDataQuery(function ($query) {
         // This is so you can match against multiple submitted form fields, and do something like "having 3 matches", where 3 is the number of user filters.
         $query->groupby('SubmittedFormField.ParentID');
     });
     // For explicit searches on fields, ie selecting a dropdown value or typing on a text field
     // that searches on a specific field.
     //
     // eg. (Name = 'EditableTextField_34' AND Value = 'VIC') AND (Name = 'EditableTextField_34' AND Value LIKE '%school%')
     //
     if ($wheres) {
         $whereSQL = '';
         foreach ($wheres as $whereGroup) {
             $whereSQL .= $whereSQL ? ' OR ' : '';
             $whereSQL .= '(' . implode(' AND ', $whereGroup) . ')';
         }
         $list = $list->where($whereSQL)->alterDataQuery(function ($query) use($wheres) {
             // This is so you can match against multiple submitted form fields, and do something like "having 3 matches", where 3 is the number of user filters.
             $query->having('COUNT(*) >= ' . count($wheres));
         });
     }
     $resultRecords = array();
     foreach ($list as $submission) {
         if ($page = $submission->UserSubmissionPage()) {
             $resultRecords[$page->ClassName . '_' . $page->ID] = $page;
         }
     }
     $userSubmissionHolder->AllListing = new ArrayList($resultRecords);
     return array();
 }