one-click-accessibility/modules/remediation/database/remediation-entry.php
VasylD 7252c6c83c
[APP-1512] add backend logic for remediation management (#298)
* [APP-1512] add backend logic for remediation management

* [APP-1512] add backend logic for remediation management

* Update modules/remediation/database/remediation-entry.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/remediation/rest/items.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* [APP-1512] add backend logic for remediation management

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
2025-06-18 10:29:22 +02:00

116 lines
2.2 KiB
PHP

<?php
namespace EA11y\Modules\Remediation\Database;
use EA11y\Classes\Database\Entry;
use EA11y\Modules\Remediation\Exceptions\Missing_URL;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Page_Entry
*/
class Remediation_Entry extends Entry {
/**
* @var string $url holds page url
*/
private string $url;
public static function get_helper_class(): string {
return Remediation_Table::get_class_name();
}
/**
* Create
*
* used to ensure:
* URL is set
*
* @param string $id
*
* @throws Missing_URL
*/
public function create( string $id = 'id' ) {
if ( empty( $this->entry_data[ Remediation_Table::URL ] ) ) {
throw new Missing_URL();
}
$date_time = gmdate( 'Y-m-d H:i:s' );
$this->entry_data[ Remediation_Table::CREATED_AT ] = $date_time;
$this->entry_data[ Remediation_Table::UPDATED_AT ] = $date_time;
parent::create( $id );
}
/**
* Remove
*
* @param string $id
*/
public static function remove( string $id ) {
$where = [
[
'column' => Remediation_Table::ID,
'value' => $id,
'operator' => '=',
],
];
Remediation_Table::delete( $where );
}
/**
* get_page_remediations
*
* @param string $url
* @param bool $total
* @return array
*/
public static function get_page_remediations( string $url, bool $total = false ) : array {
$where = [
[
'column' => Remediation_Table::URL,
'value' => $url,
'operator' => '=',
],
];
$select = $total ? 'COUNT(*) as total' : '*';
return Remediation_Table::select( $select, $where );
}
public static function get_all_remediations( int $period ) : array {
$date_threshold = gmdate( 'Y-m-d H:i:s', strtotime( "-{$period} days" ) );
$where = [
[
'column' => Remediation_Table::CREATED_AT,
'value' => $date_threshold,
'operator' => '>=',
],
];
return Remediation_Table::select( '*', $where );
}
/**
* @param array $ids
*
* @return void
*/
public static function disable_remediations( array $ids ): void {
$where = [
[
'column' => Remediation_Table::ID,
'value' => $ids,
'operator' => 'IN',
],
];
$data = [
Remediation_Table::ACTIVE => 0,
];
Remediation_Table::update( $data, $where );
}
}