public function update() { // Load the $action for editing if (isset($_REQUEST['action_id']) && $_REQUEST['action_id']) { try { $action = new Action($_REQUEST['action_id']); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; header('Location: ' . BASE_URL . '/actions'); exit; } } else { $action = new Action(); } if (isset($_POST['name'])) { $action->handleUpdate($_POST); try { $action->save(); header('Location: ' . BASE_URL . '/actions'); exit; } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } $this->template->blocks[] = new Block('actions/updateActionForm.inc', array('action' => $action)); }
public function testSaveAndLoad() { $action = new Action(); $action->setName('Test'); $action->setDescription('Description'); $action->save(); $id = $action->getId(); $this->assertNotEmpty($id); $action = new Action($id); $this->assertEquals('Test', $action->getName()); $this->assertEquals('Description', $action->getDescription()); }
public function testSaveActions() { $test = new Action('test'); $attempt = new Action('attempt'); $department = new Department($this->unusedDepartment); $department->saveActions([$test->getId(), $attempt->getId()]); $department = new Department($this->unusedDepartment); $actions = $department->getActions(); $this->assertEquals(2, count($actions)); $this->assertTrue(in_array($test->getId(), array_keys($actions))); $this->assertTrue(in_array($attempt->getId(), array_keys($actions))); $department->saveActions([]); $department = new Department($this->unusedDepartment); $actions = $department->getActions(); $this->assertEquals(0, count($actions)); }
/** * @param Action $action * @return bool */ public function hasAction(Action $action) { return in_array($action->getId(), array_keys($this->getActions())); }