Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DataTable and DataSet evolution

  • Loading branch information...
commit a177bed2932958d79adda801da83a4da7df1518f 1 parent 0519ccd
@Artazor Artazor authored
View
54 sql/builder/builder.class.php
@@ -63,28 +63,70 @@ public static function buildDomain($domain) {
if ($joinType !== false) {
$result .= $joinType . ' ';
}
- $result .= self::indent($data->getSelectExpression()) . ' as ' . $alias;
+ $result .= self::indent($data->getSourceExpression()) . ' as ' . $alias;
$on = self::buildOn($joins);
if ($on !== '') {
$result .= "on \n" . self::indent($on);
}
$result .= "\n";
}
+ return $result;
}
public static function buildColumns($columns) {
+ $result = '';
+ foreach($columns as $alias => $value) {
+ $result .= $result === ''
+ ? ' '
+ : ', '
+ ;
+ $result .= $value . ' as ' . $alias;
+ }
+ return $result === '' ? false : $result;
+ }
+
+ public static function buildGroup($columns) {
+ $result = '';
+ foreach($columns as $alias => $value) {
+ $result .= $result === ''
+ ? ' '
+ : ', '
+ ;
+ $result .= $value;
+ }
+ return $result === '' ? false : $result;
+ }
+
+ public static function buildFilter($predicate) {
+ return false;
+
+ }
+
+ public static function buildOrder($order) {
+ return false;
}
+ public static function buildLimit($limit) {
+ return false;
+
+ }
+
+
+ public static function buildOffset($offset) {
+ return false;
+
+ }
+ public function buildSql($meta, $intent) {
- public function buildSql($meta, $update = false) {
+ $from = self::buildDomain($meta['from']);
$parts = array(
- 'select' => self::buildColumns($meta['columns']),
- 'from' => self::buildDomain($meta['domain']),
- 'where' => self::buildFilter($meta['filter']),
- 'group by' => self::buildColumns($meta['key']),
+ 'select' => self::buildColumns($meta['select'][$intent]),
+ 'from' => self::buildDomain($meta['from']),
+ 'where' => self::buildFilter($meta['where'][$intent]),
+ 'group by' => self::buildGroup($meta['keys'][0]),
'having' => self::buildFilter($meta['having']),
'order by' => self::buildOrder($meta['order']),
'limit' => self::buildLimit($meta['limit']),
View
2  sql/connection/connection.class.php
@@ -337,7 +337,7 @@ private function reflectDatabases($refresh) {
c.CONSTRAINT_NAME,
u.ORDINAL_POSITION
");
- $path = array('database' => 'tables', 'table' => 'keys', 'key' => '*');
+ $path = array('database' => 'tables', 'table' => 'keys', 'key' => 'columns', 'column'=>'*');
while($row = mysql_fetch_assoc($keys)){
$this->structurize($row, $path, $this->model['databases']);
}
View
22 sql/data_set/data_set.class.php
@@ -1,6 +1,7 @@
<?
class Oxygen_SQL_DataSet extends Oxygen_Object
+ implements IteratorAggregate
//implements Countable, ArrayAccess, IteratorAggregate
{
@@ -9,6 +10,9 @@ class Oxygen_SQL_DataSet extends Oxygen_Object
const EMPTY_FILTER = '(1=1)';
public $connection = null;
+ public $builder = null;
+ public $iterationKey = array();
+ public $sql = array();
private static $defaults = array(
'select' => false,
@@ -30,12 +34,30 @@ public function getMeta() {
public function getColumnNames() { }
public function getKeyNames() { }
+ public function getIterationKey() {
+ return $this->meta['keys'][0];
+ }
+
public function __construct($meta) {
$this->meta = array_merge(self::$defaults, $meta);
}
public function __complete() {
$this->connection = $this->scope->connection;
+ $this->builder = $this->connection->builder;
+ $this->sql['select'] = $this->builder->buildSql($this->meta,'select');
+ }
+
+ public function makeRow($data) {
+ return $this->scope->Row($data);
+ }
+
+ public function getIterator() {
+ return $this->scope->DataIterator(
+ $this->sql['select'],
+ $this->getIterationKey(),
+ array($this,'makeRow')
+ );
}
View
17 sql/key/key.class.php
@@ -1,6 +1,19 @@
<?
-
+
class Oxygen_SQL_Key extends Oxygen_SQL_Columns {
+ public function getDefaultView() {
+ return 'view';
+ }
+
+ function rpc_Hello($whom) {
+ $this->flash('Hi!');
+ $this->flashError('Other!' . $whom);
+ return "Hi, {$whom}!";
+ }
+
+ public function configure($x) {
+ $x['{COLUMN_NAME:url}']->Column($this->model['columns']);
+ }
}
-?>
+?>
View
5 sql/key/view.js
@@ -0,0 +1,5 @@
+$this.find('button.zzz').click(function(){
+ $this.remote('Hello','Somebody',function(err,response){
+ //o.flash(response,'debug');
+ });
+})
View
3  sql/key/view.less
@@ -0,0 +1,3 @@
+margin: 20px;
+padding: 20px;
+background-color: #FED;
View
4 sql/key/view.php
@@ -0,0 +1,4 @@
+<?o()?>
+This is a key;
+<?//<button class="zzz">ClickMe</button>?>
+<?=$this?>
View
36 sql/table/table.class.php
@@ -32,12 +32,12 @@ public function getDefaultView() {
return 'as_table';
}
+ public function getSourceExpression() {
+ return $this->fullName;
+ }
+
public function getData($alias) {
- $from[$alias] = array(
- 'name' => $this->fullName,
- 'type' => 'init',
- 'join' => array()
- );
+ $from[$alias] = array($this,false,array());
return $this->scope->DataSet(array(
'keys' => $this->getKeys($alias),
'select' => $this->getPolicyColumns($alias),
@@ -56,7 +56,7 @@ public function getKeys($alias) {
foreach($this['keys'] as $key => $columns) {
$k = array();
foreach($columns as $name => $col) {
- $k[$name][] = $alias . '.' . $name;
+ $k[$name] = $alias . '.' . $name;
}
$result[] = $k;
}
@@ -73,7 +73,6 @@ public function getPolicyColumns($alias) {
}
$this->ensurePolicyLoaded();
$result = array();
- $this->flash($this->policy,'debug');
foreach($this->policy as $intent => $policy) {
if($policy === true) {
$policy = array('columns'=>'*','predicate'=>true);
@@ -121,7 +120,27 @@ public function getPolicyColumns($alias) {
public function getPolicyPredicates($alias) {
$this->ensurePolicyLoaded();
- return array();
+ $result = array();
+ foreach($this->policy as $intent => $resolution){
+ $predicate = $resolution['predicate'];
+ if ($predicate === true) {
+ $result[$intent] = true;
+ } else if ($predicate === false) {
+ $result[$intent] = false;
+ } else {
+ $pred = array();
+ foreach ($predicate as $key => $value) {
+ if(is_integer($key)){
+ $pred[] = $value; //TODO parse and add aliases!
+ } else {
+ $columnAlias = Oxygen_SQL_Builder::compoundAlias($alias,$key);
+ $pred[$columnAlias] = $value;
+ }
+ }
+ $result[$intent] = $pred;
+ }
+ }
+ return $result;
}
public function configure($x) {
@@ -135,6 +154,7 @@ public function __complete() {
$this->connection = $this->database->connection;
$this->policy = $this->connection->getPolicy($this->model);
$this->scope->table = $this;
+ $this->fullName = $this->database->model['name'] . '.' . $this->model['name'];
}
Please sign in to comment.
Something went wrong with that request. Please try again.