/Aurora/Addon/WebAPI/AbuseReports.php

https://bitbucket.org/VirtualReality/libaurora.php · PHP · 342 lines · 219 code · 30 blank · 93 comment · 26 complexity · 8d01f60775d1a36fd838ff2a0338b423 MD5 · raw file

  1. <?php
  2. //! @file Aurora/Addon/WebAPI/AbuseReports.php
  3. //! @brief Abuse Report-related WebAPI code
  4. //! @author SignpostMarv
  5. namespace Aurora\Addon\WebAPI{
  6. use libAurora\abstractIterator;
  7. //! AbuseReport class. Included in result returned by Aurora::Addon::WebAPI::GetAbuseReports()
  8. class AbuseReport{
  9. //! protected constructor, we hide it behind a registry method.
  10. /**
  11. * @param integer $number looks like the primary key according to IAbuseReports.GetAbuseReport
  12. * @param string $details abuse report details
  13. * @param string $location abuse report location
  14. * @param string $userName name of the account being reported
  15. * @param string $summary summary of abuse report
  16. * @param boolean $active whether or not the abuse report is open.
  17. * @param string $assignedTo name of admin the abuse report is assigned to.
  18. * @param string $category category of abuse
  19. * @param boolean $checked not entirely sure what this does.
  20. * @param string $notes notes on the abuse report.
  21. * @param string $objectName Name of object being reported (if applicable)
  22. * @param string $objectPosition Position of object being reported (if applicable)
  23. * @param string $objectUUID UUID of object being reported (if applicable)
  24. * @param string $regionName region the report originated from
  25. * @param string $reporterName account name of the user who filed the abuse report
  26. * @param string $screenshot asset UUID of screenshot attached to the abuse report
  27. */
  28. protected function __construct($number, $details, $location, $userName, $summary, $active, $assignedTo, $category, $checked, $notes, $objectName, $objectPosition, $objectUUID, $regionName, $reporterName, $screenshot){
  29. if(is_integer($number) === false){
  30. throw new InvalidArgumentException('AR Number must be an integer.');
  31. }else if(is_string($details) === false){
  32. throw new InvalidArgumentException('AR Details must be a string.');
  33. }else if(is_string($location) === false){
  34. throw new InvalidArgumentException('AR Location must be a string.');
  35. }else if(is_string($userName) === false){
  36. throw new InvalidArgumentException('AR accused name must be a string.');
  37. }else if(is_string($summary) === false){
  38. throw new InvalidArgumentException('AR summary must be a string.');
  39. }else if(is_bool($active) === false){
  40. throw new InvalidArgumentException('AR activity flag must be a boolean.');
  41. }else if(is_string($assignedTo) === false){
  42. throw new InvalidArgumentException('AR admin assignee name must be a string.');
  43. }else if(is_string($category) === false){
  44. throw new InvalidArgumentException('AR category must be a string.');
  45. }else if(is_bool($checked) === false){
  46. throw new InvalidArgumentException('AR checked flag must be a boolean.');
  47. }else if(is_string($notes) === false){
  48. throw new InvalidArgumentException('AR notes must be a string.');
  49. }else if(is_string($objectName) === false){
  50. throw new InvalidArgumentException('AR object name must be a string.');
  51. }else if(is_string($objectPosition) === false){
  52. throw new InvalidArgumentException('AR object position must be a string.');
  53. }else if(is_string($objectUUID) === false){
  54. throw new InvalidArgumentException('AR object UUID must be a string.');
  55. }else if(preg_match(\Aurora\Addon\WebAPI::regex_UUID, $objectUUID) !== 1){
  56. throw new InvalidArgumentException('AR object UUID must be a valid UUID.');
  57. }else if(is_string($regionName) === false){
  58. throw new InvalidArgumentException('AR region of origin must be a string.');
  59. }else if(is_string($reporterName) === false){
  60. throw new InvalidArgumentException('AR reporter name must be as string.');
  61. }else if(is_string($screenshot) === false){
  62. throw new InvalidArgumentException('AR screenshot UUID must be a string.');
  63. }else if(preg_match(\Aurora\Addon\WebAPI::regex_UUID, $screenshot) === false){
  64. throw new InvalidArgumentException('AR screenshot UUID must be a valid UUID.');
  65. }
  66. $this->Number = $number;
  67. $this->Details = trim($details);
  68. $this->Location = trim($location);
  69. $this->UserName = trim($userName);
  70. $this->Summary = trim($summary);
  71. $this->Active = $active;
  72. $this->AssignedTo = trim($assignedTo);
  73. $this->Category = trim($category);
  74. $this->Checked = $checked;
  75. $this->Notes = trim($notes);
  76. $this->ObjectName = trim($objectName);
  77. $this->ObjectPosition = trim($objectPosition);
  78. $this->ObjectUUID = $objectUUID;
  79. $this->RegionName = trim($regionName);
  80. $this->ReporterName = trim($reporterName);
  81. $this->Screenshot = $screenshot;
  82. }
  83. //! registry method
  84. /**
  85. * @param integer $number looks like the primary key according to IAbuseReports.GetAbuseReport
  86. * @param string $details abuse report details
  87. * @param string $location abuse report location
  88. * @param string $userName name of the account being reported
  89. * @param string $summary summary of abuse report
  90. * @param boolean $active whether or not the abuse report is open.
  91. * @param string $assignedTo name of admin the abuse report is assigned to.
  92. * @param string $category category of abuse
  93. * @param boolean $checked not entirely sure what this does.
  94. * @param string $notes notes on the abuse report.
  95. * @param string $objectName Name of object being reported (if applicable)
  96. * @param string $objectPosition Position of object being reported (if applicable)
  97. * @param string $objectUUID UUID of object being reported (if applicable)
  98. * @param string $regionName region the report originated from
  99. * @param string $reporterName account name of the user who filed the abuse report
  100. * @param string $screenshot asset UUID of screenshot attached to the abuse report
  101. * @return object an instance of Aurora::Addon::WebAPI::AbuseReport
  102. */
  103. public static function r($number, $details=null, $location=null, $userName=null, $summary=null, $active=null, $assignedTo=null, $category=null, $checked=null, $notes=null, $objectName=null, $objectPosition=null, $objectUUID=null, $regionName=null, $reporterName=null, $screenshot=null){
  104. if(
  105. is_object($number) &&
  106. property_exists($number,'Number') &&
  107. property_exists($number,'AbuseDetails') &&
  108. property_exists($number,'AbuseLocation') &&
  109. property_exists($number,'AbuserName') &&
  110. property_exists($number,'AbuseSummary') &&
  111. property_exists($number,'Active') &&
  112. property_exists($number,'AssignedTo') &&
  113. property_exists($number,'Category') &&
  114. property_exists($number,'Checked') &&
  115. property_exists($number,'Notes') &&
  116. property_exists($number,'ObjectName') &&
  117. property_exists($number,'ObjectPosition') &&
  118. property_exists($number,'ObjectUUID') &&
  119. property_exists($number,'RegionName') &&
  120. property_exists($number,'ReporterName') &&
  121. property_exists($number,'ScreenshotID')
  122. ){
  123. $details = $number->AbuseDetails;
  124. $location = $number->AbuseLocation;
  125. $userName = $number->AbuserName;
  126. $summary = $number->AbuseSummary;
  127. $active = $number->Active;
  128. $assignedTo = $number->AssignedTo;
  129. $category = $number->Category;
  130. $checked = $number->Checked;
  131. $notes = $number->Notes;
  132. $objectName = $number->ObjectName;
  133. $objectPosition = $number->ObjectPosition;
  134. $objectUUID = $number->ObjectUUID;
  135. $regionName = $number->RegionName;
  136. $reporterName = $number->ReporterName;
  137. $screenshot = $number->ScreenshotID;
  138. $number = $number->Number;
  139. }
  140. if(is_integer($number) === false){
  141. throw new InvalidArgumentException('AR number must be an integer.');
  142. }
  143. static $registry = array();
  144. $create = (isset($registry[$number]) === false);
  145. if($create === true && isset($details, $location, $userName, $summary, $active, $assignedTo, $category, $checked, $notes, $objectName, $objectPosition, $objectUUID, $regionName, $reporterName, $screenshot) === false){
  146. throw new InvalidArgumentException('Cannot return cached AbuseReport object as it hasn\'t been created.');
  147. }else if($create === false){
  148. $details = trim($details);
  149. $location = trim($location);
  150. $userName = trim($userName);
  151. $summary = trim($summary);
  152. $assignedTo = trim($assignedTo);
  153. $category = trim($category);
  154. $notes = trim($notes);
  155. $objectName = trim($objectName);
  156. $objectPosition = trim($objectPosition);
  157. $regionName = trim($regionName);
  158. $reporterName = trim($reporterName);
  159. $AR = $registry[$number];
  160. $create = (
  161. $AR->Details() !== $details ||
  162. $AR->Location() !== $location ||
  163. $AR->UserName() !== $userName ||
  164. $AR->Summary() !== $summary ||
  165. $AR->Active() !== $active ||
  166. $AR->AssignedTo() !== $assignedTo ||
  167. $AR->Category() !== $category ||
  168. $AR->Checked() !== $checked ||
  169. $AR->Notes() !== $notes ||
  170. $AR->ObjectName() !== $objectName ||
  171. $AR->ObjectPosition() !== $objectPosition ||
  172. $AR->ObjectUUID() !== $objectUUID ||
  173. $AR->RegionName() !== $regionName ||
  174. $AR->ReporterName() !== $reporterName ||
  175. $AR->Screenshot() !== $screenshot
  176. );
  177. }
  178. if($create === true){
  179. $registry[$number] = new static($number, $details, $location, $userName, $summary, $active, $assignedTo, $category, $checked, $notes, $objectName, $objectPosition, $objectUUID, $regionName, $reporterName, $screenshot);
  180. }
  181. return $registry[$number];
  182. }
  183. //! integer looks like the primary key according to IAbuseReports.GetAbuseReport
  184. //! @see Aurora::Addon::WebAPI::AbuseReport::Number()
  185. protected $Number;
  186. //! @see Aurora::Addon::WebAPI::AbuseReport::$Number
  187. public function Number(){
  188. return $this->Number;
  189. }
  190. //! string abuse report details
  191. //! @see Aurora::Addon::WebAPI::AbuseReport::Details()
  192. protected $Details;
  193. //! @see Aurora::Addon::WebAPI::AbuseReport::$Details
  194. public function Details(){
  195. return $this->Details;
  196. }
  197. //! string abuse report location
  198. //! @see Aurora::Addon::WebAPI::AbuseReport::Location()
  199. protected $Location;
  200. //! @see Aurora::Addon::WebAPI::AbuseReport::$Location
  201. public function Location(){
  202. return $this->Location;
  203. }
  204. //! string name of the account being reported
  205. //! @see Aurora::Addon::WebAPI::AbuseReport::UserName()
  206. protected $UserName;
  207. //! @see Aurora::Addon::WebAPI::AbuseReport::$UserName
  208. public function UserName(){
  209. return $this->UserName;
  210. }
  211. //! string summary of abuse report
  212. //! @see Aurora::Addon::WebAPI::AbuseReport::Summary()
  213. protected $Summary;
  214. //! @see Aurora::Addon::WebAPI::AbuseReport::$Summary
  215. public function Summary(){
  216. return $this->Summary;
  217. }
  218. //! boolean whether or not the abuse report is open.
  219. //! @see Aurora::Addon::WebAPI::AbuseReport::Active()
  220. protected $Active;
  221. //! @see Aurora::Addon::WebAPI::AbuseReport::$Active
  222. public function Active(){
  223. return $this->Active;
  224. }
  225. //! string name of admin the abuse report is assigned to.
  226. //! @see Aurora::Addon::WebAPI::AbuseReport::AssignedTo()
  227. protected $AssignedTo;
  228. //! @see Aurora::Addon::WebAPI::AbuseReport::$AssignedTo
  229. public function AssignedTo(){
  230. return $this->AssignedTo;
  231. }
  232. //! string category of abuse
  233. //! @see Aurora::Addon::WebAPI::AbuseReport::Category()
  234. protected $Category;
  235. //! @see Aurora::Addon::WebAPI::AbuseReport::$Category
  236. public function Category(){
  237. return $this->Category;
  238. }
  239. //! boolean not entirely sure what this does.
  240. //! @see Aurora::Addon::WebAPI::AbuseReport::Checked()
  241. protected $Checked;
  242. //! @see Aurora::Addon::WebAPI::AbuseReport::$Checked
  243. public function Checked(){
  244. return $this->Checked;
  245. }
  246. //! string notes on the abuse report.
  247. //! @see Aurora::Addon::WebAPI::AbuseReport::Notes()
  248. protected $Notes;
  249. //! @see Aurora::Addon::WebAPI::AbuseReport::$Notes
  250. public function Notes(){
  251. return $this->Notes;
  252. }
  253. //! string Name of object being reported (if applicable)
  254. //! @see Aurora::Addon::WebAPI::AbuseReport::ObjectName()
  255. protected $ObjectName;
  256. //! @see Aurora::Addon::WebAPI::AbuseReport::$ObjectName
  257. public function ObjectName(){
  258. return $this->ObjectName;
  259. }
  260. //! string Position of object being reported (if applicable)
  261. //! @see Aurora::Addon::WebAPI::AbuseReport::ObjectPosition()
  262. protected $ObjectPosition;
  263. //! @see Aurora::Addon::WebAPI::AbuseReport::$ObjectPosition
  264. public function ObjectPosition(){
  265. return $this->ObjectPosition;
  266. }
  267. //! string UUID of object being reported (if applicable)
  268. //! @see Aurora::Addon::WebAPI::AbuseReport::ObjectUUID()
  269. protected $ObjectUUID;
  270. //! @see Aurora::Addon::WebAPI::AbuseReport::$ObjectUUID
  271. public function ObjectUUID(){
  272. return $this->ObjectUUID;
  273. }
  274. //! string region the report originated from
  275. //! @see Aurora::Addon::WebAPI::AbuseReport::RegionName()
  276. protected $RegionName;
  277. //! @see Aurora::Addon::WebAPI::AbuseReport::$RegionName
  278. public function RegionName(){
  279. return $this->RegionName;
  280. }
  281. //! string account name of the user who filed the abuse report
  282. //! @see Aurora::Addon::WebAPI::AbuseReport::ReporterName()
  283. protected $ReporterName;
  284. //! @see Aurora::Addon::WebAPI::AbuseReport::$ReporterName
  285. public function ReporterName(){
  286. return $this->ReporterName;
  287. }
  288. //! string asset UUID of screenshot attached to the abuse report
  289. //! @see Aurora::Addon::WebAPI::AbuseReport::Screenshot()
  290. protected $Screenshot;
  291. //! @see Aurora::Addon::WebAPI::AbuseReport::$Screenshot
  292. public function Screenshot(){
  293. return $this->Screenshot;
  294. }
  295. }
  296. //! AbuseReports iterator. Returned by Aurora::Addon::WebAPI::GetAbuseReports()
  297. class AbuseReports extends abstractIterator{
  298. //! public constructor
  299. public function __construct(array $ARs=null){
  300. if(isset($ARs) === true){
  301. foreach($ARs as $AR){
  302. if(($AR instanceof AbuseReport) === false){
  303. throw new InvalidArgumentException('Only instances of Aurora::Addon::WebAPI::AbuseReport should be included in the array passed to Aurora::Addon::WebAPI::AbuseReports::__construct()');
  304. }
  305. }
  306. reset($ARs);
  307. $this->data = $ARs;
  308. }
  309. }
  310. }
  311. }
  312. ?>