From c7a19b9e8c36e42875f443e106d84e6bcde454a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaussoin=20Timoth=C3=A9e?= Date: Sun, 17 May 2015 23:58:23 +0200 Subject: [PATCH] - Add a pagination on the Contact explore view --- app/models/contact/Contact.php | 1 + app/models/contact/ContactDAO.php | 17 ++++++++- app/widgets/Contact/Contact.php | 30 ++++++++++++++-- app/widgets/Contact/_contact_explore.tpl | 37 ++------------------ app/widgets/Contact/_contact_public.tpl | 44 ++++++++++++++++++++++++ system/Utils.php | 14 ++++++++ themes/material/css/form.css | 1 + 7 files changed, 105 insertions(+), 39 deletions(-) create mode 100644 app/widgets/Contact/_contact_public.tpl diff --git a/app/models/contact/Contact.php b/app/models/contact/Contact.php index 8e225c51e..911cad05d 100755 --- a/app/models/contact/Contact.php +++ b/app/models/contact/Contact.php @@ -365,6 +365,7 @@ class Contact extends Model { if(isset($this->date) && $this->date != '0000-00-00T00:00:00+0000' && $this->date != '1970-01-01 00:00:00' + && $this->date != '1970-01-01 01:00:00' && $this->date != '1970-01-01T00:00:00+0000') { $age = intval(substr(date('Ymd') - date('Ymd', strtotime($this->date)), 0, -4)); if($age != 0) diff --git a/app/models/contact/ContactDAO.php b/app/models/contact/ContactDAO.php index 734728332..272640d14 100755 --- a/app/models/contact/ContactDAO.php +++ b/app/models/contact/ContactDAO.php @@ -373,7 +373,7 @@ class ContactDAO extends SQL { left outer join privacy on contact.jid = privacy.pkey where privacy.value = 1 - order by created desc'; + order by updated desc'; if($limitr) $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; @@ -381,6 +381,21 @@ class ContactDAO extends SQL { $this->prepare('Contact'); return $this->run('Contact'); } + + function countAllPublic() { + $this->_sql = + 'select count(*) from contact + left outer join privacy + on contact.jid = privacy.pkey + where privacy.value = 1'; + + $this->prepare('Contact'); + + $results = $this->run(null, 'array'); + $results = array_values($results[0]); + + return (int)$results[0]; + } function cleanRoster() { $this->_sql = ' diff --git a/app/widgets/Contact/Contact.php b/app/widgets/Contact/Contact.php index 04afcea4c..6cfe3e757 100644 --- a/app/widgets/Contact/Contact.php +++ b/app/widgets/Contact/Contact.php @@ -7,6 +7,8 @@ use Moxl\Xec\Action\Pubsub\GetItems; class Contact extends WidgetBase { + private $_paging = 10; + function load() { $this->registerEvent('roster_updateitem_handle', 'onContactEdited'); @@ -151,10 +153,10 @@ class Contact extends WidgetBase { if($jid == null) { $cd = new \modl\ContactDAO(); - $users = $cd->getAllPublic(0, 10); - if($users != null){ + $count = $cd->countAllPublic(); + if($count != 0){ $view = $this->tpl(); - $view->assign('users', array_reverse($users)); + $view->assign('users', $this->preparePublic()); return $view->draw('_contact_explore', true); } else { return ''; @@ -166,6 +168,28 @@ class Contact extends WidgetBase } } + function ajaxPublic($page = 0) + { + $validate_page = Validator::int(); + if(!$validate_page->validate($page)) return; + + RPC::call('MovimTpl.fill', '#public_list', $this->preparePublic($page)); + } + + private function preparePublic($page = 0) + { + $cd = new \modl\ContactDAO(); + $users = $cd->getAllPublic($page*$this->_paging, $this->_paging); + $count = $cd->countAllPublic(); + if($users != null){ + $view = $this->tpl(); + $view->assign('pages', array_fill(0, (int)($count/$this->_paging), 'p')); + $view->assign('users', array_reverse($users)); + $view->assign('page', $page); + return $view->draw('_contact_public', true); + } + } + function prepareContact($jid) { if(!$this->validateJid($jid)) return; diff --git a/app/widgets/Contact/_contact_explore.tpl b/app/widgets/Contact/_contact_explore.tpl index 9f2b87b0f..7cc441909 100644 --- a/app/widgets/Contact/_contact_explore.tpl +++ b/app/widgets/Contact/_contact_explore.tpl @@ -1,39 +1,6 @@

{$c->__('explore')}

-