default values in action

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
cached version of the post contains action.values

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
fixing default values

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/546/head
Maxence Lange 2019-05-29 13:13:45 -01:00
rodzic f117996654
commit 37f4d17815
2 zmienionych plików z 27 dodań i 5 usunięć

Wyświetl plik

@ -731,8 +731,12 @@ class CoreRequestBuilder {
->selectAlias('sa.stream_id', 'streamaction_stream_id')
->selectAlias('sa.values', 'streamaction_values');
$orX = $expr->orX();
$orX->add($expr->eq($func->lower($pf . '.id'), $func->lower('sa.stream_id')));
$orX->add($expr->eq($func->lower($pf . '.object_id'), $func->lower('sa.stream_id')));
$andX = $expr->andX();
$andX->add($expr->eq($func->lower($pf . '.id'), $func->lower('sa.stream_id')));
$andX->add($orX);
$andX->add(
$expr->eq(
$func->lower('sa.actor_id'),
@ -763,10 +767,11 @@ class CoreRequestBuilder {
$action = new StreamAction();
$action->importFromDatabase($new);
if ($action->getId() === 0) {
throw new InvalidResourceException();
}
$action->setDefaultValues(
[
'boosted' => false
]
);
return $action;
}

Wyświetl plik

@ -209,6 +209,23 @@ class StreamAction implements JsonSerializable {
}
/**
* @param array $default
*
* @return StreamAction
*/
public function setDefaultValues(array $default): StreamAction {
$keys = array_keys($default);
foreach ($keys as $k) {
if (!array_key_exists($k, $this->values)) {
$this->values[$k] = $default[$k];
}
}
return $this;
}
/**
* @param array $data
*/