Browse Source

- Add a pagination on the Contact explore view

pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
c7a19b9e8c
  1. 1
      app/models/contact/Contact.php
  2. 17
      app/models/contact/ContactDAO.php
  3. 30
      app/widgets/Contact/Contact.php
  4. 37
      app/widgets/Contact/_contact_explore.tpl
  5. 44
      app/widgets/Contact/_contact_public.tpl
  6. 14
      system/Utils.php
  7. 1
      themes/material/css/form.css

1
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)

17
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 = '

30
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;

37
app/widgets/Contact/_contact_explore.tpl

@ -1,39 +1,6 @@
<br />
<h2>{$c->__('explore')}</h2>
<ul class="flex card active thick">
{loop="$users"}
<li class="{if="$value->description != ''"}condensed{/if} block" style="background-image: url();" onclick="Contact_ajaxGetContact('{$value->jid}');">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$value->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
<span>{$value->getTrueName()}</span>
{if="$value->getAge()"}
<span class="info">{$c->__('age.years', $value->getAge())}</span>
{/if}
{if="$value->getGender()"}
<span class="info">{$value->getGender()}</span>
{/if}
<!--
{if="$value->getMarital()"}
<span class="info">{$value->getMarital()}</span>
{/if}
-->
{if="$value->description != ''"}
<p>
{$value->description|strip_tags}
</p>
{/if}
</li>
{/loop}
<ul id="public_list" class="flex card active middle">
{$users}
</ul>

44
app/widgets/Contact/_contact_public.tpl

@ -0,0 +1,44 @@
{loop="$users"}
<li class="{if="$value->description != ''"}condensed{/if} block" style="background-image: url();" onclick="Contact_ajaxGetContact('{$value->jid}');">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$value->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
<span>{$value->getTrueName()}</span>
{if="$value->getAge()"}
<span class="info">{$c->__('age.years', $value->getAge())}</span>
{/if}
{if="$value->getGender()"}
<span class="info">{$value->getGender()}</span>
{/if}
<!--
{if="$value->getMarital()"}
<span class="info">{$value->getMarital()}</span>
{/if}
-->
{if="$value->description != ''"}
<p>
{$value->description|strip_tags}
</p>
{/if}
</li>
{/loop}
{if="$pages"}
<li class="block condensed">
<span class="icon gray">
<i class="md md-my-library-books"></i>
</span>
{loop="$pages"}
<a onclick="Contact_ajaxPublic('{$key}');" class="button flat {if="$key == $page"}on{/if}">{$key+1}</a>
{/loop}
</li>
{/if}

14
system/Utils.php

@ -562,6 +562,20 @@ function generateKey($size) {
return $hash;
}
/*
* @desc Get the range aroung a position with a radius
*/
function geoRadius($latitude, $longitude, $radius) {
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($latitude) * 69.172));
$min_lat = number_format($latitude - $lat_range, "4", ".", "");
$max_lat = number_format($latitude + $lat_range, "4", ".", "");
$min_lon = number_format($longitude - $lon_range, "4", ".", "");
$max_lon = number_format($longitude + $lon_range, "4", ".", "");
return array($min_lat, $max_lat, $min_lon, $max_lon);
}
/*
* @desc Request a simple url
*/

1
themes/material/css/form.css

@ -273,6 +273,7 @@ input[type=button]:hover {
}
.button.flat:hover,
.button.flat.on,
input[type=button].flat:hover {
background-color: rgba(153, 153, 153, 0.2);
}

Loading…
Cancel
Save