/** * __construct() * Constructor for the THINKER_Object_DataSet Class * * @author Cory Gehr * @access public * @param $Schema: Primary Schema Object * @param $Table: Primary Table Object * @param $columns: Columns to pull * @param $filters: Filters to use (default: empty array) */ public function __construct($Schema, $Table, $columns, $filters = array()) { global $_DB; // Call parent constructor parent::__construct(); // Set local variables $this->columns = $columns; $this->filters = $filters; $this->PrimarySchema = $Schema; $this->PrimaryTable = $Table; // Pull data $this->compileQuery(); $statement = $_DB['thinker']->prepare($this->query); $statement->execute($this->queryParams); $this->returnedData = $statement->fetchAll(PDO::FETCH_ASSOC); if (empty($this->returnedData)) { pushMessage("No data was returned for the specified parameters.", 'warning'); } }
/** * filterSelect() * Passes data back for the 'filterSelect' subsection * * @access public */ public function filterSelect() { // Check for schema information $Schema = $this->session->__get('PRIMARY_SCHEMA'); $Table = $this->session->__get('PRIMARY_TABLE'); if (!empty($Schema) && !empty($Table)) { // Get columns $columns = $this->session->__get('PULL_COLUMNS'); if ($columns) { // Process changes $phase = getPageVar('phase', 'str', 'GET'); switch ($phase) { case 'fetchFilterTypes': // Get the name of the column $column = getPageVar('column', 'str', 'GET'); if ($column) { // Parse column provided $colParts = explode('-|-', $column); $colPartCount = count($colParts); // Needs to be three or four parts if ($colPartCount === 3 || $colPartCount === 4) { $fkCol = null; if ($colPartCount === 4) { $fkCol = $colParts[3]; } // Get the column data type $id = $this->createColId($colParts[0], $colParts[1], $colParts[2], $fkCol); if (isset($columns[$id])) { $Column = $columns[$id]; $colType = $Column['COLUMN']->getColumnType(); $filters = array(); switch ($colType) { case 'bigint': case 'decimal': case 'double': case 'float': case 'int': case 'smallint': $filters = array('EQUALS' => '=', 'GT' => '>', 'GTE' => '>=', 'LT' => '<', 'LTE' => '<='); break; case 'date': case 'datetime': case 'time': case 'timestamp': $filters = array('BEFORE' => 'Before', 'BEFORE_INCL' => 'Before (Inclusive)', 'AFTER' => 'After', 'AFTER_INCL' => 'After (Inclusive)', 'EQUALS' => 'Equals'); break; case 'tinyint': $filters = array('FALSE' => 'False', 'TRUE' => 'True'); break; default: // Varchar, Char, Enum Typically $filters = array('CONTAINS' => 'Contains', 'EQUALS' => 'Equals', 'LIKE' => 'Like', 'STARTS_WITH' => 'Starts With', 'ENDS_WITH' => 'Ends With'); break; } $this->set('filters', $filters); } } } // This is all we need here return true; break; case 'invalidColumn': pushMessage('An invalid column was specified, please try again.', 'warning'); break; case 'missingInfo': pushMessage('A required filter option and/or value were missing, please try again.', 'warning'); break; case 'proceed': // Get inputs, as long as they're provided $filters = array(); $process = true; $count = 1; while ($process) { $filterAndOrName = "filter-andor_{$count}"; $filterColName = "filter-col_{$count}"; $filterOptionName = "filter-option_{$count}"; $filterValueName = "filter-value_{$count}"; $column = getPageVar($filterColName, 'str', 'POST', false); if (!empty($column)) { // Get Column Object if (isset($columns[$column])) { $FilterCol = $columns[$column]; // Get the option, andor, and values $option = getPageVar($filterOptionName, 'str', 'POST', false); $value = getPageVar($filterValueName, 'str', 'POST', false); $andOr = getPageVar($filterAndOrName, 'str', 'POST', false); if ($option && ($value || !$value && ($option == 'FALSE' || $option == 'TRUE'))) { // If no AndOr, then assume AND if (!$andOr && $count == 1) { $andOr = 'FIRST'; } else { $andOr = 'AND'; } // Store values in array $filters[] = array('COLUMN' => $FilterCol, 'OPTION' => $option, 'VALUE' => $value, 'ANDOR' => $andOr); // Continue $count++; } else { // Throw error redirect('DataPull', 'filterSelect', array('phase' => 'missingInfo')); } } else { // Throw error redirect('DataPull', 'filterSelect', array('phase' => 'invalidColumn')); } } else { // No column value, so we're done $process = false; } } // Store filters in session and redirect $this->session->__set('PULL_FILTERS', $filters); redirect('DataPull', 'dataReview'); break; } $this->set('schemaName', $Schema->getSchemaName()); $this->set('tableName', $Table->getTableFriendlyName()); $this->set('columns', $columns); } else { // We have a schema and table, but no columns. Redirect back to dataSelect redirect('DataPull', 'dataSelect', array('phase' => 'noCols')); } } else { // User hasn't started yet. Redirect to start redirect('DataPull', 'dsSelect', array('phase' => 'noSchema')); } return true; }