PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / trunk
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager vtrunk
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / modules / script / database / script-entry.php

script-entry.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager trunk, at modules/script/database/script-entry.php

67 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Cookiez\Modules\Script\Database;
4
5 use Cookiez\Classes\Database\Entry;
6 use Cookiez\Modules\Script\Classes\Dto\Script_DTO;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Script_Entry extends Entry {
13 protected static function get_helper_class(): string {
14 return Script_Table::class;
15 }
16
17 public static function find_all(): array {
18 return (array) Script_Table::select( '*' );
19 }
20
21 public static function find_by_value( string $value ): ?Script_Entry {
22 $result = Script_Table::first( '*', [ Script_Table::VALUE => $value ] );
23
24 if ( ! $result ) {
25 return null;
26 }
27
28 return new self( [ 'data' => $result ] );
29 }
30
31 public static function insert_one( Script_DTO $dto ): Script_Entry {
32 $entry = new self();
33
34 foreach ( $dto->to_entry() as $key => $value ) {
35 $entry->set( $key, $value );
36 }
37
38 $entry->create();
39
40 return $entry;
41 }
42
43 public static function update_one( int $id, Script_DTO $dto ): void {
44 $entry = new self( [ 'id' => $id ] );
45
46 foreach ( $dto->to_entry() as $key => $value ) {
47 $entry->set( $key, $value );
48 }
49
50 $entry->save();
51 }
52
53 public static function detach_from_cookie( int $cookie_id ): void {
54 Script_Table::update(
55 [ Script_Table::COOKIE_ID => null ],
56 [ Script_Table::COOKIE_ID => $cookie_id ]
57 );
58 }
59
60 public static function retag_for_cookie( int $cookie_id, string $category ): void {
61 Script_Table::update(
62 [ Script_Table::CATEGORY => $category ],
63 [ Script_Table::COOKIE_ID => $cookie_id ]
64 );
65 }
66 }
67