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/ItemDAO.php

279 lines
7.3 KiB
PHP
Raw Normal View History

<?php
namespace modl;
2015-08-19 11:28:28 +02:00
class ItemDAO extends SQL {
function set(Item $item, $insert_only = false) {
if(!$insert_only) {
$this->_sql = '
update item
set name = :name,
creator = :creator,
created = :created,
updated = :updated,
description = :description
where server = :server
and jid = :jid
and node = :node';
2015-08-19 11:28:28 +02:00
$this->prepare(
2015-08-19 11:28:28 +02:00
'Item',
array(
'name' => $item->name,
'created' => $item->created,
'updated' => $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node,
'creator' => $item->creator,
'description' => $item->description
)
);
2015-08-19 11:28:28 +02:00
$this->run('Item');
}
2015-08-19 11:28:28 +02:00
if(!$this->_effective || $insert_only) {
$this->_sql = '
insert into item
(server,
creator,
node,
jid,
name,
created,
updated,
description
)
values(
:server,
:creator,
:node,
:jid,
:name,
:created,
:updated,
:description
)';
2015-08-19 11:28:28 +02:00
$this->prepare(
2015-08-19 11:28:28 +02:00
'Item',
array(
'name' => $item->name,
'creator' => $item->creator,
'created' => $item->created,
'updated' => $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node,
'description' => $item->description
)
);
2015-08-19 11:28:28 +02:00
$this->run('Item');
}
}
2015-08-19 11:28:28 +02:00
function getServers() {
$this->_sql = '
2015-08-19 11:28:28 +02:00
select server, count(node) as number
from item
where node not like :node
group by server
order by number desc';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'node' => 'urn:xmpp:microblog:0:comments%'
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Server');
}
2015-08-19 11:28:28 +02:00
function getConferenceServers() {
$this->_sql = '
2015-08-19 11:28:28 +02:00
select server, count(node) as number
from item
where node not like :node
and node = :name
group by server
order by number desc';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'node' => 'urn:xmpp:microblog:0:comments%',
// It's a hack to affect an empty string
'name' => ''
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Server');
}
2015-08-19 11:28:28 +02:00
function getGroupServers() {
$this->_sql = '
2015-08-19 11:28:28 +02:00
select server, count(item.node) as number, caps.name
from item
2015-08-19 11:28:28 +02:00
left outer join caps on caps.node = item.server
where item.node not like :node
and item.node != :name
group by server, caps.name
order by number desc';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'node' => 'urn:xmpp:microblog:0:comments%',
// Little hack here too
'name' => ''
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Server');
}
2015-08-19 11:28:28 +02:00
function getItems($server) {
$this->_sql = '
select * from item
left outer join (
select node, count(node) as num from postn
where origin = :server
group by node) as p
on p.node = item.node
left outer join (
select node, count(node) as sub from subscription
where server = :server
group by node) as sub
on sub.node = item.node
2015-08-19 11:28:28 +02:00
left outer join (select server, node, subscription from subscription where jid = :node)
as s on s.server = item.server
and s.node = item.node
where item.server = :server
and item.node != \'\'
order by name, item.node
';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
// Dirty hack, using node param to inject the session key
'node' => $this->_user,
'server' => $server
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Item');
}
function getGateways($server) {
$this->_sql = '
select * from item
left outer join caps on caps.node = item.jid
where server = :server
and category = \'gateway\'';
$this->prepare(
'Item',
array(
'server' => $server
)
);
return $this->run('Item');
}
function getUpload($server) {
$this->_sql = '
select * from item
left outer join caps on caps.node = item.jid
where server = :server
and category = \'store\'
and type = \'file\'';
$this->prepare(
'Item',
array(
'server' => $server
)
);
return $this->run('Item', 'item');
}
function getUpdatedItems($limitf = false, $limitr = false) {
$this->_sql = '
select * from item natural join (
select distinct node, max(updated) as num from postn
where node not like :node
group by node
order by node) as post
order by num desc
';
2015-08-19 11:28:28 +02:00
if($limitr)
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'node' => 'urn:xmpp:microblog%'
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Item');
}
function deleteItems($server) {
$this->_sql = '
delete from item
where server= :server';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'server' => $server
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Item');
}
function deleteItem($server, $item) {
$this->_sql = '
delete from item
where server = :server
and node = :node';
2015-08-19 11:28:28 +02:00
$this->prepare(
'Item',
array(
'server' => $server,
'node' => $item
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Item');
}
2015-08-19 11:28:28 +02:00
function getItem($server, $item) {
$this->_sql = '
select * from item
2015-08-19 11:28:28 +02:00
where
node = :node
and server = :server';
2015-08-19 11:28:28 +02:00
$this->prepare(
2015-08-19 11:28:28 +02:00
'Item',
array(
'node' => $item,
'server' => $server
)
);
2015-08-19 11:28:28 +02:00
return $this->run('Item', 'item');
}
}