Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group function closer to the original one #134

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions rdb/Datum/NumberDatum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class NumberDatum extends Datum
{
public function encodeServerRequest()
{
return (float)$this->getValue();
return $this->getValue();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because all the numbers are saved as float. I couldn't save integers.

}

public static function decodeServerResponse($json)
{
$result = new NumberDatum();
$result->setValue((float)$json);
$result->setValue($json);
return $result;
}

Expand Down
12 changes: 8 additions & 4 deletions rdb/Queries/Aggregations/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

class Group extends ValuedQuery
{
public function __construct(ValuedQuery $sequence, $groupOn)
public function __construct(ValuedQuery $sequence, $fieldOrFunction, $groupOn = [])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to use PHP 5.3 compatible syntax, i.e. array() instead of [].

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, will fix it

{
if (!is_array($groupOn)) {
$groupOn = array($groupOn);
}
array_unshift($groupOn, $fieldOrFunction);

if (isset($groupOn['index'])) {
$this->setOptionalArg('index', $this->nativeToDatum($groupOn['index']));
unset($groupOn['index']);
}

if (isset($groupOn['multi'])) {
$this->setOptionalArg('multi', $this->nativeToDatum($groupOn['multi']));
unset($groupOn['multi']);
}

$this->setPositionalArg(0, $sequence);
$i = 1;
Expand Down
4 changes: 2 additions & 2 deletions rdb/ValuedQuery/ValuedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public function distinct($opts = null)
{
return new Distinct($this, $opts);
}
public function group($groupOn)
public function group($fieldOrFunction, $groupOn = [])
{
return new Group($this, $groupOn);
return new Group($this, $fieldOrFunction, $groupOn);
}
public function ungroup()
{
Expand Down