| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | * Constructor |
| 28 | 28 | */ |
| 29 | 29 | public function __construct() |
| 30 | 30 | { |
| 31 | - parent::__construct(ClassificationsTable::getTableName()); | |
| 31 | + parent::__construct(); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Get table name |
| @@ -51,8 +51,32 @@ | ||
| 51 | 51 | ClassificationTypes::DIFFICULTY, |
| 52 | 52 | $slug |
| 53 | 53 | ) |
| 54 | 54 | ); |
| 55 | + return $result ?: null; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Find by name (case-insensitive match) | |
| 60 | + */ | |
| 61 | + public function findByName(string $name): ?\stdClass | |
| 62 | + { | |
| 63 | + $name = trim($name); | |
| 64 | + if ($name === '') { | |
| 65 | + return null; | |
| 66 | + } | |
| 67 | + | |
| 68 | + $table = esc_sql($this->table); | |
| 69 | + $result = $this->wpdb->get_row( | |
| 70 | + $this->wpdb->prepare( | |
| 71 | + "SELECT * FROM `{$table}` | |
| 72 | + WHERE type = %s AND LOWER(name) = LOWER(%s) | |
| 73 | + LIMIT 1", | |
| 74 | + ClassificationTypes::DIFFICULTY, | |
| 75 | + $name | |
| 76 | + ) | |
| 77 | + ); | |
| 78 | + | |
| 55 | 79 | return $result ?: null; |
| 56 | 80 | } |
| 57 | 81 | |
| 58 | 82 | /** |