toArray(); $result = $this->wpdb->insert( $this->table, [ 'formId' => (int) $data['formId'], 'type' => $data['type'], 'enabled' => (int) $data['enabled'], 'showForm' => (int) $data['showForm'], 'message' => $data['message'], 'url' => $data['url'], 'page' => $data['page'], ], ['%d', '%s', '%d', '%d', '%s', '%s', '%s'] ); if ($result === false) { throw new QueryExecutionException( BackendStrings::getExceptionStrings()['unable_to_add_data'] . __CLASS__ ); } return $this->wpdb->insert_id; } /** * Update confirmation in the database * * @param int $id * @param Confirmation $entity * * @return bool * * @throws QueryExecutionException */ public function update(int $id, $entity): bool { $data = $entity->toArray(); $result = $this->wpdb->update( $this->table, [ 'formId' => (int) $data['formId'], 'type' => $data['type'], 'enabled' => (int) $data['enabled'], 'showForm' => (int) $data['showForm'], 'message' => $data['message'], 'url' => $data['url'], 'page' => $data['page'], ], ['id' => $id], ['%d', '%s', '%d', '%d', '%s', '%s', '%s'], ['%d'] ); if ($result === false) { throw new QueryExecutionException(BackendStrings::getAllFormsStrings()['unable_to_save_data'] . __CLASS__); } return $result; } /** * Get all confirmations by form ID. * * @param int $id * * @return array */ public function getAllById(int $id): array { $rows = $this->wpdb->get_results( $this->wpdb->prepare( $this->selectQuery() . " WHERE $this->table.formId = %d", $id ), ARRAY_A ); if (empty($rows)) { return []; } return array_map(function ($row) { return call_user_func([static::FACTORY, 'create'], $row); }, $rows); } }