1<?php 2/** 3 * Circles - Bring cloud-users closer together. 4 * 5 * This file is licensed under the Affero General Public License version 3 or 6 * later. See the COPYING file. 7 * 8 * @author Maxence Lange <maxence@artificial-owl.com> 9 * @copyright 2017 10 * @license GNU AGPL version 3 or any later version 11 * 12 * This program is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Affero General Public License as 14 * published by the Free Software Foundation, either version 3 of the 15 * License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Affero General Public License for more details. 21 * 22 * You should have received a copy of the GNU Affero General Public License 23 * along with this program. If not, see <http://www.gnu.org/licenses/>. 24 * 25 */ 26 27namespace OCA\Circles\Model; 28 29class SearchResult implements \JsonSerializable { 30 31 /** @var string */ 32 private $ident; 33 34 /** @var int */ 35 private $type; 36 37 /** @var string */ 38 private $instance = ''; 39 40 /** @var array */ 41 private $data = []; 42 43 44 /** 45 * SearchResult constructor. 46 * 47 * @param string $ident 48 * @param int $type 49 * @param string $instance 50 * @param array $data 51 */ 52 public function __construct($ident = '', $type = 0, $instance = '', $data = []) { 53 $this->setIdent($ident); 54 $this->setType($type); 55 $this->setInstance($instance); 56 $this->setData($data); 57 } 58 59 60 /** 61 * @param string $ident 62 */ 63 public function setIdent($ident) { 64 $this->ident = $ident; 65 } 66 67 /** 68 * @return string 69 */ 70 public function getIdent() { 71 return $this->ident; 72 } 73 74 75 /** 76 * @param string $instance 77 */ 78 public function setInstance($instance) { 79 $this->instance = $instance; 80 } 81 82 /** 83 * @return string 84 */ 85 public function getInstance() { 86 return $this->instance; 87 } 88 89 90 /** 91 * @param int $type 92 */ 93 public function setType($type) { 94 $this->type = $type; 95 } 96 97 /** 98 * @return int 99 */ 100 public function getType() { 101 return $this->type; 102 } 103 104 105 /** 106 * @param array $data 107 */ 108 public function setData($data) { 109 $this->data = $data; 110 } 111 112 /** 113 * @return array 114 */ 115 public function getData() { 116 if (!key_exists('display', $this->data)) { 117 return ['display' => $this->getIdent()]; 118 } 119 120 return $this->data; 121 } 122 123 124 /** 125 * Specify data which should be serialized to JSON 126 * 127 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php 128 * @return mixed data which can be serialized by <b>json_encode</b>, 129 * which is a value of any type other than a resource. 130 * @since 5.4.0 131 */ 132 public function jsonSerialize() { 133 return [ 134 'ident' => $this->getIdent(), 135 'instance' => $this->getInstance(), 136 'type' => $this->getType(), 137 'data' => $this->getData() 138 ]; 139 } 140} 141