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
8class Search_Expr_Or implements Search_Expr_Interface
9{
10	private $parts;
11	private $weight = 1.0;
12
13	function __construct(array $parts)
14	{
15		$parts = array_filter($parts);
16		$this->parts = $parts;
17	}
18
19	function __clone()
20	{
21		$this->parts = array_map(function ($part) {
22			return clone $part;
23		}, $this->parts);
24	}
25
26	function addPart(Search_Expr_Interface $part)
27	{
28		$this->parts[] = $part;
29	}
30
31	function setType($type)
32	{
33		foreach ($this->parts as $part) {
34			$part->setType($type);
35		}
36	}
37
38	function setField($field = 'global')
39	{
40		foreach ($this->parts as $part) {
41			$part->setField($field);
42		}
43	}
44
45	function setWeight($weight)
46	{
47		$this->weight = (float) $weight;
48	}
49
50	function getWeight()
51	{
52		return $this->weight;
53	}
54
55	function walk($callback)
56	{
57		$results = [];
58		foreach ($this->parts as $part) {
59			$results[] = $part->walk($callback);
60		}
61
62		return call_user_func($callback, $this, $results);
63	}
64
65	function traverse($callback)
66	{
67		return call_user_func($callback, $callback, $this, $this->parts);
68	}
69}
70