示例#1
0
 public function testSavingWillTraverseLinkedFieldsToHookRowsTogether()
 {
     $db = Pimple::getResource('db');
     $db->query('DELETE FROM dewdrop_test_fruits');
     $animalModel = new RowEditorAnimalModel();
     $this->fields->add($animalModel->field('name'));
     $this->fields->add($animalModel->field('is_fierce'));
     $this->fields->add($animalModel->field('is_cute'));
     $this->rowEditor->linkByQueryString('dewdrop_test_animals', 'dewdrop_test_animal_id');
     $this->rowEditor->linkByField('dewdrop_test_fruits', $animalModel->field('favorite_fruit_id'));
     $this->rowEditor->link();
     $this->assertTrue($this->rowEditor->isValid(array('dewdrop_test_fruits:name' => 'Banana', 'dewdrop_test_fruits:level_of_deliciousness' => 8, 'dewdrop_test_animals:name' => 'Gorilla', 'dewdrop_test_animals:is_fierce' => 1, 'dewdrop_test_animals:is_cute' => 1)));
     $this->rowEditor->save();
     $this->assertEquals($db->fetchOne('SELECT MAX(dewdrop_test_fruit_id) FROM dewdrop_test_fruits'), $db->fetchOne('SELECT favorite_fruit_id FROM dewdrop_test_animals ORDER BY dewdrop_test_animal_id DESC LIMIT 1'));
 }
示例#2
0
 /**
  * On a POST request, validate the user's input.  If valid, save using the
  * RowEditor, set a success message and then redirect.  Should also behave
  * reasonably well when used as an endpoint for an XHR by returning a success
  * message and the new primary key value.
  *
  * @param ResponseHelper $responseHelper
  */
 public function process(ResponseHelper $responseHelper)
 {
     if ($this->request->isPost()) {
         $this->invalidSubmission = !$this->rowEditor->isValid($this->request->getPost());
         if (!$this->invalidSubmission) {
             $title = strtolower($this->model->getSingularTitle());
             if (!$this->request->isAjax()) {
                 if ($this->isNew) {
                     $responseHelper->setSuccessMessage("Successfully saved new {$title}.");
                 } else {
                     $responseHelper->setSuccessMessage("Successfully saved changes to {$title}.");
                 }
             }
             $this->rowEditor->save();
             if (!$this->request->isAjax()) {
                 $this->redirect($responseHelper);
             }
         }
     }
 }