/** * Update the current walk with passed in form data * This also handles GPX data */ public function updateSocial(array $formData) { $this->loadSocial($formData['id']); // Update all basic fields // Fields that can't be saved are just ignored // Invalid fields throw an exception - display this to the user and continue foreach ($formData as $name => $value) { try { $this->social->{$name} = $value; } catch (UnexpectedValueException $e) { echo "<p>"; var_dump($name); var_dump($value); var_dump($e->getMessage()); echo "</p>"; } } // Empty checkboxes... if (empty($formData['showNormal'])) { $this->social->showNormal = false; } if (empty($formData['showNewMember'])) { $this->social->showNewMember = false; } // Time fields need to be built up (they combine date & time internally) if (!empty($formData['date'])) { if (!empty($formData['starttime'])) { $this->social->start = strtotime($formData['date'] . " " . $formData['starttime']); } else { $this->social->start = strtotime($formData['date']); } if (!empty($formData['endtime'])) { $this->social->end = strtotime($formData['date'] . " " . $formData['endtime']); } else { if ($formData['endtime'] == "") { $this->social->end = null; } } } if (!empty($formData['newMemberStart'])) { $this->social->newMemberStart = strtotime($formData['date'] . " " . $formData['newMemberStart']); } if (!empty($formData['newMemberEnd'])) { $this->social->newMemberEnd = strtotime($formData['date'] . " " . $formData['newMemberEnd']); } // Alterations $this->social->alterations->incrementVersion(); $this->social->alterations->setDetails($formData['alterations_details']); $this->social->alterations->setCancelled($formData['alterations_cancelled']); $this->social->alterations->setPlaceTime($formData['alterations_placeTime']); $this->social->alterations->setOrganiser($formData['alterations_organiser']); $this->social->alterations->setDate($formData['alterations_date']); if ($this->social->isValid()) { $this->social->save(); // Redirect to the list page $itemid = JRequest::getInt('returnPage'); if (empty($itemid)) { return false; } $item = JFactory::getApplication()->getMenu()->getItem($itemid); $link = new JURI("/" . $item->route); // Jump to the event? if (JRequest::getBool('jumpToEvent')) { $link->setFragment("social_" . $this->social->id); } JFactory::getApplication()->redirect($link, "Social saved"); } else { // Find out why it's invalid. // All other errors should be caught by JS - just check it's either a normal social or a new members one. if (!$this->social->showNormal && !$this->social->showNewMember) { } } }