Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

BUmp field to Craig's latest. Merge fail.

  • Loading branch information...
commit e43a688a6a0ecb32cea554946b47303f95af7336 1 parent 8108fe0
Nick Dunn authored June 20, 2011

Showing 1 changed file with 27 additions and 11 deletions. Show diff stats Hide diff stats

  1. 38  fields/field.member_replies.php
38  fields/field.member_replies.php
@@ -82,7 +82,7 @@ public function displaySettingsPanel(&$wrapper, $errors=NULL){
82 82
 			
83 83
 			$group = new XMLElement('div', NULL, array('class' => 'group'));
84 84
 
85  
-			$label = Widget::Label(__('Reply Select Box Link'));
  85
+			$label = Widget::Label(__('Child Select Box Link'));
86 86
 			$label->appendChild(
87 87
 				Widget::Select('fields['.$this->get('sortorder').'][related_sbl_id]', $options)
88 88
 			);
@@ -194,9 +194,10 @@ private function getRepliesByParentId($entry_id) {
194 194
 				sprintf("SELECT `creation_date_gmt` FROM tbl_entries WHERE id=%d LIMIT 1", $latest_id)
195 195
 			);
196 196
 			
197  
-			$reply->{'latest-reply-id'} = $latest_id;
198  
-			$reply->{'latest-reply-date'} = date('Y-m-d', strtotime($latest_date_gmt));
199  
-			$reply->{'latest-reply-time'} = date('H:i', strtotime($latest_date_gmt));
  197
+			$reply->{'latest-reply'} = (object)array();
  198
+			$reply->{'latest-reply'}->{'id'} = $latest_id;
  199
+			$reply->{'latest-reply'}->{'date'} = date('Y-m-d', strtotime($latest_date_gmt));
  200
+			$reply->{'latest-reply'}->{'time'} = date('H:i', strtotime($latest_date_gmt));
200 201
 			
201 202
 			self::$replies[$entry_id] = $reply;
202 203
 			return $reply;
@@ -205,19 +206,29 @@ private function getRepliesByParentId($entry_id) {
205 206
 		// @todo: output list of latest entry IDs
206 207
 		public function getParameterPoolValue(Array $data, $entry_id=NULL){
207 208
 			$reply = $this->getRepliesByParentId($entry_id);
208  
-			return $reply->{'latest-reply-id'};
  209
+			return $reply->{'latest-reply'}->{'id'};
209 210
 		}
210 211
 		
211 212
 		// @todo: replace `1` in there queries with a call to Members to get member ID
212 213
 		// @todo: output latest child in XML with ID and creation date (for time ago processing)
213 214
 		public function appendFormattedElement(&$wrapper, $data, $encode=FALSE, $mode=NULL, $entry_id=NULL){
214 215
 			
  216
+			$member_id = Frontend::instance()->Page()->_param['member-id'];
  217
+			
215 218
 			$element = new XMLElement($this->get('element_name'), NULL);
216 219
 			
217 220
 			$reply = $this->getRepliesByParentId($entry_id);
218 221
 			
219 222
 			foreach($reply as $name => $value) {
220  
-				$element->setAttribute($name, $value);
  223
+				if($name != 'latest-reply') {
  224
+					$element->setAttribute($name, $value);
  225
+				}
  226
+				else {
  227
+					$latest = new XMLElement(__('latest'), $value->{'date'});
  228
+					$latest->setAttribute('id', $value->{'id'});
  229
+					$latest->setAttribute('time', $value->{'time'});
  230
+					$element->appendChild($latest);
  231
+				}
221 232
 			}
222 233
 			
223 234
 			$wrapper->appendChild($element);
@@ -226,9 +237,9 @@ public function appendFormattedElement(&$wrapper, $data, $encode=FALSE, $mode=NU
226 237
 				// find the last child entry ID that exists
227 238
 				
228 239
 				// remove any read state for this parent entry
229  
-				Symphony::Database()->query(sprintf("DELETE FROM tbl_member_replies WHERE member_id=%d AND entry_id=%d", 1, $entry_id));
  240
+				Symphony::Database()->query(sprintf("DELETE FROM tbl_member_replies WHERE member_id=%d AND entry_id=%d", $member_id, $entry_id));
230 241
 				// mark the last child as read
231  
-				Symphony::Database()->query(sprintf("INSERT INTO tbl_member_replies (member_id, entry_id, last_read_entry_id) VALUES(%d,%d,%d)", 1, $entry_id, $latest_id));
  242
+				Symphony::Database()->query(sprintf("INSERT INTO tbl_member_replies (member_id, entry_id, last_read_entry_id) VALUES(%d,%d,%d)", $member_id, $entry_id, $latest_id));
232 243
 			}
233 244
 		}
234 245
 
@@ -236,7 +247,10 @@ public function appendFormattedElement(&$wrapper, $data, $encode=FALSE, $mode=NU
236 247
 		Sorting:
237 248
 	-------------------------------------------------------------------------*/
238 249
 
239  
-		public function buildSortingSQL(&$joins, &$where, &$sort, $order='ASC'){
  250
+		public function buildSortingSQL(&$joins, &$where, &$sort, $order='ASC') {
  251
+			
  252
+			$member_id = Frontend::instance()->Page()->_param['member-id'];
  253
+			
240 254
 			// join on the related SBL field
241 255
 			$joins .= "LEFT JOIN `tbl_entries_data_".$this->get('related_sbl_id')."` AS `sbl` ON (`e`.`id` = `sbl`.`relation_id`) ";
242 256
 			
@@ -263,7 +277,7 @@ public function buildSortingSQL(&$joins, &$where, &$sort, $order='ASC'){
263 277
 								)
264 278
 								> (SELECT `last_read_entry_id` FROM `tbl_member_replies` WHERE `entry_id` = `e`.`id` AND `member_id`=%1\$d LIMIT 1)
265 279
 							)
266  
-					)", 1, $this->get('related_sbl_id'));
  280
+					)", $member_id, $this->get('related_sbl_id'));
267 281
 			}
268 282
 			
269 283
 			$sort .= " ORDER BY (
@@ -316,13 +330,15 @@ public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation=FALSE
316 330
 			$field_id = $this->get('id');
317 331
 			if (!is_array($data)) $data = array($data);
318 332
 			
  333
+			$member_id = Frontend::instance()->Page()->_param['member-id'];
  334
+			
319 335
 			$filter = reset($data);
320 336
 			$this->_key++;
321 337
 			
322 338
 			switch($filter) {
323 339
 				case 'unread':
324 340
 					self::$is_filtering = TRUE;
325  
-					$joins .= " LEFT JOIN `tbl_member_replies` AS `replies` ON (`e`.`id` = `replies`.`entry_id` AND `replies`.`member_id` = 1) ";
  341
+					$joins .= sprintf(" LEFT JOIN `tbl_member_replies` AS `replies` ON (`e`.`id` = `replies`.`entry_id` AND `replies`.`member_id` = %d) ", $member_id);
326 342
 				break;
327 343
 			}
328 344
 

0 notes on commit e43a688

Please sign in to comment.
Something went wrong with that request. Please try again.