Example #1
0
 public function show(Request $request)
 {
     $modelClass = $this->modelClass;
     $items = array();
     if ($this['id'] === ':id' && $request->query->has('item')) {
         $pks = array_map(function ($i) {
             return json_decode($i, true);
         }, $request->query->get('item', array()));
         if ($pks && $this->parent instanceof AbstractBackend) {
             $items = \PropelQuery::from($this->parent->getModelClass())->findPks($pks)->getArrayCopy();
         }
     } else {
         $items = array($this->getSelection());
     }
     $items = array_filter($items, function ($item) use($modelClass) {
         return $item instanceof $modelClass;
     });
     if (!count($items)) {
         throw new \Exception('No item to delete');
     }
     $names = array_map(function ($item) {
         return method_exists($item, '__toString') ? '`' . htmlspecialchars((string) $item) . '`' : 'this item';
     }, $items);
     if ($request->isMethod('POST') && $request->request->get('do_delete')) {
         foreach ($items as $i => $item) {
             $pk = $item->getPrimaryKey();
             $item->delete();
             // Trigger update event
             //$this->createModelUpdateEvent($this->modelClass, $pk, 'delete');
             if ($item instanceof \Curry_ISearchable) {
                 \Curry_Backend_Indexer::removeItem($item);
             }
         }
         $this->addMainContent('<p>' . $names[$i] . ' has been deleted.</p>');
     } else {
         $this->addMainContent('<form method="post">' . '<input type="hidden" name="do_delete" value="1" />' . '<p>Do you really want to delete ' . join(', ', $names) . '?</p>' . '<button type="submit" class="btn btn-danger">Delete</button>' . '</form>');
     }
     return parent::render();
 }
Example #2
0
 public function show(Request $request)
 {
     $this->addMainContent($this->getHtml($request->query->all()));
     return parent::render();
 }
Example #3
0
 public function show(Request $request)
 {
     $modelClass = $this->modelForm->getModelClass();
     $item = $this->getSelection();
     if (!isset($item) || !$item instanceof $modelClass) {
         $item = new $modelClass();
         $relatedItem = $this->parent instanceof AbstractBackend ? $this->parent->getSelection() : null;
         if ($relatedItem) {
             $relations = \PropelQuery::from($modelClass)->getTableMap()->getRelations();
             foreach ($relations as $relation) {
                 if ($relation->getRightTable()->getPhpName() == get_class($relatedItem) && in_array($relation->getType(), array(\RelationMap::MANY_TO_ONE))) {
                     $item->{'set' . $relation->getName()}($relatedItem);
                 }
             }
         }
     }
     $form = clone $this->modelForm;
     $buttons = array('save');
     $form->addField('save', array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'));
     if (!$item->isNew() && $this->parent instanceof ListView && $this->parent->hasAction('delete')) {
         $form->addField('delete', array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger', 'onclick' => "return confirm('Do you really want to delete this item? This cannot be undone.');"));
         $buttons[] = 'delete';
     }
     //$form->addDisplayGroup($buttons, 'save_group', array('class' => 'horizontal-group'));
     $form->fillForm($item);
     if ($request->isMethod('POST') && $form->isValid($request->request->all())) {
         if ($form->delete && $form->delete->isChecked()) {
             //$this->createModelUpdateEvent($modelClass, $item->getPrimaryKey(), 'delete');
             $item->delete();
             if ($item instanceof \Curry_ISearchable) {
                 \Curry_Backend_Indexer::removeItem($item);
             }
             $this->addMainContent('<p>The item has been deleted.</p>');
             return parent::render();
         }
         $form->fillModel($item);
         $this->triggerCallback($this->preSave, $item, $form);
         $item->save();
         $this->triggerCallback($this->postSave, $item, $form);
         $form->fillForm($item);
         //$this->createModelUpdateEvent($modelClass, $item->getPrimaryKey(), 'update');
         if ($item instanceof \Curry_ISearchable) {
             \Curry_Backend_Indexer::updateItem($item);
         }
         if ($request->isXmlHttpRequest()) {
             return \Symfony\Component\HttpFoundation\Response::create('');
         }
     }
     $this->triggerCallback($this->preRender, $item, $form);
     $this->addMainContent($form);
     return parent::render();
 }