| 173 | | $this->index(); |
| | 174 | |
| | 175 | if ($id == 'trackback') { |
| | 176 | $result = $this->Trackback->find('all', array( |
| | 177 | 'order' => 'Trackback.id DESC', |
| | 178 | 'limit' => '20', |
| | 179 | )); |
| | 180 | |
| | 181 | $this->set('events', $result); |
| | 182 | |
| | 183 | } else if (is_numeric($id)) { |
| | 184 | |
| | 185 | $has_many = array( |
| | 186 | 'EventComment' => array( |
| | 187 | 'className' => 'EventComment', |
| | 188 | 'foreignKey' => 'event_id' |
| | 189 | ), |
| | 190 | 'EventAttendee' => array( |
| | 191 | 'className' => 'EventAttendee', |
| | 192 | 'foreignKey' => 'event_id' |
| | 193 | ), |
| | 194 | ); |
| | 195 | |
| | 196 | $has_one = array( |
| | 197 | 'User' => array( |
| | 198 | 'className' => 'User', |
| | 199 | 'foreignKey' => 'user_id', |
| | 200 | ) |
| | 201 | ); |
| | 202 | |
| | 203 | $this->Event->bindModel(array('hasMany' => $has_many)); |
| | 204 | $this->Event->EventComment->bindModel(array('belongsTo' => $has_one)); |
| | 205 | $this->Event->EventAttendee->bindModel(array('belongsTo' => $has_one)); |
| | 206 | |
| | 207 | $event = $this->Event->findById($id, null, null, 2); |
| | 208 | if (!$event) { |
| | 209 | $this->index(); |
| | 210 | return null; |
| | 211 | } |
| | 212 | |
| | 213 | $result = array(); |
| | 214 | |
| | 215 | foreach ($event['EventComment'] as $event_comment) { |
| | 216 | $item = array(); |
| | 217 | $item['Event']['title'] = 'comment'; |
| | 218 | $item['Event']['description'] = $event_comment['User']['nickname'] .':'.$event_comment['comment']; |
| | 219 | $item['Event']['id'] = $event_comment['event_id']; |
| | 220 | $item['Event']['publish_date'] = $event_comment['created']; |
| | 221 | if (!$event_comment['created']) { |
| | 222 | $item['Event']['publish_date'] = date('Y-m-d H:i:s'); |
| | 223 | } |
| | 224 | $key = strtotime($item['Event']['publish_date']) . '0'; |
| | 225 | $result[$key] = $item; |
| | 226 | } |
| | 227 | |
| | 228 | foreach ($event['EventAttendee'] as $event_attendee) { |
| | 229 | $item = array(); |
| | 230 | $item['Event']['title'] = 'joined'; |
| | 231 | $item['Event']['description'] = $event_attendee['User']['nickname'] .':'.$event_attendee['comment']; |
| | 232 | $item['Event']['id'] = $event_attendee['event_id']; |
| | 233 | $item['Event']['publish_date'] = $event_attendee['created']; |
| | 234 | if (!$event_attendee['created']) { |
| | 235 | $item['Event']['publish_date'] = date('Y-m-d H:i:s'); |
| | 236 | } |
| | 237 | $key = strtotime($item['Event']['publish_date']) . '1'; |
| | 238 | $result[$key] = $item; |
| | 239 | } |
| | 240 | |
| | 241 | krsort($result); |
| | 242 | |
| | 243 | $events = array(); |
| | 244 | foreach ($result as $value) { |
| | 245 | $events[] = $value; |
| | 246 | } |
| | 247 | |
| | 248 | $this->set('events', $events); |
| | 249 | |
| | 250 | } else { |
| | 251 | $this->index(); |
| | 252 | } |
| | 253 | |