/**
  * test the fix position routine
  * setUp will insert feeds with position 0 and 2
  * fixPosition corrects to 0 and 1
  */
 public function testFixPositions()
 {
     $this->model->fixPositions($this->model->find(1)->current());
     $feedModel = new application_models_feeds();
     $positions = $feedModel->fetchAll($feedModel->select()->order('position ASC')->from($feedModel, 'position'))->toArray();
     $expected = array(array('position' => 0), array('position' => 1));
     $this->assertEquals($expected, $positions);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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());
 }