/** * test set categories */ public function testSetCategories() { $newdata = array(array('id' => 1, 'name' => 'cat 1', 'position' => 1), array('id' => 2, 'name' => 'category 2', 'position' => 0), array('id' => 0, 'name' => 'new cat', 'position' => 3)); // set new without delete an filled category $this->model->setCategories($newdata); $this->assertEquals($newdata[0], $this->model->find(1)->current()->toArray()); // update $this->assertEquals($newdata[1], $this->model->find(2)->current()->toArray()); // update $this->assertEquals(1, $this->model->fetchAll($this->model->select()->where('name=?', 'new cat'))->count()); $this->assertEquals(3, $this->model->fetchAll()->count()); // old deleted // set with delete filled category $newdata = array(array('id' => 0, 'name' => 'newcat', 'position' => 1)); $this->model->setCategories($newdata); $this->assertEquals(1, $this->model->fetchAll()->count()); $this->assertEquals(0, $this->model->feeds(1)); // no more feeds in cat 1 $this->assertEquals(2, $this->model->feeds(-1)); // now all feeds in cat -1 (uncategorized) }
/** * add new feed * * @return array|int id of new feed, or error messages * @param array $data the post data array */ public function add($data) { // validate data $input = $this->validate($data); if (is_array($input)) { return $input; } $categoryModel = new application_models_categories(); // save new feed $id = $this->insert(array_merge($input->getEscaped(), array('icon' => Zend_Controller_Action_HelperBroker::getStaticHelper('pluginloader')->getPlugin($input->getEscaped('source'))->icon, 'position' => $categoryModel->feeds($input->getEscaped('category')), 'multimedia' => Zend_Controller_Action_HelperBroker::getStaticHelper('pluginloader')->getPlugin($input->getEscaped('source'))->multimedia, 'htmlurl' => ''))); return $id; }