1 <?php
2 /*
3 Copyright (c) 2012, University of Cambridge Computing Service
4
5 This file is part of the Lookup/Ibis client library.
6
7 This library is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 require_once "IbisDto.php";
22 require_once "IbisPerson.php";
23
24 /**
25 * Class representing an institution contact row, for use by the web
26 * services API.
27 *
28 * @author Dean Rasheed (dev-group@ucs.cam.ac.uk)
29 */
30 class IbisContactRow extends IbisDto
31 {
32 /* Properties marked as @XmlAttribte in the JAXB class */
33 protected static $xmlAttrs = array("bold", "italic");
34
35 /* Properties marked as @XmlElement in the JAXB class */
36 protected static $xmlElems = array("description");
37
38 /* Properties marked as @XmlElementWrapper in the JAXB class */
39 protected static $xmlArrays = array("addresses", "emails", "people",
40 "phoneNumbers", "webPages");
41
42 /** @var string The contact row's text. */
43 public $description;
44
45 /**
46 * @var boolean Flag indicating if the contact row's text is normally
47 * displayed in bold.
48 */
49 public $bold;
50
51 /**
52 * @var boolean Flag indicating if the contact row's text is normally
53 * displayed in italics.
54 */
55 public $italic;
56
57 /**
58 * @var string[] A list of the contact row's addresses. This will always
59 * be non-null, but may be an empty list.
60 */
61 public $addresses;
62
63 /**
64 * @var string[] A list of the contact row's email addresses. This will
65 * always be non-null, but may be an empty list.
66 */
67 public $emails;
68
69 /**
70 * @var IbisPerson[] A list of the people referred to by the contact row.
71 * This will always be non-null, but may be an empty list.
72 */
73 public $people;
74
75 /**
76 * @var IbisContactPhoneNumber[] A list of the contact row's phone
77 * numbers. This will always be non-null, but may be an empty list.
78 */
79 public $phoneNumbers;
80
81 /**
82 * @var IbisContactWebPage[] A list of the contact row's web pages. This
83 * will always be non-null, but may be an empty list.
84 */
85 public $webPages;
86
87 /* Flag to prevent infinite recursion due to circular references. */
88 private $unflattened;
89
90 /**
91 * @ignore
92 * Create an IbisContactRow from the attributes of an XML node.
93 *
94 * @param array $attrs The attributes on the XML node.
95 */
96 public function __construct($attrs=array())
97 {
98 parent::__construct($attrs);
99 if (isset($this->bold))
100 $this->bold = strcasecmp($this->bold, "true") == 0;
101 if (isset($this->italic))
102 $this->italic = strcasecmp($this->italic, "true") == 0;
103 $this->unflattened = false;
104 }
105
106 /**
107 * @ignore
108 * Unflatten a single IbisContactRow.
109 *
110 * @param IbisResultEntityMap $em The mapping from IDs to entities.
111 */
112 public function unflatten($em)
113 {
114 if (!$this->unflattened)
115 {
116 $this->unflattened = true;
117 IbisPerson::unflattenPeople($em, $this->people);
118 }
119 return $this;
120 }
121
122 /**
123 * @ignore
124 * Unflatten a list of IbisContactRow objects (done in place).
125 *
126 * @param IbisResultEntityMap $em The mapping from IDs to entities.
127 * @param IbisContactRow[] $contactRows The contact rows to unflatten.
128 */
129 public static function unflattencontactRows($em, &$contactRows)
130 {
131 if (isset($contactRows))
132 foreach ($contactRows as $idx => $contactRow)
133 $contactRows[$idx] = $contactRow->unflatten($em);
134 }
135 }
136