/** * @param string $model */ public function __construct($model) { $this->_model = $model; $m = $this->_model; $this->_dataset = new Core\Datamodel\Dataset(); $this->_dataset->table($m::GetTablename()); $this->_dataset->select('*'); }
public function pagemetas_autocompletekeyword(){ $request = $this->getPageRequest(); $view = $this->getView(); $view->mode = View::MODE_AJAX; $view->contenttype = View::CTYPE_JSON; $term = $request->getParameter('term'); $view->record = false; // This is an ajax-only request. if(!$request->isAjax()){ return View::ERROR_BADREQUEST; } $ds = new Core\Datamodel\Dataset(); $ds->table('page_meta'); $ds->uniquerecords = true; $ds->select('meta_value', 'meta_value_title'); $ds->where('meta_key = keyword'); $ds->where('meta_value_title LIKE ' . $term . '%'); // Just in case there are a huge number of records... $stream = new DatasetStream($ds); $view->jsondata = array(); while(($record = $stream->getRecord())){ $view->jsondata[] = array( 'id' => $record['meta_value'], 'label' => $record['meta_value_title'], 'value' => $record['meta_value'], ); } // Does the user have access to search for users? // if so include that search here to! This is for the subject matter tag, or "This x is about person y!" if(\Core\user()->checkAccess('p:/user/search/autocomplete')){ $results = UserModel::Search($term); foreach($results as $r){ /** @var $r \Core\Search\ModelResult */ /** @var UserModel $user */ $user = $r->_model; $view->jsondata[] = array( 'id' => 'u:' . $user->get('id'), 'label' => $user->getDisplayName(), 'value' => 'u:' . $user->get('id'), ); } } }
/** * @access public * * @param bool $subSelect * * @return Core\Datamodel\Dataset */ public function parseSelect($subSelect = false) { $tree = new Core\Datamodel\Dataset(); $tree->_mode = Core\Datamodel\Dataset::MODE_GET; $this->getTok(); if ($this->token == 'distinct') { $tree->uniquerecords = true; $this->getTok(); } // SELECT columns $selects = []; while (1) { $exp = $this->parseCondition()['args'][0]; if(isset($exp['name'])){ $this->raiseError('Datasets do not support functions as SELECT parameters!'); } if(isset($exp['value'])){ $selects[] = $exp['value']; } elseif(isset($exp['column'])){ $selects[] = $exp['column']; } else{ $this->raiseError('Unknown SELECT object'); } if ($this->token != ',') { break; } $this->getTok(); } $tree->select($selects); // FROM if ($this->token != 'from') { return $tree; } $this->getTok(); $table = $this->parseFrom(); if(sizeof($table['table_references']['table_factors']) != 1){ $this->raiseError('Datasets only support one table at a time!'); } $tree->table($table['table_references']['table_factors'][0]['table']); // WHERE // GROUP BY // HAVING // ORDER BY // LIMIT // UNION while ($this->token != ';' && ! is_null($this->token) && (!$subSelect || $this->token != ')') && $this->token != ')') { switch ($this->token) { case 'where': $this->getTok(); $clause = $this->parseWhereCondition(); if (false === $clause) { return $clause; } $tree->_where = $clause; break; case 'order': $this->getTok(); if ($this->token != 'by') { $this->raiseError('Expected "by"'); } $this->getTok(); while ($this->token == 'ident') { $arg = $this->lexer->tokText; $this->getTok(); if ($this->token == '.') { $this->getTok(); if ($this->token == 'ident') { $arg .= '.'.$this->lexer->tokText; } else { $this->raiseError('Expected a column name'); } } else { $this->lexer->pushBack(); } $col = $arg; //$col = $this->lexer->tokText; $this->getTok(); if (isset($this->synonyms[$this->token])) { $order = $this->synonyms[$this->token]; if (($order != 'asc') && ($order != 'desc')) { $this->raiseError('Unexpected token'); } $this->getTok(); } else { $order = 'asc'; } if ($this->token == ',') { $this->getTok(); } $tree->order($col . ' ' . $order); } break; case 'limit': $this->getTok(); if ($this->token != 'int_val') { $this->raiseError('Expected an integer value'); } $length = $this->lexer->tokText; $start = 0; $this->getTok(); if ($this->token == ',') { $this->getTok(); if ($this->token != 'int_val') { $this->raiseError('Expected an integer value'); } $start = $length; $length = $this->lexer->tokText; $this->getTok(); } $tree->limit($start . ' ' . $length); break; case 'group': $this->getTok(); if ($this->token != 'by') { $this->raiseError('Expected "by"'); } $this->getTok(); while ($this->token == 'ident') { $arg = $this->lexer->tokText; $this->getTok(); if ($this->token == '.') { $this->getTok(); if ($this->token == 'ident') { $arg .= '.'.$this->lexer->tokText; } else { $this->raiseError('Expected a column name'); } } else { $this->lexer->pushBack(); } $col = $arg; //$col = $this->lexer->tokText; $this->getTok(); if ($this->token == ',') { $this->getTok(); } $this->raiseError('@TODO group by statements not supported yet'); $tree['group_by'][] = $col; } break; default: $this->raiseError('Unexpected clause'); } } return $tree; }