forked from ethymos/delibera
-
Notifications
You must be signed in to change notification settings - Fork 8
/
delibera_user_display.php
114 lines (100 loc) · 3.05 KB
/
delibera_user_display.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Delibera\Theme;
use WP_User_Query;
use WP_Query;
class UserDisplay
{
public static function getOrderBy($order)
{
switch( $order )
{
//XXX essa opção não funciona, pois nao conta o numero de pautas de um usuário apenas de posts
//case "active":
// return array( 'orderby' => 'post_count' , 'order' => 'DESC' );
case "newest":
return array( 'orderby' => 'registered' , 'order' => 'DESC' );
default:
return array( 'orderby' => 'display_name' , 'order' => 'ASC' );
}
}
public static function getPaginator($total, $page)
{
return paginate_links( array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'show_all' => false ,
'total' => $total,
'current' => $page
));
}
public static function getNumberOfPages( $total_users , $users_per_page )
{
return ($total_users/$users_per_page);
}
public static function getUsers($order_by , $search , $per_page , $paged)
{
return new WP_User_Query(
array(
'number' => $per_page ,
'offset' => $paged,
'fields' => array( 'display_name', 'user_login' , 'ID' ),
'search' => $search . '*',
'search_columns' => array( 'ID' , 'user_nicename' , 'user_login' , 'user_email' ),
'orderby' => $order_by['orderby'],
'order' => $order_by['order'],
)
);
}
public static function getLastPauta($user)
{
$args = array(
'author' => $user->ID,
'post_type' => 'pauta',
'posts_per_page' => 1 ,
'orderby' => 'post_date',
'order' => 'ASC'
);
$current_user_posts = get_posts( $args );
return $current_user_posts? $current_user_posts[0] : null;
}
public static function get_comment_meta($id, $control)
{
$string = 'delibera_' . $control;
return get_comment_meta( $id , $string , true);
}
public static function parse_comment_type($id, $control)
{
$string = 'delibera_comment_' . $control;
$type = get_comment_meta( $id , $string , true);
//echo "DEBUG Tipo: " . $type;
switch($type)
{
case 'encaminhamento':
return __('Proposta de Encaminhamento','delibera');
case 'discussao':
return __('Discussão','delibera');
case 'validacao':
return __('Validação','delibera');
case 'voto':
return __('Votação','delibera');
case 'relatoria':
return __('Em Relatoria','delibera');
}
}
public static function getUserComments($user, $search, $per_page, $paged)
{
$args = array(
'user_id' => $user->ID,
'number' => $per_page,
'post_type' => 'pauta',
'status' => 'approve',
'search' => $search,
'offset' => $paged
);
return get_comments( $args );
}
}
global $user_display;
$user_display = new \Delibera\Theme\UserDisplay();