This commit is contained in:
Paula Quispe
2018-10-08 09:56:48 -04:00
parent 21189d3a57
commit 71e3541f71

View File

@@ -148,38 +148,13 @@ class Applications
} }
if (!empty($search)) { if (!empty($search)) {
//If the filter is related to the APPLICATION table: APP_NUMBER or APP_TITLE //If the filter is related to the APP_DELEGATION table: APP_NUMBER
if ($columnSearch === 'APP_NUMBER' || $columnSearch === 'APP_TITLE') { if ($columnSearch === 'APP_NUMBER') {
$sqlSearch = "SELECT APPLICATION.APP_NUMBER FROM APPLICATION"; $sqlData .= " AND APP_DELEGATION.APP_NUMBER LIKE '%{$search}%' ";
$sqlSearch .= " WHERE APPLICATION.{$columnSearch} LIKE '%{$search}%'"; }
$orderByColumnSearch = " ORDER BY APPLICATION.{$columnSearch} " . $dir; //If the filter is related to the APPLICATION table: APP_TITLE
switch ($columnSearch) { if ($columnSearch === 'APP_TITLE') {
case 'APP_TITLE': $sqlData .= " AND APPLICATION.APP_TITLE LIKE '%{$search}%' ";
break;
case 'APP_NUMBER':
//Cast the search criteria to string
if (!is_string($search)) {
$search = (string)$search;
}
//Only if is integer we will to add to greater equal in the query
if (substr($search, 0, 1) != '0' && ctype_digit($search)) {
$sqlSearch .= " AND APPLICATION.{$columnSearch} >= {$search}";
}
break;
}
$sqlSearch .= $orderByColumnSearch;
if (!empty($start)) {
$sqlSearch .= " LIMIT $start, " . $limit;
} else {
$sqlSearch .= " LIMIT " . $limit;
}
$dataset = $stmt->executeQuery($sqlSearch);
$appNumbers = [-1];
while ($dataset->next()) {
$newRow = $dataset->getRow();
array_push($appNumbers, $newRow['APP_NUMBER']);
}
$sqlData .= " AND APP_DELEGATION.APP_NUMBER IN (" . implode(",", $appNumbers) . ")";
} }
//If the filter is related to the TASK table: TAS_TITLE //If the filter is related to the TASK table: TAS_TITLE
if ($columnSearch === 'TAS_TITLE') { if ($columnSearch === 'TAS_TITLE') {
@@ -196,7 +171,6 @@ class Applications
$sqlData .= " AND APP_DELEGATION.DEL_DELEGATE_DATE <= '{$dateTo}'"; $sqlData .= " AND APP_DELEGATION.DEL_DELEGATE_DATE <= '{$dateTo}'";
} }
//Add the additional filters
//Sorts the records in descending order by default //Sorts the records in descending order by default
if (!empty($sort)) { if (!empty($sort)) {
switch ($sort) { switch ($sort) {
@@ -218,12 +192,12 @@ class Applications
if (empty($limit)) { if (empty($limit)) {
$limit = 25; $limit = 25;
} }
if (!empty($start) && empty($search)) { if (!empty($start)) {
$sqlData .= " LIMIT $start, " . $limit; $sqlData .= " LIMIT $start, " . $limit;
} else { } else {
$sqlData .= " LIMIT " . $limit; $sqlData .= " LIMIT " . $limit;
} }
$dataset = $stmt->executeQuery($sqlData); $dataset = $stmt->executeQuery($sqlData);
$result = []; $result = [];
//By performance enable always the pagination //By performance enable always the pagination