2015-08-03 11:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace modl;
|
|
|
|
|
|
|
|
class Item extends Model {
|
|
|
|
public $server;
|
|
|
|
public $jid;
|
|
|
|
public $name;
|
|
|
|
public $node;
|
|
|
|
public $creator;
|
|
|
|
public $created;
|
|
|
|
public $updated;
|
|
|
|
public $description;
|
|
|
|
public $subscription;
|
|
|
|
public $num;
|
|
|
|
public $sub;
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
public function __construct() {
|
|
|
|
$this->_struct = '
|
|
|
|
{
|
2015-08-19 11:28:28 +02:00
|
|
|
"server" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":64, "mandatory":true, "key":true },
|
2015-08-19 11:28:28 +02:00
|
|
|
"jid" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128, "mandatory":true, "key":true },
|
2015-08-19 11:28:28 +02:00
|
|
|
"node" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128, "mandatory":true, "key":true },
|
2015-08-19 11:28:28 +02:00
|
|
|
"creator" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128 },
|
2015-08-19 11:28:28 +02:00
|
|
|
"name" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"string", "size":128 },
|
2015-08-19 11:28:28 +02:00
|
|
|
"created" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"date"},
|
2015-08-19 11:28:28 +02:00
|
|
|
"description" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"text" },
|
2015-08-19 11:28:28 +02:00
|
|
|
"updated" :
|
2015-08-03 11:35:01 +02:00
|
|
|
{"type":"date"}
|
|
|
|
}';
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($item, $from) {
|
|
|
|
$this->server = $from;
|
|
|
|
$this->node = (string)$item->attributes()->node;
|
|
|
|
$this->jid = (string)$item->attributes()->jid;
|
|
|
|
if($this->jid == null)
|
|
|
|
$this->jid = $this->node;
|
|
|
|
$this->name = (string)$item->attributes()->name;
|
|
|
|
$this->updated = date('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMetadata($metadata, $from, $node) {
|
|
|
|
$this->server = $from;
|
|
|
|
$this->jid = $from;
|
|
|
|
$this->node = $node;
|
|
|
|
|
|
|
|
foreach($metadata->children() as $i) {
|
|
|
|
$key = (string)$i->attributes()->var;
|
|
|
|
|
|
|
|
switch ($key) {
|
|
|
|
case 'pubsub#title':
|
|
|
|
$this->name = (string)$i->value;
|
|
|
|
break;
|
|
|
|
case 'pubsub#creator':
|
|
|
|
$this->creator = (string)$i->value;
|
|
|
|
break;
|
|
|
|
case 'pubsub#creation_date':
|
|
|
|
$this->created = (string)$i->value;
|
|
|
|
break;
|
|
|
|
case 'pubsub#description':
|
|
|
|
$this->description = (string)$i->value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
$this->updated = date('Y-m-d H:i:s');
|
|
|
|
}
|
2015-08-19 11:28:28 +02:00
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
public function getName() {
|
|
|
|
if($this->name != null)
|
|
|
|
return $this->name;
|
|
|
|
elseif($this->node != null)
|
|
|
|
return $this->node;
|
|
|
|
else
|
|
|
|
return $this->jid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Server extends Model {
|
|
|
|
public $server;
|
|
|
|
public $number;
|
2015-08-19 11:28:28 +02:00
|
|
|
public $name;
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|