MarkLogic/MLPHP/Facet.php
<?php
/*
Copyright 2002-2012 MarkLogic Corporation. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace MarkLogic\MLPHP;
/**
* Represents a search facet.
*
* @package MLPHP
* @author Mike Wooldridge <mike.wooldridge@marklogic.com>
*/
class Facet
{
private $name; // @var string
private $type; // @var string
private $facetValues; // @var array
/**
* Create a Facet object.
*
* @param string $facet The search-result DOMElement for the facet.
*/
public function __construct($facet)
{
$this->name = $facet->getAttribute('name');
$this->type = $facet->getAttribute('type');
$values = $facet->getElementsByTagName('facet-value');
foreach ($values as $val) {
$facetValue = new FacetValue($val->getAttribute('name'),
$val->getAttribute('count'), $val->nodeValue);
$this->facetValues[] = $facetValue;
}
}
/**
* Get the facet name.
*
* @return string The facet name.
*/
public function getName()
{
return $this->name;
}
/**
* Get the facet type.
*
* @return string The facet type.
*/
public function getType()
{
return $this->type;
}
/**
* Get the facet values.
*
* @return array An array of FacetValue objects.
*/
public function getFacetValues()
{
return $this->facetValues;
}
}