1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8namespace Tiki\Recommendation; 9 10class RecommendationSet implements \Countable, \Iterator 11{ 12 private $engine; 13 private $recommendations = []; 14 private $debug = []; 15 16 function __construct($engineName) 17 { 18 $this->engine = $engineName; 19 } 20 21 function add(EngineOutput $recommendation) 22 { 23 if ($recommendation instanceof Recommendation) { 24 $this->recommendations[] = $recommendation; 25 } else { 26 $this->addDebug($recommendation); 27 } 28 } 29 30 function addDebug($info) 31 { 32 $this->debug[] = $info; 33 } 34 35 function getEngine() 36 { 37 return $this->engine; 38 } 39 40 function getDebug() 41 { 42 return new \ArrayIterator($this->debug); 43 } 44 45 function count() 46 { 47 return count($this->recommendations); 48 } 49 50 function current() 51 { 52 return current($this->recommendations); 53 } 54 55 function next() 56 { 57 next($this->recommendations); 58 } 59 60 function key() 61 { 62 return key($this->recommendations); 63 } 64 65 function valid() 66 { 67 return current($this->recommendations) !== false; 68 } 69 70 function rewind() 71 { 72 reset($this->recommendations); 73 } 74} 75