wpdb = $wpdb; $this->table = $wpdb->prefix . 'aarambha_case_management_case_files'; } /** * Save the relationship between a case and an attachment. * * @param int $case_id Case ID. * @param int $attachment_id Attachment ID. * * @return bool */ public function save( int $case_id, int $attachment_id ): bool { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table, no core API available. $result = $this->wpdb->insert( $this->table, [ 'case_id' => $case_id, 'attachment_id' => $attachment_id, ], [ '%d', '%d', ] ); return false !== $result; } /** * Get all attachments for a case. * * @param int $case_id Case ID. * * @return array */ public function find_by_case_id( int $case_id ): array { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Custom plugin table, no core API available. Query is correctly prepared via // $this->wpdb->prepare() with a %d placeholder; the sniff doesn't reliably trace // prepare() calls through $this->wpdb (only the raw $wpdb global), hence the disable // block rather than a false per-line error. {$this->table} is built internally in the // constructor, never from user input. return $this->wpdb->get_results( $this->wpdb->prepare( "SELECT * FROM {$this->table} WHERE case_id = %d", $case_id ), ARRAY_A ); // phpcs:enable } /** * Delete a relationship. * * @param int $case_id Case ID. * @param int $attachment_id Attachment ID. * * @return bool */ public function delete( int $case_id, int $attachment_id ): bool { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table, no core API available. $result = $this->wpdb->delete( $this->table, [ 'case_id' => $case_id, 'attachment_id' => $attachment_id, ], [ '%d', '%d', ] ); return false !== $result; } }