Ejemplo n.º 1
0
 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) {
         //print_r($_POST);
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         if ($post->action == 'a') {
             // Add some rules, the input field, followed by a list of checks, carried out in order
             $post->add_rules('feed_name', 'required', 'length[3,70]');
             $post->add_rules('feed_url', 'required', 'url');
         }
         if ($post->validate()) {
             $feed_id = $post->feed_id;
             $feed = new Feed_Model($feed_id);
             if ($post->action == 'd') {
                 // Delete Action
                 if ($feed->loaded == true) {
                     ORM::factory('feed_item')->where('feed_id', $feed_id)->delete_all();
                 }
                 $feed->delete($feed_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'v') {
                     // Active/Inactive Action
                     if ($feed->loaded == true) {
                         if ($feed->feed_active == 1) {
                             $feed->feed_active = 0;
                         } else {
                             $feed->feed_active = 1;
                         }
                         $feed->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     if ($post->action == 'r') {
                         $this->_parse_feed();
                     } else {
                         // Save Action
                         // SAVE Feed
                         $feed->feed_name = $post->feed_name;
                         $feed->feed_url = $post->feed_url;
                         $feed->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('feeds'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('feed')->count_all()));
     $feeds = ORM::factory('feed')->orderby('feed_name', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $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');
 }