/** * 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(); }
/** * Setup the row editor and check component permissions. */ public function init() { $this->rowEditor = $this->getRowEditor(); $this->model = $this->getModel(); $this->fields = $this->getFields(); // Ensure primary key field is instantiated so that it is linked by row editor $this->component->getFields()->add($this->component->getListing()->getPrimaryKey())->setEditable(false); $this->rowEditor->link(); $this->isNew = $this->rowEditor->isNew(); $this->checkPermissions(); }
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')); }