Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into fix-form-field-hint-location
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Jun 30, 2016
2 parents b39bab3 + bf75105 commit 0f87e41
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
20 changes: 15 additions & 5 deletions lib/App/REST.php
Expand Up @@ -62,16 +62,26 @@ public function encodeOutput($data)

if ($_GET['format'] == 'xml') {
throw $this->exception('only JSON format is supported', null, 406);
} elseif ($_GET['format'] == 'json_pretty') {
}

if ($_GET['format'] == 'json_pretty') {
header('Content-type: application/json');
echo json_encode($data, JSON_PRETTY_PRINT);
} elseif ($_GET['format'] == 'html') {
return;
}

if ($_GET['format'] == 'html') {
echo '<pre>';
echo json_encode($data, JSON_PRETTY_PRINT);
} elseif ($data === null) {
header('Content-type: application/json');
echo json_encode(array());
return;
}

header('Content-type: application/json');

if ($data === null) {
$data = array();
}
echo json_encode($data);
}

/**
Expand Down
27 changes: 24 additions & 3 deletions lib/DB/dsql.php
Expand Up @@ -455,6 +455,7 @@ public function getField($fld)
* $q->table(array('user','salary'));
* $q->table(array('user','salary'),'user');
* $q->table(array('u'=>'user','s'=>'salary'));
* $q->table($q2->table('user')->where('active',1), 'active_users');
*
* If you specify multiple tables, you still need to make sure to add
* proper "where" conditions. All the above examples return $q (for chaining)
Expand All @@ -467,8 +468,8 @@ public function getField($fld)
* Please avoid using table() without arguments as more tables may be
* dynamically added later.
*
* @param string $table Specify table to use
* @param string $alias Specify alias for the table
* @param string|DB_dsql $table Specify table to use or DSQL to use as derived table
* @param string $alias Specify alias for the table, if $table is DSQL, then alias is mandatory
*
* @return $this|string
*/
Expand Down Expand Up @@ -496,6 +497,11 @@ public function table($table = UNDEFINED, $alias = UNDEFINED)
$this->main_table = false; // query from multiple tables
}

// if $table is DSQL, then alias is mandatory
if ($table instanceof DB_dsql && ($alias === UNDEFINED || !$alias)) {
throw $this->exception('If table is passed as DSQL, then table alias is mandatory!');
}

$this->args['table'][] = array($table, $alias);

return $this;
Expand All @@ -516,7 +522,22 @@ public function render_table()
foreach ($this->args['table'] as $row) {
list($table, $alias) = $row;

$table = $this->bt($table);
if (is_string($table)) {
// table name passed as string
$table = $this->bt($table);

} elseif ($table instanceof DB_dsql) {
// table passed as DSQL expression

// remove SQL_CALC_FOUND_ROWS from subquery
$i = @array_search('SQL_CALC_FOUND_ROWS', $table->args['options']);
if ($i !== false) {
unset($table->args['options'][$i]);
}

// consume subquery
$table = $this->consume($table);
}

if ($alias !== UNDEFINED && $alias) {
$table .= ' '.$this->bt($alias);
Expand Down
2 changes: 1 addition & 1 deletion lib/Form/Field.php
Expand Up @@ -280,7 +280,7 @@ public function setProperty($property, $value)
}
public function setFieldHint($var_args = null)
{
/* Adds a hint below this field. This will call Form_Hint->set()
/* Adds a hint after this field. This will call Field_Hint->set()
with same arguments you called this function.
*/
if (!$this->template->hasTag('below_field')) {
Expand Down

0 comments on commit 0f87e41

Please sign in to comment.