aboutsummaryrefslogtreecommitdiff
path: root/muamba.handlers.inc
blob: 21db85073e02b727d5f7f2164f69a434455aa06a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

/**
 * @file
 * Contains the muamba transaction status views field handler.
 */

/**
 * Field handler for muamba transaction status.
 */
class views_handler_field_muamba_status extends views_handler_field {
  /**
   * Renders the field.
   */
  function render($values) {
    if (isset($values->muamba_status)) {
      return muamba_statuses($values->muamba_status);
    }
  }
}

/**
 * Filter by transaction status
 */
class views_handler_filter_muamba_status extends views_handler_filter_in_operator {
  function get_value_options() {
    if (!isset($this->value_options)) {
      $this->value_title   = t('Transaction status');
      $this->value_options = muamba_statuses();
    }
  }
}

/**
 * Field handler for muamba transaction status.
 */
class views_handler_field_muamba_available extends views_handler_field {
  /**
   * Implements views_handler_field#query().
   *
   * @see views_php_views_pre_execute()
   */
  function query() {
    // Provide an field alias but don't actually alter the query.
    $this->field_alias = 'views_muamba_available_' . $this->position;
  }

  /**
   * Renders the field.
   */
  function render($values) {
    if (!isset($values->nid)) {
      return;
    }

    global $user;
    $available = muamba_check_availability($values->nid);

    if ($values->users_node_uid == $user->uid) {
      return t('You own the item');
    }
    elseif (!$available) {
      $transaction = muamba_current_transactions($values->nid, $user->uid);

      if (isset($transaction['uid']) && $transaction['uid'] == $user->uid) {
        return t('You requested');
      }
      else {
        return t('No');
      }
    }

    return t('Yes');
  }
}

/**
 * Field handler for muamba transaction status.
 */
class views_handler_field_muamba_actions extends views_handler_field {
  /**
   * Implements views_handler_field#query().
   *
   * @see views_php_views_pre_execute()
   */
  function query() {
    // Provide an field alias but don't actually alter the query.
    $this->field_alias = 'views_muamba_actions_' . $this->position;
  }

  /**
   * Renders the field.
   */
  function render($values) {
    global $user;

    if (isset($values->mid)) {
      $transaction = muamba_get_transaction($values->mid);

      if ($transaction['owner'] == $user->uid) {
        return theme('muamba_widget_owner', array('transaction' => $transaction));
      }
      elseif ($transaction['uid'] == $user->uid) {
        return theme('muamba_widget_requester', array('transaction' => $transaction));
      }
    }
    elseif (isset($values->nid)) {
      $node = node_load($values->nid);
      return muamba_widget($node);
    }
  }
}