1<?php 2/** 3 * The Kolab_Folder class represents an single folder in the Kolab 4 * backend. 5 * 6 * PHP version 5 7 * 8 * @category Kolab 9 * @package Kolab_Storage 10 * @author Gunnar Wrobel <wrobel@pardus.de> 11 * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 12 */ 13 14/** 15 * The Kolab_Folder class represents an single folder in the Kolab 16 * backend. 17 * 18 * Copyright 2004-2017 Horde LLC (http://www.horde.org/) 19 * 20 * See the enclosed file COPYING for license information (LGPL). If you 21 * did not receive this file, see http://www.horde.org/licenses/lgpl21. 22 * 23 * @author Stuart Binge <omicron@mighty.co.za> 24 * @author Gunnar Wrobel <wrobel@pardus.de> 25 * @author Thomas Jarosch <thomas.jarosch@intra2net.com> 26 * @package Kolab_Storage 27 */ 28class Horde_Kolab_Storage_Folder_Base 29implements Horde_Kolab_Storage_Folder 30{ 31 /** 32 * The handler for the list of folders. 33 * 34 * @var Horde_Kolab_Storage_List 35 */ 36 private $_list; 37 38 /** 39 * The folder path. 40 * 41 * @var string 42 */ 43 private $_path; 44 45 /** 46 * Additional folder information. 47 * 48 * @var array 49 */ 50 private $_data; 51 52 /** 53 * Constructor. 54 * 55 * @param Horde_Kolab_Storage_List_Query_List $list The query handler for 56 * the list of folders. 57 * @param string $path Path of the folder. 58 */ 59 public function __construct(Horde_Kolab_Storage_List_Query_List $list, $path) 60 { 61 $this->_list = $list; 62 $this->_path = $path; 63 } 64 65 /** 66 * Fetch the data array. 67 * 68 * @return NULL 69 */ 70 private function _init() 71 { 72 if ($this->_data === null) { 73 $this->_data = $this->_list->folderData($this->_path); 74 } 75 } 76 77 /** 78 * Fetch a data value. 79 * 80 * @param string $key The name of the data value to fetch. 81 * 82 * @return mixed The data value 83 */ 84 public function get($key) 85 { 86 $this->_init(); 87 if (isset($this->_data[$key])) { 88 return $this->_data[$key]; 89 } 90 throw new Horde_Kolab_Storage_Exception( 91 sprintf('No "%s" information available!', $key) 92 ); 93 } 94 95 /** 96 * Fetch a data value and accept a missing value (represented by the return value NULL). 97 * 98 * @param string $key The name of the data value to fetch. 99 * 100 * @return mixed The data value 101 */ 102 public function getWithNull($key) 103 { 104 $this->_init(); 105 if (isset($this->_data[$key])) { 106 return $this->_data[$key]; 107 } 108 } 109 110 /** 111 * Return the storage path of the folder. 112 * 113 * @return string The storage path of the folder. 114 */ 115 public function getPath() 116 { 117 return $this->_path; 118 } 119 120 /** 121 * Return the namespace type of the folder. 122 * 123 * @return string The namespace type of the folder. 124 */ 125 public function getNamespace() 126 { 127 return $this->get('namespace'); 128 } 129 130 /** 131 * Return the namespace prefix of the folder. 132 * 133 * @return string The namespace prefix of the folder. 134 */ 135 public function getPrefix() 136 { 137 return $this->get('prefix'); 138 } 139 140 /** 141 * Returns a readable title for this folder. 142 * 143 * @return string The folder title. 144 */ 145 public function getTitle() 146 { 147 return $this->get('name'); 148 } 149 150 /** 151 * Returns the owner of the folder. 152 * 153 * @return string The owner of this folder. 154 */ 155 public function getOwner() 156 { 157 return $this->getWithNull('owner'); 158 } 159 160 /** 161 * Returns the folder path without namespace components. 162 * 163 * @return string The subpath of this folder. 164 */ 165 public function getSubpath() 166 { 167 return $this->get('subpath'); 168 } 169 170 /** 171 * Returns the folder parent. 172 * 173 * @return string The parent of this folder. 174 */ 175 public function getParent() 176 { 177 return $this->get('parent'); 178 } 179 180 /** 181 * Is this a default folder? 182 * 183 * @return boolean Boolean that indicates the default status. 184 */ 185 public function isDefault() 186 { 187 return $this->get('default'); 188 } 189 190 /** 191 * The type of this folder. 192 * 193 * @return string The folder type. 194 */ 195 public function getType() 196 { 197 return $this->get('type'); 198 } 199} 200