/** * Ensure the user has permissions to work with notifications in this component * and setup Fields and RowEditor objects. */ public function init() { $this->component->getPermissions()->haltIfNotAllowed('notifications'); $gateway = new NotificationGateway($this->component->getDb()); $this->fields = $gateway->buildFields($this->component->url('notification-edit'), $this->component->getFields()); $this->rowEditor = new RowEditor($this->fields, $this->request); $this->rowEditor->linkByQueryString('dewdrop_notification_subscriptions', 'dewdrop_notification_subscription_id'); $this->rowEditor->link(); }
/** * Get the \Dewdrop\Fields\RowEditor object that will assist with the * editing of items in this component. * * @return RowEditor */ public function getRowEditor() { if (!$this->rowEditor) { $fields = $this->getFields(); $this->rowEditor = new RowEditor($fields, $this->getRequest()); $this->rowEditor->linkByQueryString('users', 'user_id')->link(); if ($this->rowEditor->isNew()) { $this->addPasswordFields($fields); } } return $this->rowEditor; }
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')); }