public static function get(AttributeCollection $attributeCollection, $name) { $attributes = $attributeCollection->attributes(ParameterAttribute::class); if (!empty($attributes)) { /** @var ParameterAttribute $attribute */ foreach ($attributes as $attribute) { if ($attribute instanceof ParameterAttribute && $name === $attribute->name) { return $attribute; } } } return null; }
/** * @param int $tagId * @param int $offset * @param int $limit * @param string $order * @return AttributeCollection */ public function findAttributesByTagId($tagId, $offset = 0, $limit = PHP_INT_MAX, $order = 'name ASC') { $sql = new Sql($this->adapter); $select = $sql->select(); $select->from('attribute'); $select->where(['tag_id' => $tagId]); $select->offset($offset); $select->limit($limit); $select->order($order); $statement = $sql->prepareStatementForSqlObject($select); $result = $statement->execute(); $selectStatement = $this->adapter->createStatement('SELECT FOUND_ROWS() as total;'); $total = $selectStatement->execute(); $total = (int) $total->current(); $collection = new AttributeCollection(); $collection->setTotalCount($total); foreach ($result as $row) { $entity = $this->createEntity($row); $collection->addElement($entity, $entity->getId()); } return $collection; }