2019-09-23 10:34:21 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2019-09-23 10:34:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-09-23 10:34:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Db;
|
|
|
|
|
2022-12-07 00:14:12 +00:00
|
|
|
use OCA\Social\Exceptions\StreamDestDoesNotExistException;
|
|
|
|
use OCA\Social\Model\StreamDest;
|
|
|
|
use OCA\Social\Tools\Exceptions\RowNotFoundException;
|
2022-06-17 14:29:54 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2019-09-23 10:34:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class StreamDestRequestBuilder
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Db
|
|
|
|
*/
|
|
|
|
class StreamDestRequestBuilder extends CoreRequestBuilder {
|
|
|
|
use TArrayTools;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Insert request
|
|
|
|
*/
|
2019-09-29 15:41:47 +00:00
|
|
|
protected function getStreamDestInsertSql(): SocialQueryBuilder {
|
|
|
|
$qb = $this->getQueryBuilder();
|
2019-09-23 10:34:21 +00:00
|
|
|
$qb->insert(self::TABLE_STREAM_DEST);
|
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Update request
|
|
|
|
*
|
2022-12-07 00:14:12 +00:00
|
|
|
* @return SocialQueryBuilder
|
2019-09-23 10:34:21 +00:00
|
|
|
*/
|
2022-12-07 00:14:12 +00:00
|
|
|
protected function getStreamDestUpdateSql(): SocialQueryBuilder {
|
2019-10-01 11:53:26 +00:00
|
|
|
$qb = $this->getQueryBuilder();
|
2019-09-23 10:34:21 +00:00
|
|
|
$qb->update(self::TABLE_STREAM_DEST);
|
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Select request for Shares
|
|
|
|
*
|
2020-06-25 02:48:36 +00:00
|
|
|
* @return SocialQueryBuilder
|
2019-09-23 10:34:21 +00:00
|
|
|
*/
|
2020-06-25 02:48:36 +00:00
|
|
|
protected function getStreamDestSelectSql(): SocialQueryBuilder {
|
2019-10-01 11:53:26 +00:00
|
|
|
$qb = $this->getQueryBuilder();
|
2019-09-23 10:34:21 +00:00
|
|
|
|
|
|
|
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
2022-12-07 00:14:12 +00:00
|
|
|
$qb->select('sd.actor_id', 'sd.stream_id', 'sd.type', 'sd.subtype')
|
2019-09-23 10:34:21 +00:00
|
|
|
->from(self::TABLE_STREAM_DEST, 'sd');
|
|
|
|
|
|
|
|
$this->defaultSelectAlias = 'sd';
|
2020-06-25 02:48:36 +00:00
|
|
|
$qb->setDefaultSelectAlias('sd');
|
2019-09-23 10:34:21 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Delete request
|
|
|
|
*
|
2022-12-07 00:14:12 +00:00
|
|
|
* @return SocialQueryBuilder
|
2019-09-23 10:34:21 +00:00
|
|
|
*/
|
2022-12-07 00:14:12 +00:00
|
|
|
protected function getStreamDestDeleteSql(): SocialQueryBuilder {
|
2019-10-01 11:53:26 +00:00
|
|
|
$qb = $this->getQueryBuilder();
|
2019-09-23 10:34:21 +00:00
|
|
|
$qb->delete(self::TABLE_STREAM_DEST);
|
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Select request for Shares
|
|
|
|
*
|
2020-06-25 02:48:36 +00:00
|
|
|
* @return SocialQueryBuilder
|
2019-09-23 10:34:21 +00:00
|
|
|
*/
|
2020-06-25 02:48:36 +00:00
|
|
|
protected function countStreamDestSelectSql(): SocialQueryBuilder {
|
2019-10-01 11:53:26 +00:00
|
|
|
$qb = $this->getQueryBuilder();
|
2019-09-23 10:34:21 +00:00
|
|
|
$qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')
|
|
|
|
->from(self::TABLE_STREAM_DEST, 'sd');
|
|
|
|
|
|
|
|
$this->defaultSelectAlias = 'sd';
|
2020-06-25 02:48:36 +00:00
|
|
|
$qb->setDefaultSelectAlias('sd');
|
2019-09-23 10:34:21 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
2022-12-07 00:14:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param SocialQueryBuilder $qb
|
|
|
|
*
|
|
|
|
* @return StreamDest
|
|
|
|
* @throws StreamDestDoesNotExistException
|
|
|
|
*/
|
|
|
|
public function getStreamDestFromRequest(SocialQueryBuilder $qb): StreamDest {
|
|
|
|
/** @var StreamDest $result */
|
|
|
|
try {
|
|
|
|
$result = $qb->getRow([$this, 'parseStreamDestSelectSql']);
|
|
|
|
} catch (RowNotFoundException $e) {
|
|
|
|
throw new StreamDestDoesNotExistException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param SocialQueryBuilder $qb
|
|
|
|
*
|
|
|
|
* @return StreamDest[]
|
|
|
|
*/
|
|
|
|
public function getStreamDestsFromRequest(SocialQueryBuilder $qb): array {
|
|
|
|
return $qb->getRows([$this, 'parseStreamDestSelectSql']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return StreamDest
|
|
|
|
*/
|
|
|
|
public function parseStreamDestSelectSql(array $data): StreamDest {
|
|
|
|
$streamDest = new StreamDest();
|
|
|
|
$streamDest->importFromDatabase($data);
|
|
|
|
|
|
|
|
return $streamDest;
|
|
|
|
}
|
2019-09-23 10:34:21 +00:00
|
|
|
}
|