/** * Edit (or add) database page */ public function assignDatabasesAction() { $category_id = $this->request->requireParam('category', 'Request did not include category id'); $subcategory_id = $this->request->requireParam('subcategory', 'Request did not include subcategory id'); $databases = $this->request->getParam('database', null, true); $subcategory = $this->knowledgebase->getSubcategoryById($subcategory_id); foreach ($databases as $database) { $database_object = $this->knowledgebase->getDatabase($database); $sequence = new DatabaseSequence(); $sequence->setDatabase($database_object); $subcategory->addDatabaseSequence($sequence); } $this->knowledgebase->update($subcategory); $params = array('controller' => $this->request->getParam('controller'), 'action' => 'subject', 'id' => $category_id); return $this->redirectTo($params); }
/** * @param DatabaseSequence $sequence */ public function addDatabaseSequence(DatabaseSequence $sequence) { // check to make sure the database isn't already assigned foreach ($this->database_sequences as $database_sequence) { if ($database_sequence->getDatabase()->getId() == $sequence->getDatabase()->getId()) { return null; // don't add it } } $sequence->setSubcategory($this); $sequence->setOwner($this->owner); $this->database_sequences[] = $sequence; }