1: <?php
2: 3: 4:
5: class Whups_Form_Query_DateCriterion extends Horde_Form
6: {
7: public function __construct(&$vars)
8: {
9: parent::__construct(
10: $vars,
11: $vars->get('edit') ? _("Edit Date Criterion") : _("Add Date Criterion"),
12: 'Whups_Form_Query_DateCriterion');
13:
14: $this->addHidden('', 'edit', 'boolean', false);
15:
16: $this->addVariable(
17: _("Created from"), 'ticket_timestamp[from]', 'monthdayyear', false,
18: false, null, array(date('Y') - 10));
19: $this->addVariable(
20: _("Created to"), 'ticket_timestamp[to]', 'monthdayyear', false,
21: false, null, array(date('Y') - 10));
22:
23: $this->addVariable(
24: _("Updated from"), 'date_updated[from]', 'monthdayyear', false,
25: false, null, array(date('Y') - 10));
26: $this->addVariable(
27: _("Updated to"), 'date_updated[to]', 'monthdayyear', false, false,
28: null, array(date('Y') - 10));
29:
30: $this->addVariable(
31: _("Resolved from"), 'date_resolved[from]', 'monthdayyear', false,
32: false, null, array(date('Y') - 10));
33: $this->addVariable(
34: _("Resolved to"), 'date_resolved[to]', 'monthdayyear', false, false,
35: null, array(date('Y') - 10));
36:
37: $this->addVariable(
38: _("Assigned from"), 'date_assigned[from]', 'monthdayyear', false,
39: false, null, array(date('Y') - 10));
40: $this->addVariable(
41: _("Assigned to"), 'date_assigned[to]', 'monthdayyear', false,
42: false, null, array(date('Y') - 10));
43:
44: $this->addVariable(
45: _("Due from"), 'ticket_due[from]', 'monthdayyear', false, false,
46: null, array(date('Y') - 10));
47: $this->addVariable(
48: _("Due to"), 'ticket_due[to]', 'monthdayyear', false, false, null,
49: array(date('Y') - 10));
50: }
51:
52: public function execute(&$vars)
53: {
54: $path = $vars->get('path');
55: $parent = false;
56:
57: $keys = array(
58: Whups_Query::CRITERION_TIMESTAMP => 'ticket_timestamp',
59: Whups_Query::CRITERION_UPDATED => 'date_updated',
60: Whups_Query::CRITERION_RESOLVED => 'date_resolved',
61: Whups_Query::CRITERION_ASSIGNED => 'date_assigned',
62: Whups_Query::CRITERION_DUE => 'ticket_due');
63:
64: foreach ($keys as $key_id => $key_name) {
65: $date = $vars->get($key_name . '[from]');
66: if (!empty($date['month'])) {
67: if (!$parent) {
68: $path = $GLOBALS['whups_query']->insertBranch(
69: $path, Whups_Query::TYPE_AND);
70: $parent = true;
71: }
72: $date = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
73: $GLOBALS['whups_query']->insertCriterion(
74: $path, $key_id, null, Whups_Query::OPERATOR_GREATER, $date);
75: }
76: $date = $vars->get($key_name . '[to]');
77: if (!empty($date['month'])) {
78: if (!$parent) {
79: $path = $GLOBALS['whups_query']->insertBranch(
80: $path, Whups_Query::TYPE_AND);
81: $parent = true;
82: }
83: $date = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
84: $GLOBALS['whups_query']->insertCriterion(
85: $path, $key_id, null, Whups_Query::OPERATOR_LESS, $date);
86: }
87: }
88:
89: $this->unsetVars($vars);
90: }
91:
92: }