-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft.introvert.php
205 lines (170 loc) · 4.8 KB
/
ft.introvert.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Introvert: Fieldtype which outputs reverse related entries to the one being edited
*
* @package ExpressionEngine
* @subpackage Fieldtypes
* @category Fieldtypes
* @author Iain Urquhart <[email protected]>
* @copyright Copyright (c) 2010 Iain Urquhart
* @license All Rights Reserved.
*/
class Introvert_ft extends EE_Fieldtype
{
var $info = array(
'name' => 'Introvert Fieldtype',
'version' => '1.0'
);
public function Introvert_()
{
parent::EE_Fieldtype();
$this->EE->lang->loadfile('introvert');
}
// output the field on the publish page
public function display_field($data)
{
// when editing an entry the entry_id should be available as a GET
$entry_id = $this->EE->input->get('entry_id');
// if its not there, then its a new entry being published via the cp
if($entry_id == NULL)
{
// we'll stop here then, laters
return '<p>No Registrations yet</p>';
}
$r = '';
// build the css based on statuses
// if you have other statuses apart from open/closed, style them here
$r .= '
<style type="text/css">
tr.introvert-closed td{
color: #E11842;
}
tr.introvert-open td {
background:#E6EFC2;
color:#264409;
border-top: 1px solid #C6D880 !important;
border-bottom: 1px solid #C6D880 !important;
}
tr.introvert-open td a{
color:#264409;
}
tr.introvert-closed td {
background:#FBE3E4;
color:#8a1f11;
border-top: 1px solid #FBC2C4 !important;
border-bottom: 1px solid #FBC2C4 !important;
}
tr.introvert-closed td a{
color:#8a1f11;
}
</style>
';
// my needs are quite specific, so adjust the column names to suit what you're after
$r .= '<table class="mainTable" border="0" cellspacing="0" cellpadding="0" style="margin-top: 5px;">
<tr>
<th style="width: 30%;">Name</th>
<th style="width: 30%;">Email</th>
<th style="width: 30%;">Tel</th>
<th></th>
</tr>';
// build our reverse related query
// I'm getting some specific field data for my setup
// You'll need to update for your needs/setup
// field_id_25 = Registrant first name
// field_id_26 = Registrant surname
// field_id_27 = Email
// field_id_28 = Phone
// field_id_29 = Institute
$sql = "SELECT
exp_relationships.rel_parent_id,
exp_relationships.rel_child_id,
exp_channel_titles.title,
exp_channel_titles.entry_id,
exp_channel_titles.status,
exp_channel_data.field_id_25,
exp_channel_data.field_id_26,
exp_channel_data.field_id_27,
exp_channel_data.field_id_28,
exp_channel_data.field_id_29
FROM exp_relationships
LEFT JOIN exp_channel_titles
ON (exp_relationships.rel_parent_id=exp_channel_titles.entry_id)
LEFT JOIN exp_channel_data
ON (exp_relationships.rel_parent_id=exp_channel_data.entry_id)
WHERE exp_relationships.rel_child_id = '$entry_id'
AND exp_relationships.rel_type = 'channel'
ORDER BY exp_channel_titles.title";
// run it
$query = $this->EE->db->query($sql);
// build our 'edit' links
$edit_base = BASE.AMP.'C=content_publish'.AMP.'M=entry_form'.AMP.'channel_id=3'.AMP.'entry_id=';
if ($query->num_rows() > 0)
{
// build the table rows
foreach($query->result_array() as $row)
{
// make things a little more readable
// print_r($row);
$title = $row['title'];
$firstname = $row['field_id_25'];
$surname = $row['field_id_26'];
$email = $row['field_id_27'];
$phone = $row['field_id_28'];
$institute = $row['field_id_29'];
$status = $row['status'];
$edit_link = $edit_base.$row['entry_id'];
$r .= '<tr class="introvert-'.$status.'">';
$r .= "<td><strong>$firstname $surname</strong> ($institute)</td>";
$r .= "<td><a href='mailto:$email'>$email</a></td>";
$r .= "<td>$phone</td>";
$r .= "<td><a href='$edit_link'>View / Edit</a></td>";
$r .= '</tr>';
}
}
// no results
else
{
return '<p>Nothing yet…</p>';
}
$r .= '</table>';
return $r;
}
function pre_process($data)
{
// nada
}
public function replace_tag($data, $params = FALSE, $tagdata = FALSE)
{
// nada
}
public function save($data)
{
// we're not even saving anything
}
function post_save($data)
{
// nada
}
public function validate($data)
{
return TRUE;
}
public function save_settings($data)
{
// nada
}
public function display_settings($data)
{
// nada
}
function install()
{
// zip
}
function unsinstall()
{
// move along, nothing to see
}
}
//END CLASS
/* End of file ft.introvert.php */