Example #1
0
    public function getBrands()
    {
        $brands = array();
        $pdo = DataSource::load();
        $data = array();
        $statement = 'SELECT brand.*, category.name AS categoryName FROM brand
		LEFT JOIN category ON brand.category = category.id
		WHERE deleted = 0';
        if (!empty($this->categoryId)) {
            $statement .= ' AND category = :category';
            $data['category'] = $this->categoryId;
        }
        if ($this->status !== null) {
            $statement .= ' AND status = :status';
            $data['status'] = $this->status;
        }
        if (!empty($this->orderBy)) {
            $statement .= ' ORDER BY ' . $this->orderBy;
        }
        if (!empty($this->limit)) {
            $statement .= ' LIMIT ' . (int) $this->limit;
        }
        if (!empty($this->offset)) {
            $statement .= ' OFFSET ' . (int) $this->offset;
        }
        $preparedStatement = $pdo->prepare($statement);
        $preparedStatement->execute($data);
        $brandsData = $preparedStatement->fetchAll();
        foreach ($brandsData as $brandData) {
            $brand = new Brand();
            $brand->setProperties($brandData);
            $brands[] = $brand;
        }
        return $brands;
    }