table = empty(phpb_config('page.translation.table')) ? 'page_translations' : phpb_config('page.translation.table'); parent::__construct(); $this->class = phpb_instance('page.translation'); } /** * Determine whether a route is already used by another page translation. * * @param string $route * @param mixed|null $excludedPageId * @return bool */ public function routeExists(string $route, $excludedPageId = null): bool { $query = "SELECT 1 FROM {$this->table} WHERE route = ?"; $parameters = [$route]; if ($excludedPageId !== null) { $foreignKey = $this->removeNonAlphaNumeric(phpb_config('page.translation.foreign_key')); $query .= " AND {$foreignKey} != ?"; $parameters[] = $excludedPageId; } $query .= ' LIMIT 1'; return ! empty($this->db->select($query, $parameters)); } /** * Return translations belonging to the given page IDs. * * @param array $pageIds * @return array */ public function getForPages(array $pageIds): array { if (empty($pageIds)) { return []; } $foreignKey = $this->removeNonAlphaNumeric(phpb_config('page.translation.foreign_key')); $placeholders = implode(', ', array_fill(0, count($pageIds), '?')); $records = $this->db->select( "SELECT * FROM {$this->table} WHERE {$foreignKey} IN ({$placeholders})", array_values($pageIds) ); return $this->createInstances($records); } }