1<?php
2/**
3 * Return the mail address of the KolabInetOrgPersons with the given uid or mail
4 * address.
5 *
6 * PHP version 5
7 *
8 * @category Kolab
9 * @package  Kolab_Server
10 * @author   Gunnar Wrobel <wrobel@pardus.de>
11 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
12 * @link     http://pear.horde.org/index.php?package=Kolab_Server
13 */
14
15/**
16 * Return the mail address of the KolabInetOrgPersons with the given uid or mail
17 * address.
18 *
19 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
20 *
21 * See the enclosed file COPYING for license information (LGPL). If you
22 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23 *
24 * @category Kolab
25 * @package  Kolab_Server
26 * @author   Gunnar Wrobel <wrobel@pardus.de>
27 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
28 * @link     http://pear.horde.org/index.php?package=Kolab_Server
29 */
30class Horde_Kolab_Server_Search_Operation_Mailforuidormail
31extends Horde_Kolab_Server_Search_Operation_Base
32{
33
34    /**
35     * The base attribute search.
36     *
37     * @var Horde_Kolab_Server_Search_Operation
38     */
39    private $_search;
40
41    /**
42     * Constructor
43     *
44     * @param Horde_Kolab_Server_Composite $composite A link to the composite
45     *                                                server handler.
46     */
47    public function __construct(Horde_Kolab_Server_Composite $composite)
48    {
49        $this->_composite = $composite;
50        $this->_search = new Horde_Kolab_Server_Search_Operation_Constraint_Strict(
51            new Horde_Kolab_Server_Search_Operation_Attributes(
52                $this->getComposite()
53            )
54        );
55    }
56
57    /**
58     * Return the mail address of the KolabInetOrgPersons with the given uid or
59     * mail address.
60     *
61     * @param string $uid  The uid to search for.
62     * @param string $mail The mail address to search for.
63     *
64     * @return array The GUID(s).
65     *
66     * @throws Horde_Kolab_Server_Exception
67     */
68    public function searchMailForUidOrMail($uid, $mail)
69    {
70        $criteria = new Horde_Kolab_Server_Query_Element_And(
71            new Horde_Kolab_Server_Query_Element_Equals(
72                'Objectclass',
73                Horde_Kolab_Server_Object_Kolabinetorgperson::OBJECTCLASS_KOLABINETORGPERSON
74            ),
75            new Horde_Kolab_Server_Query_Element_Or(
76                new Horde_Kolab_Server_Query_Element_Equals(
77                    'Uid', $uid
78                ),
79                new Horde_Kolab_Server_Query_Element_Equals(
80                    'Mail', $mail
81                )
82            )
83        );
84        $data = $this->_search->searchAttributes($criteria, array('Mail'));
85
86        $internal = $this->getComposite()->structure->getAttributeInternal(
87            'Mail'
88        );
89        if (!empty($data)) {
90            return $data[$internal][0];
91        } else {
92            return false;
93        }
94    }
95}