Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 72 additions & 3 deletions datasources/csv_source.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private function __getDescriptionFromFirstLine() {
$this->_initConnection();
}
$columns = $this->_getNextRow();
$this->fields = $columns;
$this->fields = array_map(function($column) {
return (trim(strtolower($column)));
}, $columns);
$this->maxCol = count($columns);

return (bool)$this->maxCol;
Expand Down Expand Up @@ -195,7 +197,7 @@ function read(&$model, $queryData = array(), $recursive = null) {
$i = 0;
$record['id'] = $recordCount;
foreach($fields as $field) {
$record[$field] = $data[$i++];
$record[trim(strtolower($field))] = $data[$i++];
}

} else {
Expand All @@ -215,6 +217,58 @@ function read(&$model, $queryData = array(), $recursive = null) {

$this->_initConnection();

/*Filtering results*/
if (isset($queryData['conditions'])) {
if (!empty($queryData['conditions'])) {
$filtered_data = array();
foreach ($resultSet as $id => $row) {
$total_conditions = count($queryData['conditions']);
$iterator_conditions = 0;
foreach ($queryData['conditions'] as $column_operator => $value) {
list($column, $operator) = array_pad(explode(' ', $column_operator, 2), 2, null);
if (isset($row[$model->alias][$column])) {
switch ($operator) {
case '>=':
if ($row[$model->alias][$column] >= $value) {
$iterator_conditions += 1;
}
break;
case '>':
if ($row[$model->alias][$column] > $value) {
$iterator_conditions += 1;
}
break;
case '=':
if ($row[$model->alias][$column] == $value) {
$iterator_conditions += 1;
}
break;
case '<':
if ($row[$model->alias][$column] < $value) {
$iterator_conditions += 1;
}
break;
case '<=':
if ($row[$model->alias][$column] <= $value) {
$iterator_conditions += 1;
}
break;
default:
if ($row[$model->alias][$column] == $value) {
$iterator_conditions += 1;
}
break;
}
}
}
if ($total_conditions == $iterator_conditions) {
$filtered_data[] = $row;
}
}
$resultSet = $filtered_data;
}
}

$this->data = $resultSet;

if ($model->findQueryType === 'count') {
Expand Down Expand Up @@ -270,6 +324,21 @@ function calculate(&$model, $func, $params = array()) {
return array('count' => true);
}

private function __arrayfilter($array, $callback = null) {
if ($callback == null) {
$callback = function($key, $val) {
return (bool) $val;
};
}
$return = array();
foreach ($array as $key => $val) {
if ($callback($key, $val)) {
$return[$key] = $val;
}
}
return $return;
}

}

?>
?>