To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

root/plugins/apostropheBlogPlugin/branches/1.5/modules/aEventAdmin/lib/BaseaEventAdminActions.class.php @ 4097

Revision 4097, 6.4 KB (checked in by tboutell, 21 months ago)

* Blog and events search now works with aMysqlSearchPlugin (which means it works again in the sandbox)
* aSearchBody refactored to be a simple wrapper in the case where search services are present; old implementation in place for maximum backwards compatibility if you're not using search services

Line 
1<?php
2require_once dirname(__FILE__).'/aEventAdminGeneratorConfiguration.class.php';
3require_once dirname(__FILE__).'/aEventAdminGeneratorHelper.class.php';
4/**
5 * Base actions for the aEventPlugin aEventAdmin module.
6 *
7 * @package     aEventPlugin
8 * @subpackage  aEventAdmin
9 * @author      Dan Ordille <dan@punkave.com>
10 */
11abstract class BaseaEventAdminActions extends autoAEventAdminActions
12{ 
13  public $minorSorts = array('start_date desc', 'start_time desc');
14  public function preExecute()
15  {
16    parent::preExecute();
17  }
18
19  // You must create with at least a title
20  public function executeNew(sfWebRequest $request)
21  {
22    $this->forward404();
23  }
24 
25  // Doctrine collection routes make it a pain to change the settings
26  // of the standard routes fundamentally, so we provide another route
27  public function executeNewWithTitle(sfWebRequest $request)
28  {
29    $this->form = new aNewEventForm();
30    $this->form->bind($request->getParameter('a_new_event'));
31    if ($this->form->isValid())
32    {
33      $this->a_event = new aEvent();
34      $this->a_event->Author = $this->getUser()->getGuardUser();
35      $this->a_event->setTitle($this->form->getValue('title'));
36                        // Reasonable default: event starts at the top of the next half hour, and runs for one hour
37                        $now = time();
38                        $halfHours = floor($now / (30 * 60));
39                        $halfHours ++;
40                        $now = $halfHours * (30 * 60);
41                        $later = $now + 60 * 60;
42                       
43                        $this->a_event->start_date = date('Y-m-d', $now);
44                        $this->a_event->end_date = date('Y-m-d', $later);
45                        $this->a_event->start_time = date('H:i:s', $now);
46                        $this->a_event->end_time = date('H:i:s', $later);
47      $this->a_event->save();
48     
49      $event = new sfEvent($this->a_event, 'a.eventAdded', array());
50      $this->dispatcher->notify($event);
51     
52      $this->getUser()->setFlash('new_post', true);
53      $this->eventUrl = $this->generateUrl('a_event_admin_edit', $this->a_event);
54      return 'Success';
55    }
56    return 'Error';
57  }
58   
59  // DEPRECATED, see executeSearch below
60   
61  public function executeAutocomplete(sfWebRequest $request)
62  {
63    // Search is in virtual pages, the TITLE field is dead (or going to be) and not
64    // I18N, we have to cope with that correctly. I tried to use Zend Search but we
65    // can't easily distinguish blog pages from the rest and that seems to be a deeper
66    // architectural problem. I still had to fix a few things in PluginaBlogItem which
67    // was locking the virtual pages down and making them unsearchable by normal mortals.
68    // Now it locks them down only when they are not status = published. Republish things
69    // to get the benefit of this on existing sites
70   
71    $this->aEvents = aBlogItemTable::titleSearch($request->getParameter('q'), '@a_event_search_redirect');
72    $this->setLayout(false);
73  }
74 
75  /**
76   * Autocomplete of title in 'term'. Outputs jquery autocomplete compatible list of events
77   */
78  public function executeSearch(sfWebRequest $request)
79  {
80    return aBlogToolkit::searchBody($this, '@a_event_search_redirect', 'aEvent', null, $request);
81  }   
82 
83  public function executeUpdate(sfWebRequest $request)
84  {
85    $this->setAEventForUser();
86    $this->form = new aEventForm($this->a_event);
87    if ($request->getMethod() === 'POST')
88    {
89      $this->form->bind($request->getParameter($this->form->getName()));
90      if ($this->form->isValid())
91      {
92        $this->a_event = $this->form->save();
93
94        // We do this here to avoid some nasty race conditions that crop up when
95        // we try to push things to the page inside the Doctrine form transaction
96        $this->a_event->updatePageTagsAndCategories();
97
98        // Recreate the form to get rid of bound values for the publication field,
99        // so we can see the new setting
100        $this->form = new aEventForm($this->a_event);
101      }
102    }
103    if (!$request->isXmlHttpRequest())
104    {
105      return $this->redirect($this->generateUrl('a_event_admin_edit', $this->a_event));
106    }
107    $this->getTagInfo();
108  }
109 
110  protected function setAEventForUser()
111  {
112    $request = $this->getRequest();
113    if ($this->getUser()->hasCredential('admin'))
114    {
115      $this->a_event = $this->getRoute()->getObject();
116    }
117    else
118    {
119      $this->a_event = Doctrine::getTable('aEvent')->findOneEditable($request->getParameter('id'), $this->getUser()->getGuardUser()->getId());
120    }
121  }
122 
123  public function executeRedirect()
124  {
125    $aEvent = $this->getRoute()->getObject();
126    aRouteTools::pushTargetEnginePage($aEvent->findBestEngine());
127    $url = $this->generateUrl('a_event_post', $aEvent);
128    $this->redirect($url);
129  }
130
131  public function executeCategories()
132  {
133    $this->redirect('@a_blog_category_admin');
134  }
135
136  public function executeIndex(sfWebRequest $request)
137  {
138    if(!aPageTable::getFirstEnginePage('aEvent'))
139    {
140      $this->setTemplate('engineWarning');
141    }
142
143    parent::executeIndex($request);
144    aBlogItemTable::populatePages($this->pager->getResults());
145  }
146
147  public function executeEdit(sfWebRequest $request)
148  {
149    $this->setAEventForUser();
150    $this->forward404Unless($this->a_event);
151    $this->form = new aEventForm($this->a_event);
152
153    aBlogItemTable::populatePages(array($this->a_event));
154    $this->getTagInfo();
155  }
156
157  protected function getTagInfo()
158  {
159                // Retrieve the tags currently assigned to the event for the inlineTaggableWidget
160                $this->existingTags = $this->form->getObject()->getTags();
161                // Retrieve the 10 most popular tags for the inlineTaggableWidget
162    $this->popularTags = TagTable::getAllTagNameWithCount(null, array('model' => 'aEvent', 'sort_by_popularity' => true), false, 10);
163  }
164
165  protected function buildQuery()
166  {
167    if (is_null($this->filters))
168    {
169      $this->filters = $this->configuration->getFilterForm($this->getFilters());
170    }
171    $filters = $this->getFilters();
172    $resetFilters = false;
173    foreach($this->filters->getAppliedFilters() as $name => $field)
174    {
175      foreach($field as $key => $value)
176      {
177        if(is_null($value))
178        {
179          unset($filters[$name]);
180          $resetFilters = true;
181        }
182      }
183    }
184    if($resetFilters)
185    {
186      $this->getUser()->setAttribute('aBlogAdmin.filters', $filters, 'admin_module');
187      $this->filters = $this->configuration->getFilterForm($this->getFilters());
188    }
189
190    $query = parent::buildQuery();
191    $query->leftJoin($query->getRootAlias().'.Author')
192      ->leftJoin($query->getRootAlias().'.Editors')
193      ->leftJoin($query->getRootAlias().'.Categories')
194      ->leftJoin($query->getRootAlias().'.Page');
195    return $query;
196  }
197}
Note: See TracBrowser for help on using the browser.