You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

  1. <?php
  2. namespace modl;
  3. class Item extends Model {
  4. public $server;
  5. public $jid;
  6. public $name;
  7. public $node;
  8. public $creator;
  9. public $created;
  10. public $updated;
  11. public $description;
  12. public $subscription;
  13. public $num;
  14. public function __construct() {
  15. $this->_struct = '
  16. {
  17. "server" :
  18. {"type":"string", "size":128, "mandatory":true, "key":true },
  19. "jid" :
  20. {"type":"string", "size":128, "mandatory":true, "key":true },
  21. "node" :
  22. {"type":"string", "size":128, "mandatory":true, "key":true },
  23. "creator" :
  24. {"type":"string", "size":128 },
  25. "name" :
  26. {"type":"string", "size":128 },
  27. "created" :
  28. {"type":"date"},
  29. "description" :
  30. {"type":"text" },
  31. "updated" :
  32. {"type":"date"}
  33. }';
  34. parent::__construct();
  35. }
  36. public function set($item, $from) {
  37. $this->server = $from;
  38. $this->node = (string)$item->attributes()->node;
  39. $this->jid = (string)$item->attributes()->jid;
  40. if($this->jid == null)
  41. $this->jid = $this->node;
  42. $this->name = (string)$item->attributes()->name;
  43. $this->updated = date('Y-m-d H:i:s');
  44. }
  45. public function setMetadata($metadata, $from, $node) {
  46. $this->server = $from;
  47. $this->jid = $from;
  48. $this->node = $node;
  49. foreach($metadata->children() as $i) {
  50. $key = (string)$i->attributes()->var;
  51. switch ($key) {
  52. case 'pubsub#title':
  53. $this->name = (string)$i->value;
  54. break;
  55. case 'pubsub#creator':
  56. $this->creator = (string)$i->value;
  57. break;
  58. case 'pubsub#creation_date':
  59. $this->created = (string)$i->value;
  60. break;
  61. case 'pubsub#description':
  62. $this->description = (string)$i->value;
  63. break;
  64. }
  65. }
  66. $this->updated = date('Y-m-d H:i:s');
  67. }
  68. public function getName() {
  69. if($this->name != null)
  70. return $this->name;
  71. elseif($this->node != null)
  72. return $this->node;
  73. else
  74. return $this->jid;
  75. }
  76. }
  77. class Server extends Model {
  78. public $server;
  79. public $number;
  80. }