1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains the flag_user class.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements a user flag.
|
10
|
*/
|
11
|
class flag_user extends flag_entity {
|
12
|
function options() {
|
13
|
$options = parent::options();
|
14
|
$options += array(
|
15
|
'show_on_profile' => TRUE,
|
16
|
'access_uid' => '',
|
17
|
);
|
18
|
return $options;
|
19
|
}
|
20
|
|
21
|
/**
|
22
|
* Options form extras for user flags.
|
23
|
*/
|
24
|
function options_form(&$form) {
|
25
|
parent::options_form($form);
|
26
|
$form['access']['types'] = array(
|
27
|
// A user flag doesn't support node types.
|
28
|
// TODO: Maybe support roles instead of node types.
|
29
|
'#type' => 'value',
|
30
|
'#value' => array(0 => 0),
|
31
|
);
|
32
|
$form['access']['access_uid'] = array(
|
33
|
'#type' => 'checkbox',
|
34
|
'#title' => t('Users may flag themselves'),
|
35
|
'#description' => t('Disabling this option may be useful when setting up a "friend" flag, when a user flagging themself does not make sense.'),
|
36
|
'#default_value' => $this->access_uid ? 0 : 1,
|
37
|
);
|
38
|
$form['display']['show_on_profile'] = array(
|
39
|
'#type' => 'checkbox',
|
40
|
'#title' => t('Display link on user profile page'),
|
41
|
'#description' => t('Show the link formatted as a user profile element.'),
|
42
|
'#default_value' => $this->show_on_profile,
|
43
|
// Put this above 'show on entity'.
|
44
|
'#weight' => -1,
|
45
|
);
|
46
|
}
|
47
|
|
48
|
function form_input($form_values) {
|
49
|
parent::form_input($form_values);
|
50
|
// The access_uid value is intentionally backwards from the UI, to avoid
|
51
|
// confusion caused by checking a box to disable a feature.
|
52
|
$this->access_uid = empty($form_values['access_uid']) ? 'others' : '';
|
53
|
}
|
54
|
|
55
|
function type_access($entity_id, $action, $account) {
|
56
|
// Prevent users from flagging themselves.
|
57
|
if ($this->access_uid == 'others' && $entity_id == $account->uid) {
|
58
|
return FALSE;
|
59
|
}
|
60
|
}
|
61
|
|
62
|
function type_access_multiple($entity_ids, $account) {
|
63
|
$access = array();
|
64
|
|
65
|
// Exclude anonymous.
|
66
|
if (array_key_exists(0, $entity_ids)) {
|
67
|
$access[0] = FALSE;
|
68
|
}
|
69
|
|
70
|
// Prevent users from flagging themselves.
|
71
|
if ($this->access_uid == 'others' && array_key_exists($account->uid, $entity_ids)) {
|
72
|
$access[$account->uid] = FALSE;
|
73
|
}
|
74
|
|
75
|
return $access;
|
76
|
}
|
77
|
|
78
|
function get_flag_action($entity_id) {
|
79
|
$flag_action = parent::get_flag_action($entity_id);
|
80
|
$user = $this->fetch_entity($entity_id);
|
81
|
$flag_action->content_title = $user->name;
|
82
|
$flag_action->content_url = $this->_flag_url('user/' . $user->uid);
|
83
|
return $flag_action;
|
84
|
}
|
85
|
|
86
|
function get_relevant_action_objects($entity_id) {
|
87
|
return array(
|
88
|
'user' => $this->fetch_entity($entity_id),
|
89
|
);
|
90
|
}
|
91
|
|
92
|
function get_views_info() {
|
93
|
$views_info = parent::get_views_info();
|
94
|
$views_info['title field'] = 'name';
|
95
|
return $views_info;
|
96
|
}
|
97
|
}
|