2026-02-04 23:31:53 +01:00
< ? php
2026-02-11 19:28:12 +01:00
namespace MintyPHP\Repository\Org ;
2026-02-04 23:31:53 +01:00
use MintyPHP\DB ;
2026-02-11 19:28:12 +01:00
use MintyPHP\Repository\Support\RepoQuery ;
2026-02-04 23:31:53 +01:00
class DepartmentRepository
{
2026-02-23 12:58:19 +01:00
private function unwrap ( ? array $row ) : ? array
2026-02-04 23:31:53 +01:00
{
if ( ! $row ) {
return null ;
}
return $row [ 'departments' ] ? ? null ;
}
2026-02-23 12:58:19 +01:00
private function unwrapList ( $rows ) : array
2026-02-04 23:31:53 +01:00
{
if ( ! is_array ( $rows )) {
return [];
}
$list = [];
foreach ( $rows as $row ) {
$department = $row [ 'departments' ] ? ? null ;
if ( is_array ( $department )) {
$list [] = $department ;
}
}
return $list ;
}
2026-02-23 12:58:19 +01:00
public function list () : array
2026-02-04 23:31:53 +01:00
{
$rows = DB :: select (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select id, uuid, description, tenant_id, code, cost_center, active, created_by, modified_by, created, modified from departments order by id desc'
2026-02-04 23:31:53 +01:00
);
2026-02-23 12:58:19 +01:00
return $this -> unwrapList ( $rows );
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function listIds () : array
2026-02-04 23:31:53 +01:00
{
$rows = DB :: select ( 'select id from departments' );
if ( ! is_array ( $rows )) {
return [];
}
$ids = [];
foreach ( $rows as $row ) {
$data = $row [ 'departments' ] ? ? $row ;
if ( is_array ( $data ) && isset ( $data [ 'id' ])) {
$ids [] = ( int ) $data [ 'id' ];
}
}
return array_values ( array_unique ( $ids ));
}
2026-02-23 12:58:19 +01:00
public function listActiveIdsByTenantIds ( array $tenantIds ) : array
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
{
$tenantIds = array_values ( array_unique ( array_map ( 'intval' , $tenantIds )));
$tenantIds = array_filter ( $tenantIds , static fn ( $id ) => $id > 0 );
if ( ! $tenantIds ) {
return [];
}
$placeholders = implode ( ',' , array_fill ( 0 , count ( $tenantIds ), '?' ));
$rows = DB :: select (
'select id from departments where active = 1 and tenant_id in (' . $placeholders . ')' ,
... array_map ( 'strval' , $tenantIds )
);
if ( ! is_array ( $rows )) {
return [];
}
$ids = [];
foreach ( $rows as $row ) {
$data = $row [ 'departments' ] ? ? $row ;
if ( is_array ( $data ) && isset ( $data [ 'id' ])) {
$ids [] = ( int ) $data [ 'id' ];
}
}
return array_values ( array_unique ( $ids ));
}
2026-02-23 12:58:19 +01:00
public function listByTenantIds ( array $tenantIds ) : array
2026-02-04 23:31:53 +01:00
{
$tenantIds = array_values ( array_unique ( array_map ( 'intval' , $tenantIds )));
$tenantIds = array_filter ( $tenantIds , static fn ( $id ) => $id > 0 );
if ( ! $tenantIds ) {
return [];
}
$placeholders = implode ( ',' , array_fill ( 0 , count ( $tenantIds ), '?' ));
$rows = DB :: select (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select departments.id, departments.uuid, departments.description, departments.tenant_id, departments.code, departments.cost_center, departments.active, departments.created_by, departments.modified_by, departments.created, departments.modified ' .
" from departments departments join tenants t on t.id = departments.tenant_id and t.status = 'active' " .
'where departments.active = 1 and departments.tenant_id in (' . $placeholders . ') ' .
2026-02-04 23:31:53 +01:00
'order by departments.description asc' ,
... array_map ( 'strval' , $tenantIds )
);
2026-02-23 12:58:19 +01:00
return $this -> unwrapList ( $rows );
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function listByIds ( array $departmentIds , bool $includeInactive = false ) : array
2026-02-04 23:31:53 +01:00
{
$departmentIds = array_values ( array_unique ( array_map ( 'intval' , $departmentIds )));
$departmentIds = array_filter ( $departmentIds , static fn ( $id ) => $id > 0 );
if ( ! $departmentIds ) {
return [];
}
$placeholders = implode ( ',' , array_fill ( 0 , count ( $departmentIds ), '?' ));
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$activeSql = $includeInactive ? '' : 'active = 1 and ' ;
2026-02-04 23:31:53 +01:00
$rows = DB :: select (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select id, uuid, description, tenant_id, code, cost_center, active, created_by, modified_by, created, modified from departments where ' . $activeSql . 'id in (' . $placeholders . ') order by description asc' ,
2026-02-04 23:31:53 +01:00
... array_map ( 'strval' , $departmentIds )
);
2026-02-23 12:58:19 +01:00
return $this -> unwrapList ( $rows );
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function listPaged ( array $options ) : array
2026-02-04 23:31:53 +01:00
{
$search = trim (( string ) ( $options [ 'search' ] ? ? '' ));
$tenant = trim (( string ) ( $options [ 'tenant' ] ? ? '' ));
2026-02-11 19:28:12 +01:00
$allowedOrder = [ 'id' , 'uuid' , 'description' , 'code' , 'cost_center' , 'active' , 'created' , 'modified' ];
[ $limit , $offset ] = RepoQuery :: sanitizeLimitOffset ( $options );
[ $order , $dir ] = RepoQuery :: sanitizeOrder ( $options , $allowedOrder );
2026-02-04 23:31:53 +01:00
$where = [];
$params = [];
2026-02-11 19:28:12 +01:00
RepoQuery :: addLikeFilter (
$where ,
$params ,
[ 'description' , 'uuid' , 'code' , 'cost_center' ],
$search
);
$activeValue = array_key_exists ( 'active' , $options ) ? $options [ 'active' ] : null ;
RepoQuery :: addEnumFilter ( $where , $params , $activeValue , [
[ 'aliases' => [ '1' , 'true' , 'active' ], 'sql' => 'departments.active = 1' ],
[ 'aliases' => [ '0' , 'false' , 'inactive' ], 'sql' => 'departments.active = 0' ],
]);
RepoQuery :: addEqualsFilter (
$where ,
$params ,
$tenant ,
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
" exists (select 1 from tenants t where t.id = departments.tenant_id and t.status = 'active' and t.uuid = ?) "
2026-02-11 19:28:12 +01:00
);
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
2026-02-04 23:31:53 +01:00
if ( ! empty ( $options [ 'tenantUserId' ])) {
$tenantUserId = ( int ) $options [ 'tenantUserId' ];
if ( $tenantUserId > 0 ) {
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$where [] = 'exists (select 1 from user_tenants ut ' .
" join tenants t on t.id = ut.tenant_id and t.status = 'active' " .
'where ut.user_id = ? and ut.tenant_id = departments.tenant_id)' ;
$params [] = ( string ) $tenantUserId ;
2026-02-04 23:31:53 +01:00
}
} elseif ( array_key_exists ( 'tenantIds' , $options )) {
$tenantIds = $options [ 'tenantIds' ];
$tenantIds = is_array ( $tenantIds ) ? array_values ( array_unique ( array_map ( 'intval' , $tenantIds ))) : [];
if ( $tenantIds ) {
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$where [] = 'departments.tenant_id in (???)' ;
$params [] = $tenantIds ;
2026-02-04 23:31:53 +01:00
} else {
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$where [] = '1=0' ;
2026-02-04 23:31:53 +01:00
}
}
$whereSql = $where ? ( ' where ' . implode ( ' and ' , $where )) : '' ;
$count = DB :: selectValue ( 'select count(*) from departments' . $whereSql , ... $params );
$total = $count ? ( int ) $count : 0 ;
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$query = 'select id, uuid, description, tenant_id, code, cost_center, active, created_by, modified_by, created, modified from departments' .
2026-02-04 23:31:53 +01:00
$whereSql .
sprintf ( ' order by `%s` %s limit ? offset ?' , $order , $dir );
$queryParams = array_merge ( $params , [( string ) $limit , ( string ) $offset ]);
$rows = call_user_func_array ([ 'MintyPHP\\DB' , 'select' ], array_merge ([ $query ], $queryParams ));
2026-02-23 12:58:19 +01:00
$list = $this -> unwrapList ( $rows );
2026-02-04 23:31:53 +01:00
$ids = [];
foreach ( $list as $department ) {
if ( isset ( $department [ 'id' ])) {
$ids [] = ( int ) $department [ 'id' ];
}
}
$tenantLabelsByDepartment = [];
if ( $ids ) {
$placeholders = implode ( ',' , array_fill ( 0 , count ( $ids ), '?' ));
$labelRows = DB :: select (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select d.id as department_id, t.description as description from departments d join tenants t on t.id = d.tenant_id ' .
'where d.id in (' . $placeholders . ') order by t.description asc' ,
2026-02-04 23:31:53 +01:00
... array_map ( 'strval' , $ids )
);
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
foreach (( array ) $labelRows as $row ) {
$departmentId = 0 ;
$label = '' ;
foreach (( array ) $row as $table ) {
if ( ! is_array ( $table )) {
continue ;
2026-02-04 23:31:53 +01:00
}
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
if ( $departmentId === 0 && isset ( $table [ 'department_id' ])) {
$departmentId = ( int ) $table [ 'department_id' ];
2026-02-04 23:31:53 +01:00
}
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
if ( $label === '' && isset ( $table [ 'description' ])) {
$label = ( string ) $table [ 'description' ];
2026-02-04 23:31:53 +01:00
}
}
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
if ( $departmentId > 0 && $label !== '' ) {
$tenantLabelsByDepartment [ $departmentId ] = [ $label ];
}
}
2026-02-04 23:31:53 +01:00
}
foreach ( $list as & $department ) {
$departmentId = ( int ) ( $department [ 'id' ] ? ? 0 );
$department [ 'tenant_labels' ] = $tenantLabelsByDepartment [ $departmentId ] ? ? [];
}
unset ( $department );
return [
'total' => $total ,
'rows' => $list ,
];
}
2026-02-23 12:58:19 +01:00
public function find ( int $id ) : ? array
2026-02-04 23:31:53 +01:00
{
$row = DB :: selectOne (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select id, uuid, description, tenant_id, code, cost_center, active, created_by, modified_by, created, modified from departments where id = ? limit 1' ,
2026-02-04 23:31:53 +01:00
( string ) $id
);
2026-02-23 12:58:19 +01:00
return $this -> unwrap ( $row );
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function findByUuid ( string $uuid ) : ? array
2026-02-04 23:31:53 +01:00
{
$row = DB :: selectOne (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'select id, uuid, description, tenant_id, code, cost_center, active, created_by, modified_by, created, modified from departments where uuid = ? limit 1' ,
2026-02-04 23:31:53 +01:00
$uuid
);
2026-02-23 12:58:19 +01:00
return $this -> unwrap ( $row );
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function existsByCode ( string $code , int $excludeId = 0 ) : bool
2026-02-11 19:28:12 +01:00
{
$code = trim ( $code );
if ( $code === '' ) {
return false ;
}
if ( $excludeId > 0 ) {
$count = DB :: selectValue ( 'select count(*) from departments where code = ? and id != ?' , $code , ( string ) $excludeId );
} else {
$count = DB :: selectValue ( 'select count(*) from departments where code = ?' , $code );
}
return ( int ) $count > 0 ;
}
2026-02-23 12:58:19 +01:00
public function existsByTenantAndDescription ( int $tenantId , string $description , int $excludeId = 0 ) : bool
2026-02-04 23:31:53 +01:00
{
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
$tenantId = ( int ) $tenantId ;
$description = trim ( $description );
if ( $tenantId <= 0 || $description === '' ) {
return false ;
}
if ( $excludeId > 0 ) {
$count = DB :: selectValue (
'select count(*) from departments where tenant_id = ? and lower(description) = lower(?) and id != ?' ,
( string ) $tenantId ,
$description ,
( string ) $excludeId
);
} else {
$count = DB :: selectValue (
'select count(*) from departments where tenant_id = ? and lower(description) = lower(?)' ,
( string ) $tenantId ,
$description
);
}
return ( int ) $count > 0 ;
}
2026-02-23 12:58:19 +01:00
public function countByTenantId ( int $tenantId ) : int
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
{
if ( $tenantId <= 0 ) {
return 0 ;
}
$count = DB :: selectValue ( 'select count(*) from departments where tenant_id = ?' , ( string ) $tenantId );
return $count ? ( int ) $count : 0 ;
2026-02-04 23:31:53 +01:00
}
2026-02-23 12:58:19 +01:00
public function create ( array $data )
2026-02-04 23:31:53 +01:00
{
return DB :: insert (
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'insert into departments (uuid, description, tenant_id, code, cost_center, active, created_by, created) values (?,?,?,?,?,?,?,NOW())' ,
$data [ 'uuid' ] ? ? RepoQuery :: uuidV4 (),
2026-02-04 23:31:53 +01:00
$data [ 'description' ],
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
( string ) ( $data [ 'tenant_id' ] ? ? 0 ),
2026-02-11 19:28:12 +01:00
$data [ 'code' ] ? ? null ,
$data [ 'cost_center' ] ? ? null ,
$data [ 'active' ] ? ? 1 ,
2026-02-04 23:31:53 +01:00
$data [ 'created_by' ] ? ? null
);
}
2026-02-23 12:58:19 +01:00
public function update ( int $id , array $data ) : bool
2026-02-04 23:31:53 +01:00
{
$fields = [
'description' => $data [ 'description' ],
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
'tenant_id' => ( string ) ( $data [ 'tenant_id' ] ? ? 0 ),
2026-02-11 19:28:12 +01:00
'code' => $data [ 'code' ] ? ? null ,
'cost_center' => $data [ 'cost_center' ] ? ? null ,
'active' => $data [ 'active' ] ? ? 1 ,
2026-02-04 23:31:53 +01:00
];
if ( array_key_exists ( 'modified_by' , $data )) {
$fields [ 'modified_by' ] = $data [ 'modified_by' ];
}
$setParts = [];
$params = [];
foreach ( $fields as $field => $value ) {
$setParts [] = sprintf ( '`%s` = ?' , $field );
$params [] = $value ;
}
$params [] = ( string ) $id ;
$query = 'update departments set ' . implode ( ', ' , $setParts ) . ' where id = ?' ;
$result = DB :: update ( $query , ... $params );
return $result !== false ;
}
2026-02-23 12:58:19 +01:00
public function setTenant ( int $id , int $tenantId ) : bool
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
{
if ( $id <= 0 || $tenantId <= 0 ) {
return false ;
}
$result = DB :: update (
'update departments set tenant_id = ? where id = ?' ,
( string ) $tenantId ,
( string ) $id
);
return $result !== false ;
}
2026-02-23 12:58:19 +01:00
public function delete ( int $id ) : bool
2026-02-04 23:31:53 +01:00
{
$result = DB :: delete ( 'delete from departments where id = ?' , ( string ) $id );
return $result !== false ;
}
}