2022-04-20 06:28:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Model\Post;
|
|
|
|
|
2022-04-20 06:33:14 +00:00
|
|
|
use BadMethodCallException;
|
2022-04-20 06:28:02 +00:00
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\Database\DBStructure;
|
2022-07-12 21:21:16 +00:00
|
|
|
use Friendica\DI;
|
2022-04-20 06:28:02 +00:00
|
|
|
|
|
|
|
class Question
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Update a post question entry
|
|
|
|
*
|
|
|
|
* @param integer $uri_id
|
|
|
|
* @param array $data
|
|
|
|
* @param bool $insert_if_missing
|
|
|
|
* @return bool
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public static function update(int $uri_id, array $data = [], bool $insert_if_missing = true)
|
|
|
|
{
|
|
|
|
if (empty($uri_id)) {
|
|
|
|
throw new BadMethodCallException('Empty URI_id');
|
|
|
|
}
|
|
|
|
|
2022-07-12 22:23:12 +00:00
|
|
|
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-question', $data);
|
2022-04-20 06:28:02 +00:00
|
|
|
|
|
|
|
// Remove the key fields
|
|
|
|
unset($fields['uri-id']);
|
|
|
|
|
|
|
|
if (empty($fields)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DBA::update('post-question', $fields, ['uri-id' => $uri_id], $insert_if_missing ? true : []);
|
|
|
|
}
|
2022-04-22 19:24:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param integer $id Question ID
|
|
|
|
* @param array $fields Array of selected fields, empty for all
|
|
|
|
* @return array|boolean Question record if it exists, false otherwise
|
|
|
|
*/
|
|
|
|
public static function getById($id, $fields = [])
|
|
|
|
{
|
|
|
|
return DBA::selectFirst('post-question', $fields, ['id' => $id]);
|
|
|
|
}
|
2022-04-20 06:28:02 +00:00
|
|
|
}
|