1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/app/models/item/Item.php

94 lines
2.5 KiB
PHP
Raw Normal View History

<?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
public function __construct() {
$this->_struct = '
{
2015-08-19 11:28:28 +02:00
"server" :
{"type":"string", "size":64, "mandatory":true, "key":true },
2015-08-19 11:28:28 +02:00
"jid" :
{"type":"string", "size":128, "mandatory":true, "key":true },
2015-08-19 11:28:28 +02:00
"node" :
{"type":"string", "size":128, "mandatory":true, "key":true },
2015-08-19 11:28:28 +02:00
"creator" :
{"type":"string", "size":128 },
2015-08-19 11:28:28 +02:00
"name" :
{"type":"string", "size":128 },
2015-08-19 11:28:28 +02:00
"created" :
{"type":"date"},
2015-08-19 11:28:28 +02:00
"description" :
{"type":"text" },
2015-08-19 11:28:28 +02:00
"updated" :
{"type":"date"}
}';
2015-08-19 11:28:28 +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
$this->updated = date('Y-m-d H:i:s');
}
2015-08-19 11:28:28 +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;
}