2021-10-08 13:45:20 -04:00
|
|
|
<?php
|
2021-10-10 14:57:23 -04:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2021, 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/>.
|
|
|
|
*
|
|
|
|
*/
|
2021-10-08 13:45:20 -04:00
|
|
|
|
|
|
|
namespace Friendica\Profile\ProfileField\Factory;
|
|
|
|
|
|
|
|
use Friendica\BaseFactory;
|
2021-10-10 17:30:21 -04:00
|
|
|
use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
|
2021-10-08 13:45:20 -04:00
|
|
|
use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository;
|
|
|
|
use Friendica\Profile\ProfileField\Entity;
|
|
|
|
use Friendica\Capabilities\ICanCreateFromTableRow;
|
2021-10-10 14:39:35 -04:00
|
|
|
use Friendica\Security\PermissionSet\Entity\PermissionSet;
|
2021-10-08 13:45:20 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class ProfileField extends BaseFactory implements ICanCreateFromTableRow
|
|
|
|
{
|
|
|
|
/** @var PermissionSetDepository */
|
|
|
|
private $permissionSetDepository;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger, PermissionSetDepository $permissionSetDepository)
|
|
|
|
{
|
|
|
|
parent::__construct($logger);
|
|
|
|
|
|
|
|
$this->permissionSetDepository = $permissionSetDepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-10-10 14:39:35 -04:00
|
|
|
public function createFromTableRow(array $row, PermissionSet $permissionSet = null): Entity\ProfileField
|
2021-10-08 13:45:20 -04:00
|
|
|
{
|
2021-10-10 17:30:21 -04:00
|
|
|
if (empty($permissionSet) && empty($row['psid'])) {
|
|
|
|
throw new UnexpectedPermissionSetException('Either set the permission set ID or the permission set itself');
|
|
|
|
}
|
|
|
|
|
2021-10-08 13:45:20 -04:00
|
|
|
return new Entity\ProfileField(
|
|
|
|
$this->permissionSetDepository,
|
|
|
|
$row['uid'],
|
|
|
|
$row['order'],
|
2021-10-10 17:30:21 -04:00
|
|
|
$row['psid'] ?? $permissionSet->id,
|
2021-10-08 13:45:20 -04:00
|
|
|
$row['label'],
|
|
|
|
$row['value'],
|
2021-10-10 14:39:35 -04:00
|
|
|
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
|
|
|
|
new \DateTime($row['edited'] ?? 'now', new \DateTimeZone('UTC')),
|
2021-10-10 17:30:21 -04:00
|
|
|
$row['id'] ?? null,
|
2021-10-10 14:39:35 -04:00
|
|
|
$permissionSet
|
2021-10-08 13:45:20 -04:00
|
|
|
);
|
|
|
|
}
|
2021-10-10 14:39:35 -04:00
|
|
|
|
|
|
|
public function createFromString(
|
|
|
|
int $uid,
|
|
|
|
int $order,
|
|
|
|
string $label,
|
|
|
|
string $value,
|
|
|
|
PermissionSet $permissionSet
|
|
|
|
): Entity\ProfileField {
|
|
|
|
return $this->createFromTableRow([
|
|
|
|
'uid' => $uid,
|
|
|
|
'order' => $order,
|
|
|
|
'psid' => $permissionSet->id,
|
|
|
|
'label' => $label,
|
|
|
|
'value' => $value,
|
|
|
|
], $permissionSet);
|
|
|
|
}
|
2021-10-08 13:45:20 -04:00
|
|
|
}
|