db = $db ?? $GLOBALS['wpdb']; } public function enabledForGoal( int $goalId ): array { $t = $this->db->prefix . 'sg_rules'; $rows = $this->db->get_results( $this->db->prepare( "SELECT id, goal_id, type, config FROM {$t} WHERE goal_id = %d AND enabled = 1 ORDER BY sort ASC, id ASC", $goalId ), ARRAY_A ); $out = array(); foreach ( (array) $rows as $r ) { $cfg = json_decode( (string) $r['config'], true ); $out[] = new RuleDef( (int) $r['id'], (int) $r['goal_id'], (string) $r['type'], is_array( $cfg ) ? $cfg : array() ); } return $out; } }