Completed
Push — 7.x-3.x ( d8666b...d48267 )
by Devin
03:54
created

commons_follow_handler_field_ops   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 0 47 7
1
<?php
2
3
/**
4
 * @file
5
 * Contains the flag Ops field handler.
6
 */
7
8
/**
9
 * Views field handler for the Flag operations links (flag/unflag).
10
 *
11
 * @ingroup views
12
 */
13
class commons_follow_handler_field_ops extends flag_handler_field_ops {
14
15
  function render($values) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
    global $user;
17
    //If the passed in user doesn't match the current user
18
    if(isset($this->view->args[0]) && $user->uid != $this->view->args[0]) {
19
20
      if (!($flag = $this->get_flag())) {
21
        // get_flag() itself will print a more detailed message.
22
        return t('Missing flag');
23
      }
24
      $content_id = $values->{$this->aliases['content_id']};
25
      $is_flagged = $values->{$this->aliases['is_flagged']};
26
27
      if (empty($this->flag_applies[$content_id])) {
28
        // Flag does not apply to this content.
29
        return;
30
      }
31
32
      if (!empty($this->options['link_type'])) {
33
        $flag->link_type = $this->options['link_type'];
34
      }
35
36
      $variables = array();
37
      $action = $is_flagged ? 'unflag' : 'flag';
38
      $variables['flag_css_name'] = str_replace('_', '-', $flag->name);
39
40
      $flag_wrapper_classes_array = array();
41
      $flag_wrapper_classes_array[] = 'flag-wrapper';
42
      $flag_wrapper_classes_array[] = 'flag-' . $variables['flag_css_name'];
43
      $flag_wrapper_classes_array[] = 'flag-' . $variables['flag_css_name'] . '-' . $content_id;
44
      $variables['flag_wrapper_classes'] = implode(' ',$flag_wrapper_classes_array);
45
46
      $flag_classes_array = array();
47
      $flag_classes_array[] = 'flag';
48
      $flag_classes_array[] = $action . '-action';
49
      $flag_classes_array[] = 'flag-link-' . $flag->link_type;
50
      $variables['flag_classes'] = implode(' ', $flag_classes_array);
51
      $variables['is_flagged'] = $action;
52
      $variables['link_text'] = $flag->get_label($action . '_short', $content_id);
53
54
      return theme('commons_follow_otheruser_flag', $variables);
55
    }
56
    else {
57
      return parent::render($values);
58
    }
59
60
//    return $flag->theme($is_flagged ? 'unflag' : 'flag', $content_id);
61
  }
62
}
63