1<?php
2/**
3 * Return all KolabInetOrgPersons with the given uid or mail address.
4 *
5 * PHP version 5
6 *
7 * @category Kolab
8 * @package  Kolab_Server
9 * @author   Gunnar Wrobel <wrobel@pardus.de>
10 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @link     http://pear.horde.org/index.php?package=Kolab_Server
12 */
13
14/**
15 * Return all KolabInetOrgPersons with the given uid or mail address.
16 *
17 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
18 *
19 * See the enclosed file COPYING for license information (LGPL). If you
20 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21 *
22 * @category Kolab
23 * @package  Kolab_Server
24 * @author   Gunnar Wrobel <wrobel@pardus.de>
25 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
26 * @link     http://pear.horde.org/index.php?package=Kolab_Server
27 */
28class Horde_Kolab_Server_Search_Operation_Guidforuidormail
29implements Horde_Kolab_Server_Search_Operation_Interface
30{
31    /**
32     * A link to the search.
33     *
34     * @var Horde_Kolab_Server_Search
35     */
36    private $_search;
37
38    /**
39     * Constructor
40     *
41     * @param Horde_Kolab_Server_Structure_Interface $structure A link to the
42     *                                                          server
43     *                                                          structure.
44     */
45    public function __construct(
46        Horde_Kolab_Server_Structure_Interface $structure
47    ) {
48        $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict(
49            new Horde_Kolab_Server_Search_Operation_Restrictkolab(
50                $structure
51            )
52        );
53    }
54
55    /**
56     * Return the reference to the server structure.
57     *
58     * @return Horde_Kolab_Server_Structure_Interface
59     */
60    public function getStructure()
61    {
62        return $this->_search->getStructure();
63    }
64
65    /**
66     * Return all KolabInetOrgPersons with the given uid or mail address.
67     *
68     * @param string $id The uid or mail address to search for.
69     *
70     * @return array The GUID(s).
71     *
72     * @throws Horde_Kolab_Server_Exception
73     */
74    public function searchGuidForUidOrMail($id)
75    {
76        $criteria = new Horde_Kolab_Server_Query_Element_Or(
77            array(
78                new Horde_Kolab_Server_Query_Element_Equals(
79                    'Uid', $id
80                ),
81                new Horde_Kolab_Server_Query_Element_Equals(
82                    'Mail', $id
83                )
84            )
85        );
86        return $this->_search->searchRestrictKolab($criteria);
87    }
88}