joomla-oauth-server/com_oauthserver/administrator/src/Model/AccessTokenModel.php

88 lines
2.2 KiB
PHP
Raw Normal View History

2024-03-06 13:20:51 +03:00
<?php
2024-03-09 18:53:26 +03:00
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
2024-03-06 13:20:51 +03:00
namespace Webmasterskaya\Component\OauthServer\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\AdminModel;
2024-03-09 18:53:26 +03:00
use Joomla\CMS\Table\Table;
use Webmasterskaya\Component\OauthServer\Administrator\Table\AccessTokenTable;
\defined('_JEXEC') or die;
2024-03-06 13:20:51 +03:00
class AccessTokenModel extends AdminModel implements RevokedModelInterface
2024-03-06 13:20:51 +03:00
{
use GetItemByIdentifierTrait;
use RevokedModelTrait;
2024-03-06 13:20:51 +03:00
2024-03-09 18:53:26 +03:00
/**
* @inheritdoc
* @since version
*/
2024-03-06 13:20:51 +03:00
public function getForm($data = [], $loadData = true): Form|bool
{
$form = $this->loadForm('com_oauthserver.access_token', 'access_token', ['control' => 'jform', 'load_data' => $loadData]);
2024-03-09 18:53:26 +03:00
if (empty($form))
{
2024-03-06 13:20:51 +03:00
return false;
}
return $form;
}
/**
2024-03-09 18:53:26 +03:00
* @inheritdoc
2024-03-06 13:20:51 +03:00
* @since version
*/
protected function loadFormData(): mixed
{
// Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_oauthserver.edit.access_token.data', []);
2024-03-09 18:53:26 +03:00
if (empty($data))
{
2024-03-06 13:20:51 +03:00
$data = $this->getItem();
}
$this->preprocessData('com_oauthserver.access_token', $data);
return $data;
}
/**
2024-03-09 18:53:26 +03:00
* @param \Webmasterskaya\Component\OauthServer\Administrator\Table\AccessTokenTable $table
*
* @return void
* @since version
*/
protected function prepareTable($table)
{
2024-03-09 18:53:26 +03:00
if ($table->expiry instanceof \DateTime || $table->expiry instanceof \DateTimeImmutable)
{
$table->expiry = $table->expiry->format($table->getDbo()->getDateFormat());
}
}
2024-03-09 18:53:26 +03:00
/**
* @param $name
* @param $prefix
* @param $options
*
* @return bool|Table|AccessTokenTable
* @throws \Exception
* @since version
*/
public function getTable($name = 'AccessToken', $prefix = 'Administrator', $options = [])
{
return parent::getTable($name, $prefix, $options);
}
2024-03-09 18:53:26 +03:00
}