Ejemplo n.º 1
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
         try {
             $event = $form->save();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $event)));
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@event_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $params = $request->getParameter('event');
             if (isset($params['main_slideshow'])) {
                 $objEvCat = EventCategoryTable::ExistByEventAndCat($event->get('id'), 2);
                 if (is_null($objEvCat)) {
                     $obj = new EventCategory();
                     $obj->setCategoryId(2);
                     $obj->setEventId($event->get('id'));
                     $obj->save();
                 }
             } else {
                 $objEvCat = EventCategoryTable::ExistByEventAndCat($event->get('id'), 2);
                 if (!is_null($objEvCat)) {
                     $objEvCat->delete();
                 }
             }
             if ($params['event_cat'] != '') {
                 $obj = new EventCategory();
                 $obj->setCategoryId($params['event_cat']);
                 $obj->setEventId($event->get('id'));
                 $obj->save();
             }
             $this->redirect('events/index');
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
Ejemplo n.º 2
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     //var_dump($request->getParameter('event[start_time]'));
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         //$event = $form->save();
         $name = $form->getValue('name');
         $venue = $form->getValue('venue');
         $description = $form->getValue('description');
         $price = $form->getValue('price');
         $c_ids = $form->getValue('category_ids');
         $event_url = $form->getValue('event_url');
         $start_time = $form->getValue('start_time');
         $end_time = $form->getValue('end_time');
         $date = $form->getValue('date');
         $o_id = $form->getValue('organizer_id');
         $event = null;
         if (!$form->getObject()->isNew()) {
             $event = $form->getObject();
             //Delete previous relations to genres
             Doctrine_Core::getTable('EventCategory')->createQuery()->delete()->where('event_id = ?', $event->getId())->execute();
         } else {
             $event = new Event();
         }
         if ($event === null) {
             $event = new Event();
         }
         //$event = new Event();
         //$event->setCategoryId($c_id);
         $event->setName($name);
         $event->setDescription($description);
         $event->setPrice($price);
         $event->setVenue($venue);
         $event->setEventUrl($event_url);
         $event->setStartTime($start_time);
         $event->setEndTime($end_time);
         $event->setOrganizerId($o_id);
         $sql_date = date("Y-m-d", strtotime($date));
         $event->setDate($sql_date);
         $event->save();
         foreach ($c_ids as $cid) {
             $ec = new EventCategory();
             $ec->setEventId($event->getId());
             $ec->setCategoryId($cid);
             $ec->save();
         }
         $this->getUser()->setAttribute('m', 1);
         $this->redirect('organize/edit?id=' . $event->getId() . '&m=1');
     }
 }