added ability to grab a users image, and got a count of how many there are with images available

This commit is contained in:
arzynik 2013-11-27 15:09:15 -08:00
parent b22c5f51f7
commit b6949f0717
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?php
class Controller_test_userimage extends Crunchbutton_Controller_Account {
public function init() {
$users = User::q('
select `user`.* from `user` left join user_auth using(id_user)
where
user_auth.active=1
and user.active=1
and ((user_auth.type = "local" and user_auth.email LIKE "%@%") or (user_auth.type = "facebook"))
group by `user`.id_user
order by `user`.id_user
');
$c = 0;
foreach ($users as $user) {
if ($user->image()) {
$image = ['name' => $user->name, 'image' => $user->image()];
if (strpos($user->image(),'gravitar')) {
$image['type'] = 'gravitar';
} else {
$image['type'] = 'facebook';
}
$images[] = $image;
$c++;
}
}
Cana::view()->images = $images;
Cana::view()->layout('layout/blank');
Cana::view()->useFilter(false);
Cana::view()->display('test/userimage');
}
}

View File

@ -226,6 +226,28 @@ class Crunchbutton_User extends Cana_Table {
public function debits(){
return Crunchbutton_Credit::debitByUser( $this->id_user );
}
public function image() {
if (!isset($this->_image)) {
$auths = $this->auths();
foreach ($auths as $auth) {
if ($auth->type == 'facebook') {
$image = 'http://graph.facebook.com/'.$auth->auth.'/picture?type=square&height=200&width=200';
break;
}
}
if (!$image) {
foreach ($auths as $auth) {
if ($auth->type == 'local') {
$image = 'http://www.gravatar.com/avatar/'.md5(strtolower($auth->email)).'?s=480&d=404';
break;
}
}
}
$this->_image = $image;
}
return $this->_image;
}
public function __construct($id = null) {
parent::__construct();

View File

@ -0,0 +1,22 @@
<style>
.image {
height: 100px;
width: 100px;
}
.hidden {
display: none;
}
</style>
<? foreach ($this->images as $image) : ?>
<img src="<?=$image['image']?>" class="image <?=$image['type']?>">
<? endforeach ; ?>
<div class="count"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('img').error(function () {
$(this).addClass('hidden');
});
});
</script>