• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/user/views_plugin_argument_default_user.inc

Go to the documentation of this file.
00001 <?php
00010 class views_plugin_argument_default_user extends views_plugin_argument_default {
00011   function option_definition() {
00012     $options = parent::option_definition();
00013     $options['user'] = array('default' => '', 'bool' => TRUE, 'translatable' => FALSE);
00014 
00015     return $options;
00016   }
00017 
00018   function options_form(&$form, &$form_state) {
00019     $form['user'] = array(
00020       '#type' => 'checkbox',
00021       '#title' => t('Also look for a node and use the node author'),
00022       '#default_value' => $this->options['user'],
00023     );
00024   }
00025 
00026   function convert_options(&$options) {
00027     if (!isset($options['user']) && isset($this->argument->options['default_argument_user'])) {
00028       $options['user'] = $this->argument->options['default_argument_user'];
00029     }
00030   }
00031 
00032   function get_argument() {
00033     foreach (range(1, 3) as $i) {
00034       $user = menu_get_object('user', $i);
00035       if (!empty($user)) {
00036         return $user->uid;
00037       }
00038     }
00039 
00040     foreach (range(1, 3) as $i) {
00041       $user = menu_get_object('user_uid_optional', $i);
00042       if (!empty($user)) {
00043         return $user->uid;
00044       }
00045     }
00046 
00047     if (!empty($this->options['user'])) {
00048       foreach (range(1, 3) as $i) {
00049         $node = menu_get_object('node', $i);
00050         if (!empty($node)) {
00051           return $node->uid;
00052         }
00053       }
00054     }
00055 
00056     if (arg(0) == 'user' && is_numeric(arg(1))) {
00057       return arg(1);
00058     }
00059 
00060     if (!empty($this->options['user'])) {
00061       if (arg(0) == 'node' && is_numeric(arg(1))) {
00062         $node = node_load(arg(1));
00063         if ($node) {
00064           return $node->uid;
00065         }
00066       }
00067     }
00068 
00069     // If the current page is a view that takes uid as an argument, return the uid.
00070     $view = views_get_page_view();
00071 
00072     if ($view && isset($view->argument['uid'])) {
00073       return $view->argument['uid']->argument;
00074     }
00075   }
00076 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1