private function process_update_post(CalendarEvent $old_event) { $updating = (bool) $old_event->getId(); if (isset($_POST['save']) && isset($_POST['event'])) { $post_data = array_map('trim', $_POST['event']); // validate the data and create error message $errors = $this->validate_post_data($post_data); if ($errors) { Flash::setNow('error', 'There are errors in the form.'); return array('event' => $old_event, 'updating' => $updating, 'post_data' => $post_data, 'errors' => $errors); } // if we'are updating an event, some data should be added to $post_data if ($updating) { $post_data['id'] = $old_event->getId(); $post_data['created_by_id'] = $old_event->getAuthorID(); } $updated_event = new CalendarEvent($post_data); $saved = $updated_event->save(); if ($saved) { Flash::set('success', $updating ? __('The event has been updated.') : __('A new event has been created.')); redirect(get_url('plugin/' . CALENDAR_ID . '/events')); } else { Flash::setNow('error', __('Could not update this event!')); return array('event' => $updated_event, 'updating' => $updating); } } // if it's not POST, just return $old_event return array('event' => $old_event, 'updating' => $updating); }
/** * Exclude object from result * * @param CalendarEvent $calendarEvent Object to remove from the list of results * * @return CalendarEventQuery The current query, for fluid interface */ public function prune($calendarEvent = null) { if ($calendarEvent) { $this->addUsingAlias(CalendarEventPeer::ID, $calendarEvent->getId(), Criteria::NOT_EQUAL); } return $this; }
<form action="<?php echo BASE_URL; ?> plugin/calendar/update_event" method="post"> <fieldset style="padding:0.5em;"> <legend style="padding: 0em 0.5em 0em 0.5em; font-weight: bold;"><?php echo __('Edit the event'); ?> </legend> <table class="fieldset" cellspacing="0" cellpadding="0" border="0"> <?php if ($edit_event) { ?> <input type="hidden" name="event[id]" value="<?php echo $event->getId(); ?> " /> <input type="hidden" name="event[created_by_id]" value="<?php echo $event->getAuthorID(); ?> " /> <?php } ?> <tr> <td class="label"><label for="event-title"><?php echo __('Title'); ?> </label></td>
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param CalendarEvent $value A CalendarEvent object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(CalendarEvent $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }