| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace Models;
- class DescriptionModel
- {
- private \PDO $pdo;
- public function __construct()
- {
- $dbFile = $_ENV['DB_FILE'];
- $dbPath = __DIR__ . '/../' . $dbFile;
- $this->pdo = new \PDO("sqlite:" . $dbPath);
- $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
- }
- public function getDescriptionsByCompany(int $companyId): array
- {
- $stmt = $this->pdo->prepare("
- SELECT d.description_id, d.description_text, d.product_id
- FROM description d
- WHERE d.company_id = :company_id
- ");
- $stmt->execute(['company_id' => $companyId]);
- return $stmt->fetchAll(\PDO::FETCH_ASSOC);
- }
- public function addDescription(int $productId, int $companyId, string $text): bool
- {
- $stmt = $this->pdo->prepare("
- INSERT INTO description (description_text, product_id, company_id)
- VALUES (:text, :product_id, :company_id)
- ");
- return $stmt->execute([
- 'text' => $text,
- 'product_id' => $productId,
- 'company_id' => $companyId,
- ]);
- }
- public function updateDescription(int $descriptionId, string $text): bool
- {
- $stmt = $this->pdo->prepare("
- UPDATE description SET description_text = :text
- WHERE description_id = :id
- ");
- return $stmt->execute([
- 'text' => $text,
- 'id' => $descriptionId,
- ]);
- }
- }
|