/**
  * test automatic generation of uncategorized cat
  * setUp will not insert the uncategrized cat
  */
 public function testCheckUncategorized()
 {
     $this->assertEquals(0, $this->model->find(-1)->count());
     $this->model->checkUncategorized();
     $this->assertEquals(1, $this->model->find(-1)->count());
     $this->model->checkUncategorized();
     $this->assertEquals(1, $this->model->find(-1)->count());
     // dont add it twice
 }
 /**
  * test max position
  * feeds has wrong positions by setUp
  */
 public function testSort()
 {
     $categoryModel = new application_models_categories();
     $this->model->sort($categoryModel->find('2')->current(), array('2', '1'));
     $this->assertEquals(1, $this->model->find('1')->count());
     $this->assertEquals(1, $this->model->find('2')->count());
     $this->assertEquals(1, $this->model->find('3')->count());
     $this->assertEquals('0', $this->model->find('2')->current()->position);
     // correct position
     $this->assertEquals('2', $this->model->find('2')->current()->category);
     // corrent category
     $this->assertEquals('1', $this->model->find('1')->current()->position);
     // correct position
     $this->assertEquals('2', $this->model->find('1')->current()->category);
     // corrent category
     $this->assertEquals('0', $this->model->find('3')->current()->position);
     // correct position
     $this->assertEquals('1', $this->model->find('3')->current()->category);
     // corrent category
 }
 /**
  * save new order of feeds (sortable)
  *
  * @return void
  */
 public function sortAction()
 {
     // get new category
     $category = $this->getRequest()->getParam('cat');
     if (strlen($category) > 4) {
         $category = substr($category, 4);
     }
     // load category
     $categoriesModel = new application_models_categories();
     $category = $categoriesModel->find($category);
     // no category found: abort
     if ($category->count() == 0) {
         return;
     }
     // get feeds in new order
     $feeds = $this->getRequest()->getParam('feed');
     // save new order
     $feedsModel = new application_models_feeds();
     $categories = $feedsModel->sort($category->current(), $feeds);
     // send new unread items
     $unread = Zend_Controller_Action_HelperBroker::getStaticHelper('itemcounter')->unreadItemsCategories();
     $this->_helper->json($unread);
 }
 /**
  * removes a feed
  *
  * @return array|bool true or error messages
  * @param int id of the feed
  */
 public function remove($id)
 {
     // get feed and category
     $feed = $this->find($id);
     if ($feed->count() == 0) {
         return Zend_Registry::get('language')->translate("feed doesn't exists");
     }
     $feed = $feed->current();
     $category = $feed->category;
     // delete all items
     $itemsModel = new application_models_items();
     $itemsModel->delete('feed=' . $feed->id);
     // delete icon
     $this->deleteIcon($feed);
     // delete messages
     $messagesModel = new application_models_messages();
     $messagesModel->delete('feed=' . $feed->id);
     // delete feed
     $this->delete('id=' . $feed->id);
     // reorder feeds in parent category
     if ($category != 0) {
         $categoryModel = new application_models_categories();
         $categoryModel->fixPositions($categoryModel->find($category)->current());
     }
     // success
     return true;
 }
 /**
  * insert given feeds
  * 
  * @return void
  * @param int $category id
  * @param array $feeds as array
  */
 protected function insertFeeds($category, $feeds)
 {
     $feedsModel = new application_models_feeds();
     // insert unkown feeds
     foreach ($feeds as $feed) {
         // search existing feed
         $moreFeeds = $feedsModel->fetchAll($feedsModel->select()->where($feedsModel->getAdapter()->quoteInto('url=?', trim($feed['link']))));
         // if feed doesn't exists
         if ($moreFeeds->count() == 0) {
             $feedsModel->add(array('name' => trim($feed['title']), 'url' => trim($feed['link']), 'category' => $category, 'priority' => 1, 'source' => 'plugins_rss_feed'));
         }
     }
     // fix positions
     $categoriesModel = new application_models_categories();
     $categoriesModel->fixPositions($categoriesModel->find($category)->current());
 }