public function resort() { $json = Loader::helper('json'); $fieldsJSON = $json->decode(file_get_contents("php://input")); $i = 1; foreach ($fieldsJSON as $ffJSON) { $log .= $ffJSON->label . ' '; $ff = \Concrete\Package\Formify\Src\FormifyField::get($ffJSON->ffID); $ff->set('sortPriority', $i); $i++; } }
function setRecordData() { //Task: Determine which records to get without getting the full record data //Reason: Outside of the filtering, we could just setup a long SQL query, but the // filtering requires some extra SQL queries to check the actual record data. $db = Loader::db(); $SQLvars = array(); $SQLvars[] = $this->fID; // Run some checks before setting up the query // 1. Setup sort order SQL if ($this->getSortFieldID() != 0) { $SQLvars[] = intval($this->getSortFieldID()); $sortField = \Concrete\Package\Formify\Src\FormifyField::get($this->getSortFieldID()); if ($sortField->type == 'Date') { $sortType = "STR_TO_DATE(a.value,'" . $this->getDateFormat() . "')"; } elseif ($sortField->type == 'Number') { $sortType = '(a.value + 0)'; } else { $sortType = 'a.value'; } } else { $sortType = 'a.value'; } $sortOrderField = 'sortPriority'; if ($this->getSortOrder() == 'RAND') { $sortOrderSQL = 'RAND()'; $sortOrderField = ''; } else { $sortOrderSQL = $this->getSortOrder(); } // 2. Include expired records? if ($this->includeExpired) { $expiredSQL = ''; } else { $expiredSQL = "AND (expiration > '" . time() . "' OR expiration IS NULL)"; } // 3. Get approved records only? if ($this->requireApproval) { $approvalSQL = 'AND approval = 1'; } else { $approvalSQL = ''; } // 4. Only show records owned by the current user? if ($this->requireOwnership) { $owner = new User(); $ownershipSQL = "AND uID = " . intval($owner->getUserID()); } else { $ownershipSQL = ''; } // 5. Only show records that have not yet been exported? if (!$this->includeExported) { $f = \Concrete\Package\Formify\Src\FormifyForm::get($this->fID); if ($this->includeUpdated) { $exportedSQL = "AND created > " . intval($f->properties['exportTimestamp']); } else { $exportedSQL = "AND created > " . intval($f->properties['exportTimestamp']); } } else { $exportedSQL = ''; } // 6. Search according to the date range specified if ($this->startDate != '') { $startDateSQL = "AND created >= " . intval($this->startDate); } else { $startDateSQL = ''; } if ($this->endDate != '') { $endDateSQL = "AND created <= " . intval($this->endDate); } else { $endDateSQL = ''; } // 7. Is there are search query? $q = $this->getQuery(); if ($q) { if (count($q) == 1) { $searchSQL = "AND searchIndex LIKE ?"; $SQLvars[] = '%' . $q[0] . '%'; } else { $searchSQL = "AND ("; $i = 0; foreach ($q as $word) { if ($i > 0) { $searchSQL .= ' AND '; } $searchSQL .= "searchIndex LIKE ?"; $SQLvars[] = '%' . $word . '%'; $i++; } $searchSQL .= ')'; } } // 8. Setup matching filters // 1. Get the filters // 2. Get answers that match the filter // 3. Add the filter ID to "matchingFilters" field for the records that match the filter // 4. Set $filterSQL = '(matchingFilters = X) OR (matchingFilters = X)…' $filters = $this->getFilters(); if (count($filters) > 0) { foreach ($filters as $filter) { if ($filter['exact'] == true) { $matchingAnswers = $db->getAll("SELECT rID FROM " . TABLE_FORMIFY_ANSWERS . " WHERE ffID = ? AND value = ?", array($filter['ffID'], $filter['value'])); } else { $matchingAnswers = $db->getAll("SELECT rID FROM " . TABLE_FORMIFY_ANSWERS . " WHERE ffID = ? AND value LIKE ?", array($filter['ffID'], '%' . $filter['value'] . '%')); } if (is_array($matchingAnswers)) { foreach ($matchingAnswers as $ma) { $asRow = $db->getRow("SELECT count(rID) as total FROM " . TABLE_FORMIFY_RECORDS . " WHERE rID=? AND matchingFilters LIKE ?", array($ma['rID'], '%,' . $filter['filterID'] . ',%')); if (intval($asRow['total']) == 0) { $db->execute('UPDATE ' . TABLE_FORMIFY_RECORDS . ' SET matchingFilters=CONCAT_WS(",",matchingFilters,?) WHERE rID=?', array($filter['filterID'] . ',', $ma['rID'])); } } } $filterSQL .= 'AND matchingFilters LIKE ?'; $SQLvars[] = '%,' . $filter['filterID'] . ',%'; } } // 9. Get the record ID's $pageSize = $this->getPageSize(); $startAt = ($this->getPage() - 1) * $pageSize; if ($startAt < 0) { $startAt = 0; } if ($this->getPageSize() == 0) { $limitSQL = ''; } else { $limitSQL = "LIMIT {$startAt}, {$pageSize}"; } if ($this->getSortFieldID() == 0 || $sortOrderField == '') { $query = "SELECT * FROM " . TABLE_FORMIFY_RECORDS . " WHERE fID = ? AND isDeleted != 1 {$expiredSQL} {$approvalSQL} {$ownershipSQL} {$exportedSQL} {$startDateSQL} {$endDateSQL} {$searchSQL} {$filterSQL} ORDER BY {$sortOrderField} {$sortOrderSQL} {$limitSQL}"; } else { $query = "SELECT *, ans.rID, a.value FROM " . TABLE_FORMIFY_RECORDS . " ans, " . TABLE_FORMIFY_ANSWERS . " a WHERE ans.fID = ? AND a.ffID = ? AND a.rID = ans.rID AND ans.isDeleted != 1 {$expiredSQL} {$approvalSQL} {$ownershipSQL} {$exportedSQL} {$startDateSQL} {$endDateSQL} {$searchSQL} {$filterSQL} ORDER BY {$sortType} {$sortOrderSQL} {$limitSQL}"; } $this->records = $db->getAll($query, $SQLvars); $this->isPrePopulated = true; }
public function getFriendlyAnswerValue($id, $index = 0) { $a = $this->getAnswer($id); $value = $this->getAnswer($id)->value[$index]; $field = \Concrete\Package\Formify\Src\FormifyField::get($a->ffID); if ($field->type == 'attachment' || $field->type == 'file') { $file = File::getByID($value); if ($file && is_numeric($value)) { $fv = $file->getApprovedVersion(); $value = '<a href="' . $fv->getRelativePath() . '">' . $fv->getFileName() . '</a>'; } else { $value = ''; } } return $value; }
public function getField($id) { return \Concrete\Package\Formify\Src\FormifyField::get($id, $this->fID); }