public function executeUpdate(sfWebRequest $request) { if ($this->getUser()->hasCredential('admin')) { $this->a_event = $this->getRoute()->getObject(); } else { $this->a_event = Doctrine::getTable('aEvent')->findOneEditable($request->getParameter('id'), $this->getUser()->getGuardUser()->getId()); } $this->forward404Unless($this->a_event); $this->form = $this->configuration->getForm($this->a_event); if ($request->isXmlHttpRequest()) { $this->setLayout(false); $response = array(); $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $this->a_event = $this->form->save(); //We need to recreate the form to handle the fact that it is not possible to change the value of a sfFormField $this->form = $this->configuration->getForm($this->a_event); $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $this->a_event))); } $response['errors'] = $this->form->getErrorSchema()->getErrors(); aPageTable::queryWithTitles()->addWhere('page_id = ?', $this->a_event['page_id'])->execute(); $response['aBlogPost'] = $this->a_event->toArray(); $response['aBlogPost']['title'] = html_entity_decode($response['aBlogPost']['title'], ENT_COMPAT, 'UTF-8'); $response['modified'] = $this->a_event->getLastModified(); $response['time'] = aDate::time($this->a_event['updated_at']); //Any additional messages can go here $output = json_encode($response); $this->getResponse()->setHttpHeader("X-JSON", '(' . $output . ')'); return sfView::HEADER_ONLY; } else { $this->processForm($request, $this->form); } $this->setTemplate('edit'); }
/** * @param string $name The element name * @param string $value The date displayed in this widget (sometimes already an array with hour and minute keys) * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $prefix = $this->generateId($name); $image = ''; if (false !== $this->getOption('image')) { // TODO: clock widget handling } $hourid = $this->generateId($name . '[hour]'); $minid = $this->generateId($name . '[minute]'); $s = '<div class="a-time-wrapper" id="' . $prefix . '-time">'; $s .= '<span style="display: none">' . parent::render($name, $value, $attributes, $errors) . '</span>'; $val = ''; if (is_array($value)) { if (strlen($value['hour']) && strlen($value['minute'])) { $val = htmlspecialchars(aDate::time(sprintf("%02d:%02d:00", $value['hour'], $value['minute']), false)); } } elseif (strlen($value)) { $val = htmlspecialchars(aDate::time($value, false), ENT_QUOTES); } $s .= "<input type='text' name='a-ignored' id='{$prefix}-ui' value='{$val}' class='" . (isset($attributes['class']) ? $attributes['class'] : '') . "'><img id='{$prefix}-ui-trigger' class='ui-timepicker-trigger' src='/apostrophePlugin/images/a-icon-time.png'/>"; $s .= <<<EOM <script> \$(function() { var hour; var min; var times = [ ]; for (thour = 0; (thour < 24); thour++) { // Starting with 8am makes more sense for typical clients var hour = (thour + 8) % 24; for (min = 0; (min < 60); min += 30) { times.push(prettyTime(hour, min)); } } \$('#{$prefix}-ui').autocomplete(times, { minChars: 0, selectFirst: false, max: 100 }); // Double click on focus pops up autocomplete immediately \$('#{$prefix}-ui').focus(function() { \$(this).click(); \$(this).click() } ).next().click(function(event){ \t\tevent.preventDefault(); \t\t\$(this).prev().focus(); \t}); \$('#{$prefix}-ui').blur(function() { var val = \$(this).val(); var components = val.match(/(\\d\\d?)(:\\d\\d)?\\s*(am|pm)?/i); if (components) { var hour = components[1]; var min = components[2]; if (min) { min = min.substr(1); } if (!min) { min = '00'; } if (min < 10) { min = '0' + Math.floor(min); } var ampm = components[3] ? components[3].toUpperCase() : false; if (!ampm) { if (hour >= 8) { ampm = 'AM'; } else { ampm = 'PM'; } } var formal = hour + ':' + min + ampm; \$(this).val(formal); if ((ampm === 'AM') && (hour == 12)) { hour = 0; } if ((ampm === 'PM') && !(hour == 12)) { // Careful: force numeric hour = Math.floor(hour) + 12; } \$('#{$hourid}').val(hour); \$('#{$minid}').val(min); // Something to bind to in other places \$(this).trigger('aTimeUpdated'); } else { if (val.length) { alert("The time must be in hh:mm format, followed by AM or PM. Hint: click on the typeahead suggestions."); \$('#{$prefix}-ui').focus(); } else { // NULL is often a valid value \$('#{$hourid}').val(''); \$('#{$minid}').val(''); } } }); function prettyTime(hour, min) { var ampm = 'AM'; phour = hour; if (hour >= 12) { ampm = 'PM'; } if (hour >= 13) { phour -= 12; } if (phour == 0) { phour = 12; } pmin = min; if (min < 10) { pmin = '0' + Math.floor(min); } return phour + ':' + pmin + ampm; } \t// General useability stuff that the original date widget was lacking because it was made by robots and not actual human beings \t\$('#{$prefix}-ui-trigger').attr('title','Set A Time').hover(function(){ \t\t\$(this).fadeTo(0,.5); \t},function(){ \t\t\$(this).fadeTo(0,1); \t}); }); </script> </div> EOM; return $s; }
?> <td class="date"> <?php // Localize the date. We used to do: "j M Y - g:iA" ?> <?php // Avoid a crash in some versions of PHP when date columns ?> <?php // are null or all zeroes ?> <?php if ($data['created_at'] > '0000-00-00 00:00:00') { ?> <?php echo aDate::pretty($data['created_at']) . ' ' . aDate::time($data['created_at']); ?> <?php } ?> </td> <td class="editor"> <?php echo $data['author']; ?> </td> <td class="preview"> <?php echo $data['diff']; ?> </td>
</a> <?php } else { ?> <?php echo $feedItem->getTitle(); ?> <?php } ?> </li> <?php $date = $feedItem->getPubDate(); ?> <?php if ($date) { ?> <li class="date"><?php echo $dateFormat ? date($dateFormat, $date) : aDate::pretty($date) . ' ' . aDate::time($date); ?> </li> <?php } ?> <li class="description"><?php echo auto_link_text(aHtml::simplify($feedItem->getDescription(), $markup, false, isset($attributes) ? $attributes : false, isset($styles) ? $styles : false)); ?> </li> </ul> </li>
<?php $startDate = aDate::dayMonthYear($aEvent->getStartDate()); $endDate = aDate::dayMonthYear($aEvent->getEndDate()); $startTime = aDate::time($aEvent->getStartDate()); $endTime = aDate::time($aEvent->getEndDate()); ?> <ul class="a-blog-item-meta"> <li class="start-date"><?php echo $startDate; ?> </li> <?php if ($startDate == $endDate) { ?> <?php if ($startTime != $endTime) { ?> <li class="event-time"><?php echo $startTime; ?> – <?php echo $endTime; ?> </li> <?php } ?> <?php } else {