Example #1
0
 /**
  * Tests Feed_Model::is_valid_feed
  * @test
  */
 public function testIsValidFeed()
 {
     if (ORM::factory('feed')->count_all() == 0) {
         $this->markTestSkipped('There are no records in the feeds table');
     }
     // Test with a valid feed id
     $random_feed_id = testutils::get_random_id('feed');
     $this->assertEquals(TRUE, Feed_Model::is_valid_feed($random_feed_id));
     // Test with an invalid feed id
     $this->assertEquals(FALSE, Feed_Model::is_valid_feed('90.9999'));
 }
Example #2
0
 /**
  * Add Edit News Feeds
  */
 public function feeds()
 {
     $this->template->content = new View('admin/feeds');
     // setup and initialize form field names
     $form = array('action' => '', 'feed_id' => '', 'feed_name' => '', 'feed_url' => '', 'feed_active' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         // Feed_Model instance
         $feed = (isset($_POST['feed_id']) and Feed_Model::is_valid_feed($_POST['feed_id'])) ? new Feed_Model($_POST['feed_id']) : new Feed_Model();
         if ($_POST['action'] == 'a') {
             // Manually extract the data to be validated
             $data = arr::extract($_POST, 'feed_name', 'feed_url');
             // Test validation
             if ($feed->validate($data)) {
                 $feed->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
             } else {
                 // Repopulate the form fields
                 $form = arr::overwrite($form, $data->as_array());
                 // Populate the error fields, if any
                 $errors = arr::overwrite($errors, $data->errors('feeds'));
                 $form_error = TRUE;
             }
         } elseif ($_POST['action'] == 'd') {
             // Delete Action
             if ($feed->loaded == TRUE) {
                 ORM::factory('feed_item')->where('feed_id', $feed->id)->delete_all();
                 $feed->delete();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
         } elseif ($_POST['action'] == 'v') {
             // Active/Inactive Action
             if ($feed->loaded == TRUE) {
                 $feed->feed_active = $feed->feed_active == 1 ? 0 : 1;
                 $feed->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             }
         } elseif ($_POST['action'] == 'r') {
             $this->_parse_feed();
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('feed')->count_all()));
     $feeds = ORM::factory('feed')->orderby('feed_name', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->feeds = $feeds;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->js = new View('admin/feeds_js');
 }