/**
  * @return array
  */
 public function exec()
 {
     $this->_view = views_new_view();
     $this->_view->view_php = '';
     $this->_view->base_table = $this->_type;
     $this->_view->is_cacheable = FALSE;
     $this->_view->api_version = 2;
     $handler = $this->_view->new_display('default', 'Defaults', 'default');
     $this->_view->display['default']->handler->override_option('items_per_page', 0);
     $this->_view->display['default']->handler->override_option('relationships', $this->_relationships);
     $this->_view->display['default']->handler->override_option('fields', $this->_fields);
     $this->_view->display['default']->handler->override_option('sorts', $this->_sorts);
     $this->_view->display['default']->handler->override_option('filters', $this->_filters);
     $dummy = $this->_view->execute_display('default', array());
     $mapping = array();
     foreach ($this->_view->display_handler->handlers['field'] as $field_id => $fieldhandler) {
         $mapping[$fieldhandler->field_alias] = $field_id;
     }
     //    var_dump($mapping);
     //    var_dump($this->_view);
     //    var_dump($this->_view->result);
     //    var_dump($this->_outputMapping);
     //    exit;
     $output = array();
     foreach ($this->_view->result as $row) {
         $newRow = new stdClass();
         //      foreach ($this->_outputMapping as $viewFieldName => $outputFieldName) {
         foreach ($mapping as $viewFieldName => $outputFieldName) {
             $newRow->{$outputFieldName} = $row->{$viewFieldName};
         }
         if (isset($newRow->nid)) {
             $output[$newRow->nid] = $newRow;
             //        $output[$newRow->nid] = $row;
         } else {
             $output[] = $newRow;
             //        $output[] = $row;
         }
     }
     return $output;
 }
  protected function instantiate_view($form, &$form_state) {
    // Build the basic view properties.
    $view = views_new_view();
    $view->name = $form_state['values']['name'];
    $view->human_name = $form_state['values']['human_name'];
    $view->description = $form_state['values']['description'];
    $view->tag = 'default';
    $view->core = VERSION;
    $view->base_table = $this->base_table;

    // Build all display options for this view.
    $display_options = $this->build_display_options($form, $form_state);

    // Allow the fully built options to be altered. This happens before adding
    // the options to the view, so that once they are eventually added we will
    // be able to get all the overrides correct.
    $this->alter_display_options($display_options, $form, $form_state);

    $this->add_displays($view, $display_options, $form, $form_state);

    return $view;
  }
コード例 #3
0
 protected function instantiate_view($form, &$form_state)
 {
     $view = views_new_view();
     $view->name = $form_state['values']['name'];
     $view->human_name = $form_state['values']['human_name'];
     $view->description = $form_state['values']['description'];
     $view->tag = 'default';
     $view->core = VERSION;
     $view->base_table = $this->base_table;
     // Display: Master
     $default_display = $view->new_display('default', 'Master', 'default');
     $options = $this->default_display_options($form, $form_state);
     if (!isset($options['filters'])) {
         $options['filters'] = array();
     }
     $options['filters'] += $this->default_display_filters($form, $form_state);
     if (!isset($options['sorts'])) {
         $options['sorts'] = array();
     }
     $options['sorts'] += $this->default_display_sorts($form, $form_state);
     foreach ($options as $option => $value) {
         $default_display->set_option($option, $value);
     }
     // Display: Page
     if (!empty($form_state['values']['page']['create'])) {
         $display = $view->new_display('page', 'Page', 'page');
         $options = $this->page_display_options($form, $form_state);
         // The page display is usually the main one (from the user's point of
         // view). Its options should therefore become the overall view defaults,
         // so that new displays which are added later automatically inherit them.
         $this->set_default_options($options, $display, $default_display);
         // Display: Feed (attached to the page)
         if (!empty($form_state['values']['page']['feed'])) {
             $display = $view->new_display('feed', 'Feed', 'feed');
             $options = $this->page_feed_display_options($form, $form_state);
             $this->set_override_options($options, $display, $default_display);
         }
     }
     // Display: Block
     if (!empty($form_state['values']['block']['create'])) {
         $display = $view->new_display('block', 'Block', 'block');
         $options = $this->block_display_options($form, $form_state);
         // When there is no page, the block display options should become the
         // overall view defaults.
         if (empty($form_state['values']['page']['create'])) {
             $this->set_default_options($options, $display, $default_display);
         } else {
             $this->set_override_options($options, $display, $default_display);
         }
     }
     return $view;
 }