-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrelated-candidates.php
162 lines (142 loc) · 6.56 KB
/
related-candidates.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
* Author: National Research Council Canada
* Website: http://www.nrc-cnrc.gc.ca/eng/rd/ict/
*
* License: Creative Commons Attribution 3.0 Unported License
* Copyright: Her Majesty the Queen in Right of Canada, 2015
*/
/*
* Displays all the candidates which have relationships to the mission.
*/
$mission = $vars['entity'];
$applicant_relationships = get_entity_relationships($mission->guid);
// Sidebar content which displays the candidates who are going to work on this mission.
$applicants_none_accepted = true;
$applicants_none_tentative = true;
$accepted = '<h3>' . elgg_echo('missions:participants') . ':</h3>';
$tentative = '<h3>' . elgg_echo('missions:applicants') . ':</h3>';
$width_class_first = 'col-sm-12';
$width_class_second = $width_class_first;
$participant_count = 0;
$applicant_count = 0;
foreach ($applicant_relationships as $applicant_relation) {
// Candidates which have been accepted into the mission.
if ($applicant_relation->relationship == 'mission_accepted') {
$accepted .= '<div class="col-sm-12" style="display:inline-block;" name="mission-participant" id="mission-participant-' . $applicant_relation->guid_two . '">' . elgg_view_entity(get_user($applicant_relation->guid_two)) . '</div>';
if($mission->state == 'posted') {
if(elgg_get_logged_in_user_guid() == $mission->owner_guid || elgg_get_logged_in_user_guid() == $mission->account) {
// Removal button for the candidate.
$accepted .= '<div class="col-sm-12">' . elgg_view('output/url', array(
'href' => elgg_get_site_url() . 'action/missions/remove-applicant?aid=' . $applicant_relation->guid_two . '&mid=' . $mission->guid,
'text' => elgg_echo('missions:remove'),
'is_action' => true,
'class' => 'elgg-button btn btn-danger',
'style' => 'margin:4px;',
'id' => 'fill-mission-applicant-' . $applicant_relation->guid_two . '-remove-button',
'confirm' => elgg_echo('missions:placeholder_i')
)) . '</div>';
}
}
else {
$accepted .= '<div class="col-sm-4">';
if(elgg_get_logged_in_user_guid() == $mission->owner_guid || elgg_get_logged_in_user_guid() == $mission->account) {
$owner = $mission->owner_guid;
$target = $applicant_relation->guid_two;
}
else if(elgg_get_logged_in_user_guid() == $applicant_relation->guid_two) {
$owner = $applicant_relation->guid_two;
$target = $mission->owner_guid;
}
$feedback_search = elgg_get_entities_from_metadata(array(
'type' => 'object',
'subtype' => 'mission-feedback',
'owner_guid' => $owner,
'metadata_name_value_pairs' => array(
array('name' => 'recipient', 'value' => $target),
array('name' => 'mission', 'value' => $mission->guid),
array('name' => 'message', 'value' => 'sent')
)
));
if(elgg_get_logged_in_user_guid() == $mission->owner_guid || elgg_get_logged_in_user_guid() == $mission->account
|| elgg_get_logged_in_user_guid() == $applicant_relation->guid_two) {
if(count($feedback_search)) {
if($feedback_search[0]->endorsement != 'on') {
$accepted .= elgg_view('output/url', array(
'href' => elgg_get_site_url() . 'action/missions/endorse-user?fid=' . $feedback_search[0]->guid,
'text' => elgg_echo('missions:endorse'),
'is_action' => true,
'class' => 'elgg-button btn btn-success',
'style' => 'margin:4px;',
'id' => 'fill-mission-applicant-' . $applicant_relation->guid_two . '-endorse-button'
));
}
}
else {
$accepted .= elgg_view('output/url', array(
'href' => elgg_get_site_url() . 'missions/mission-feedback/' . $mission->guid,
'text' => elgg_echo('missions:feedback'),
'class' => 'elgg-button btn btn-success',
'style' => 'margin:4px;',
'id' => 'fill-mission-applicant-' . $applicant_relation->guid_two . '-submit-feedback-button'
));
}
}
$accepted .= '</div>';
}
$applicants_none_accepted = false;
$participant_count++;
}
// Candidates which have been sent an invitation to the mission.
if ($applicant_relation->relationship == 'mission_applied' || $applicant_relation->relationship == 'mission_offered') {
if($mission->state == 'posted') {
if(elgg_get_logged_in_user_guid() == $mission->owner_guid || elgg_get_logged_in_user_guid() == $mission->account
|| elgg_get_logged_in_user_guid() == $applicant_relation->guid_two || elgg_is_admin_logged_in()) {
$tentative .= '<div class="col-sm-12" style="display:inline-block;" name="mission-applicant" id="mission-applicant-' . $applicant_relation->guid_two . '">' . elgg_view_entity(get_user($applicant_relation->guid_two)) . '</div>';
if(elgg_get_logged_in_user_guid() == $mission->owner_guid || elgg_get_logged_in_user_guid() == $mission->account || elgg_is_admin_logged_in()) {
$tentative .= '<div class="col-sm-12">';
$tentative .= mm_offer_button($mission, get_user($applicant_relation->guid_two));
// Removal button for the candidate.
$tentative .= elgg_view('output/url', array(
'href' => elgg_get_site_url() . 'action/missions/remove-applicant?aid=' . $applicant_relation->guid_two . '&mid=' . $mission->guid,
'text' => elgg_echo('missions:remove'),
'is_action' => true,
'class' => 'elgg-button btn btn-danger',
'style' => 'margin:4px;',
'id' => 'fill-mission-applicant-' . $applicant_relation->guid_two . '-remove-button',
'confirm' => elgg_echo('missions:placeholder_i2')
));
$tentative .= '</div>';
}
$applicants_none_tentative = false;
}
$applicant_count++;
}
}
}
// Display something if there are no applicants.
if($applicants_none_accepted) {
$accepted .= '<div name="no-accepted-candidate" class="col-sm-12">' . elgg_echo('missions:nobody') . '</div>';
}
if($applicants_none_tentative && $applicant_count == 0) {
$tentative .= '<div name="no-tentative-candidate" class="col-sm-12">' . elgg_echo('missions:nobody') . '</div>';
}
else {
$s_or_not = '';
if($applicant_count > 1) {
$s_or_not = 's';
}
$tentative .= '<div name="applicant_count" class="col-sm-12">' . elgg_echo('missions:applicant_count', array($applicant_count, $s_or_not)) . '</div>';
}
$accepted .= $hidden_participant_count = elgg_view('input/hidden', array(
'name' => 'hidden_participant_count',
'value' => $participant_count
));
$tentative .= $hidden_applicant_count = elgg_view('input/hidden', array(
'name' => 'hidden_applicant_count',
'value' => $applicant_count
));
echo '<div>';
echo '<div class="' . $width_class_first . '" >' . $accepted . '</div>';
echo '<div class="' . $width_class_second . '" >' . $tentative . '</div>';
echo '</div>';