mirror of
https://github.com/Karaka-Management/oms-Script.git
synced 2026-01-11 20:38:42 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
7a22d48a99
commit
d40e5d9e13
|
|
@ -31,7 +31,7 @@ use Modules\Media\Models\NullMedia;
|
|||
use Modules\Tag\Models\NullTag;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Autoloader;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
|
@ -77,10 +77,18 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
/** @var Template $template */
|
||||
$template = TemplateMapper::get((int) $request->getData('id'));
|
||||
$accountId = $request->header->account;
|
||||
$template = TemplateMapper::get()
|
||||
->with('source')
|
||||
->with('source/sources')
|
||||
->with('reports')
|
||||
->with('reports/source')
|
||||
->with('reports/source/sources')
|
||||
->with('createdBy')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
$isExport = \in_array($request->getData('type'), ['xlsx', 'pdf', 'docx', 'pptx', 'csv', 'json']);
|
||||
$accountId = $request->header->account;
|
||||
$isExport = \in_array($request->getData('type'), ['xlsx', 'pdf', 'docx', 'pptx', 'csv', 'json']);
|
||||
|
||||
// is allowed to read
|
||||
if (!$this->app->accountManager->get($accountId)->hasPermission(PermissionType::READ, $this->app->orgId, null, self::NAME, PermissionState::REPORT, $template->getId())
|
||||
|
|
@ -285,13 +293,17 @@ final class ApiController extends Controller
|
|||
|
||||
$view = new View($this->app->l11nManager, $request, $response);
|
||||
if (!$template->isStandalone) {
|
||||
/** @var Report[] $report */
|
||||
$report = ReportMapper::getNewest(1,
|
||||
(new Builder($this->app->dbPool->get()))->where('helper_report_d3.helper_report_template', '=', $template->getId())
|
||||
);
|
||||
/** @var Report $report */
|
||||
$report = ReportMapper::get()
|
||||
->with('template')
|
||||
->with('source')
|
||||
->with('source/sources')
|
||||
->where('template', $template->getId())
|
||||
->sort('id', OrderType::DESC)
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
$rcoll = [];
|
||||
$report = \end($report);
|
||||
$report = $report === false ? new NullReport() : $report;
|
||||
|
||||
if (!($report instanceof NullReport)) {
|
||||
|
|
@ -381,7 +393,7 @@ final class ApiController extends Controller
|
|||
$collection->setPath('/Modules/Media/Files/Modules/Helper/' . ((string) ($request->getData('name') ?? '')));
|
||||
$collection->setVirtualPath('/Modules/Helper');
|
||||
|
||||
CollectionMapper::create($collection);
|
||||
CollectionMapper::create()->execute($collection);
|
||||
|
||||
$template = $this->createTemplateFromRequest($request, $collection->getId());
|
||||
|
||||
|
|
@ -528,7 +540,7 @@ final class ApiController extends Controller
|
|||
return;
|
||||
}
|
||||
|
||||
CollectionMapper::create($collection);
|
||||
CollectionMapper::create()->execute($collection);
|
||||
|
||||
$report = $this->createReportFromRequest($request, $response, $collection->getId());
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use Modules\Media\Models\Media;
|
|||
use Modules\Media\Theme\Backend\Components\Upload\BaseView;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Utils\StringUtils;
|
||||
|
|
@ -58,7 +59,7 @@ final class BackendController extends Controller
|
|||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002701001, $request, $response));
|
||||
|
||||
$path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/'));
|
||||
$templates = TemplateMapper::with('language', $response->getLanguage())::getByVirtualPath($path);
|
||||
$templates = TemplateMapper::getByVirtualPath($path)->with('tags')->with('tags/title')->where('tags/title/language', $response->getLanguage())->execute();
|
||||
|
||||
list($collection, $parent) = CollectionMapper::getCollectionsByPath($path);
|
||||
|
||||
|
|
@ -143,7 +144,15 @@ final class BackendController extends Controller
|
|||
//$file = preg_replace('([^\w\s\d\-_~,;:\.\[\]\(\).])', '', $template->getName());
|
||||
|
||||
/** @var Template $template */
|
||||
$template = TemplateMapper::with('language', $response->getLanguage())::get((int) $request->getData('id'));
|
||||
$template = TemplateMapper::get()
|
||||
->with('createdBy')
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->with('source')
|
||||
->with('source/sources')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->where('tags/title/language', $response->getLanguage())
|
||||
->execute();
|
||||
|
||||
$view->setTemplate('/Modules/Helper/Theme/Backend/helper-single');
|
||||
|
||||
|
|
@ -192,9 +201,7 @@ final class BackendController extends Controller
|
|||
}
|
||||
|
||||
/** @var \Modules\Helper\Models\Report[] $report */
|
||||
$report = ReportMapper::getNewest(1,
|
||||
(new Builder($this->app->dbPool->get()))->where('helper_report.helper_report_template', '=', $template->getId())
|
||||
);
|
||||
$report = ReportMapper::get()->where('template', $template->getId())->sort('id', OrderType::DESC)->limit(1)->execute();
|
||||
|
||||
$rcoll = [];
|
||||
$report = \end($report);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\Helper\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Report mapper class.
|
||||
|
|
@ -25,7 +25,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class ReportMapper extends DataMapperAbstract
|
||||
final class ReportMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -33,7 +33,7 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'helper_report_id' => ['name' => 'helper_report_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'helper_report_status' => ['name' => 'helper_report_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'helper_report_title' => ['name' => 'helper_report_title', 'type' => 'string', 'internal' => 'title'],
|
||||
|
|
@ -51,7 +51,7 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'source' => [
|
||||
'mapper' => \Modules\Media\Models\CollectionMapper::class,
|
||||
'external' => 'helper_report_media',
|
||||
|
|
@ -68,7 +68,7 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'helper_report_creator',
|
||||
|
|
@ -81,7 +81,7 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'helper_report';
|
||||
public const TABLE = 'helper_report';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -89,7 +89,7 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'helper_report_id';
|
||||
public const PRIMARYFIELD ='helper_report_id';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -97,5 +97,5 @@ final class ReportMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'helper_report_created';
|
||||
public const CREATED_AT = 'helper_report_created';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ use Modules\Admin\Models\AccountMapper;
|
|||
use Modules\Media\Models\CollectionMapper;
|
||||
use Modules\Organization\Models\UnitMapper;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Database\Mapper\ReadMapper;
|
||||
|
||||
/**
|
||||
* Report mapper class.
|
||||
|
|
@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\RelationType;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class TemplateMapper extends DataMapperAbstract
|
||||
final class TemplateMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -37,7 +37,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'helper_template_id' => ['name' => 'helper_template_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'helper_template_status' => ['name' => 'helper_template_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'helper_template_title' => ['name' => 'helper_template_title', 'type' => 'string', 'internal' => 'name'],
|
||||
|
|
@ -59,7 +59,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'source' => [
|
||||
'mapper' => CollectionMapper::class,
|
||||
'external' => 'helper_template_media',
|
||||
|
|
@ -72,7 +72,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'helper_template_creator',
|
||||
|
|
@ -89,7 +89,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'reports' => [
|
||||
'mapper' => ReportMapper::class,
|
||||
'table' => 'helper_report',
|
||||
|
|
@ -110,7 +110,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'helper_template';
|
||||
public const TABLE = 'helper_template';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -118,7 +118,7 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'helper_template_created';
|
||||
public const CREATED_AT = 'helper_template_created';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -126,23 +126,23 @@ final class TemplateMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'helper_template_id';
|
||||
public const PRIMARYFIELD ='helper_template_id';
|
||||
|
||||
/**
|
||||
* Get editor doc based on virtual path.
|
||||
*
|
||||
* @param string $virtualPath Virtual path
|
||||
*
|
||||
* @return array
|
||||
* @return ReadMapper
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getByVirtualPath(string $virtualPath = '/') : array
|
||||
public static function getByVirtualPath(string $virtualPath = '/') : ReadMapper
|
||||
{
|
||||
$depth = 3;
|
||||
$query = self::getQuery(depth: $depth);
|
||||
$query->where(self::$table . '_d' . $depth . '.helper_template_virtual', '=', $virtualPath);
|
||||
|
||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
return self::getAll()
|
||||
->with('createdBy')
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->where('virtualPath', $virtualPath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use phpOMS\Uri\UriFactory;
|
|||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
*/
|
||||
$templateList = \Modules\Helper\Models\TemplateMapper::getAll();
|
||||
$templateList = \Modules\Helper\Models\TemplateMapper::getAll()->execute();
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$CONFIG = [
|
||||
|
|
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
|
|||
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
||||
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ final class ReportMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$report->source = $collection;
|
||||
|
||||
$id = ReportMapper::create($report);
|
||||
$id = ReportMapper::create()->execute($report);
|
||||
self::assertGreaterThan(0, $report->getId());
|
||||
self::assertEquals($id, $report->getId());
|
||||
|
||||
$reportR = ReportMapper::get($report->getId());
|
||||
$reportR = ReportMapper::get()->with('template')->where('id', $report->getId())->execute();
|
||||
self::assertEquals($report->createdAt->format('Y-m-d'), $reportR->createdAt->format('Y-m-d'));
|
||||
self::assertEquals($report->createdBy->getId(), $reportR->createdBy->getId());
|
||||
self::assertEquals($report->description, $reportR->description);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Modules\Helper\Models\TemplateDataType;
|
|||
use Modules\Helper\Models\TemplateMapper;
|
||||
use Modules\Media\Models\Collection;
|
||||
use Modules\Media\Models\Media;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Helper\Models\TemplateMapperTest: Template database mapper
|
||||
|
|
@ -101,11 +102,11 @@ final class TemplateMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$template->source = $collection;
|
||||
|
||||
$id = TemplateMapper::create($template);
|
||||
$id = TemplateMapper::create()->execute($template);
|
||||
self::assertGreaterThan(0, $template->getId());
|
||||
self::assertEquals($id, $template->getId());
|
||||
|
||||
$templateR = TemplateMapper::get($template->getId());
|
||||
$templateR = TemplateMapper::get()->where('id', $template->getId())->execute();
|
||||
self::assertEquals($template->createdAt->format('Y-m-d'), $templateR->createdAt->format('Y-m-d'));
|
||||
self::assertEquals($template->createdBy->getId(), $templateR->createdBy->getId());
|
||||
self::assertEquals($template->description, $templateR->description);
|
||||
|
|
@ -124,7 +125,7 @@ final class TemplateMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testNewest() : void
|
||||
{
|
||||
$newest = TemplateMapper::getNewest(1);
|
||||
$newest = TemplateMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->execute();
|
||||
|
||||
self::assertCount(1, $newest);
|
||||
}
|
||||
|
|
@ -135,7 +136,7 @@ final class TemplateMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testVirtualPath() : void
|
||||
{
|
||||
$virtualPath = TemplateMapper::getByVirtualPath('/');
|
||||
$virtualPath = TemplateMapper::getByVirtualPath('/')->execute();
|
||||
|
||||
self::assertGreaterThan(0, \count($virtualPath));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user