/** * test configuration */ public function testConfiguration() { $this->assertEquals($this->db, $this->model->getAdapter()); $this->assertEquals(array(1 => 'id'), $this->model->info('primary')); $this->assertEquals(Zend_Registry::get('config')->resources->db->prefix . 'categories', $this->model->info('name')); $this->assertEquals(Zend_Registry::get('config')->resources->db->params->dbname, $this->model->info('schema')); $this->assertEquals(array('application_models_feeds'), $this->model->getDependentTables()); }
/** * check whether a category exists and returns the id * else insert new category * * @return int category id * @param string $category the category name */ protected function insertCategory($category) { // no category handling for uncategorized if ($category == -1) { return -1; } // search existing category $categoriesModel = new application_models_categories(); $categories = $categoriesModel->fetchAll($categoriesModel->select()->where($categoriesModel->getAdapter()->quoteInto('name=?', trim($category)))); // use existing category if ($categories->count() > 0) { return $categories->current()->id; } else { return $categoriesModel->insert(array('name' => trim($category), 'position' => $categoriesModel->maxPosition() + 1)); } }