/**
  * This function returns the products by using the product filter.
  *
  * @author David Pauli <*****@*****.**>
  * @return Product[] Returns an array of products.
  * @since 0.0.0
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  * @since 0.1.2 Add error reporting.
  * @since 0.1.3 Get all results.
  * @since 0.2.0 Set error message for empty responses to notify.
  * @since 0.2.1 Implement REST client fixes.
  */
 public function getProducts()
 {
     $this->errorReset();
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH . "?" . $parameter);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("PF-8");
         Logger::notify("ep6\\ProductFilter\nREST respomd for getting products is empty.");
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         $this->errorSet("PF-9");
         Logger::error("ep6\\ProductFilter\nRespond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $this->results = $content['results'];
     $products = array();
     // is there any product found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $product = new Product($item);
             // go to every filter
             foreach ($this->filters as $filter) {
                 switch ($filter->getAttribute()) {
                     case 'stocklevel':
                         $value = array();
                         $value["stocklevel"] = $product->getStocklevel();
                         break;
                     case 'price':
                         $value = array();
                         $value["price"] = $product->getPrice()->getAmount();
                         break;
                     case 'category':
                         $value = array();
                         $value["category"] = $product->getCategories();
                         break;
                     default:
                         $value = $item;
                         break;
                 }
                 if (!InputValidator::isEmptyArrayKey($value, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) {
                     if (!InputValidator::isArray($value[$filter->getAttribute()])) {
                         if (!$filter->isElementInFilter($value)) {
                             continue 2;
                         }
                     }
                 } else {
                     continue 2;
                 }
             }
             array_push($products, $product);
         }
     }
     return $products;
 }