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');
 }
Esempio n. 2
0
 /**
  * CAREFUL: if you are not absolutely positive that you won't need other slots for this
  * page (ie it is NOT the current page), then don't use this. Use retrieveBySlugWithSlots
  * If culture is null you get the current user's culture,
  * or sf_default_culture if none is set or we're running in a task context
  * @param mixed $slug
  * @param mixed $culture
  * @return mixed
  */
 public static function retrieveBySlugWithTitles($slug, $culture = null)
 {
     if (is_null($culture)) {
         $culture = aTools::getUserCulture();
     }
     $query = aPageTable::queryWithTitles($culture);
     $page = $query->andWhere('p.slug = ?', $slug)->fetchOne();
     // In case Doctrine is clever and returns the same page object
     if ($page) {
         $page->clearSlotCache();
         $page->setCulture($culture);
     }
     return $page;
 }
 public static function titleSearch($search, $slugPrefix)
 {
     $q = aPageTable::queryWithTitles();
     $q->addWhere('p.slug LIKE ?', array("{$slugPrefix}%"));
     $q->addWhere('s.value LIKE ?', array('%' . $search . '%'));
     $q->addWhere('p.archived IS FALSE');
     $virtualPages = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
     $ids = array();
     foreach ($virtualPages as $page) {
         if (preg_match("/^{$slugPrefix}\\?id=(\\d+)\$/", $page['slug'], $matches)) {
             $ids[] = $matches[1];
         }
     }
     if (!count($ids)) {
         return array();
     } else {
         return Doctrine::getTable('aBlogItem')->createQuery('e')->whereIn('e.id', $ids)->execute(array(), Doctrine::HYDRATE_ARRAY);
     }
 }