Add goals repository and configurable rules engine
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
939193f258
commit
7155396312
19 files changed
+882
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Core;
|
||||
|
||||
use StreamGoals\Rules\StateRepository;
|
||||
|
||||
/** $wpdb-backed sg_state access (goal_id, skey, svalue). Requires live WordPress. */
|
||||
final class StateStore implements StateRepository {
|
||||
|
||||
private \wpdb $db;
|
||||
|
||||
public function __construct( ?\wpdb $db = null ) {
|
||||
$this->db = $db ?? $GLOBALS['wpdb'];
|
||||
}
|
||||
|
||||
public function getInt( int $goalId, string $key, int $default = 0 ): int {
|
||||
$t = $this->db->prefix . 'sg_state';
|
||||
$v = $this->db->get_var( $this->db->prepare( "SELECT svalue FROM {$t} WHERE goal_id = %d AND skey = %s", $goalId, $key ) );
|
||||
return null === $v ? $default : (int) $v;
|
||||
}
|
||||
|
||||
public function setInt( int $goalId, string $key, int $value ): void {
|
||||
$t = $this->db->prefix . 'sg_state';
|
||||
$this->db->query(
|
||||
$this->db->prepare(
|
||||
"INSERT INTO {$t} (goal_id, skey, svalue, updated_at) VALUES (%d, %s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE svalue = VALUES(svalue), updated_at = VALUES(updated_at)",
|
||||
$goalId,
|
||||
$key,
|
||||
(string) $value,
|
||||
gmdate( 'Y-m-d H:i:s' )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user