1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Turba_View_Duplicates
15: {
16: 17: 18: 19: 20:
21: protected $_duplicates;
22:
23: 24: 25: 26: 27:
28: protected $_type;
29:
30: 31: 32: 33: 34:
35: protected $_duplicate;
36:
37: 38: 39: 40: 41:
42: protected $_driver;
43:
44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
57: public function __construct(array $duplicates, Turba_Driver $driver,
58: $type = null, $duplicate = null)
59: {
60: $this->_duplicates = $duplicates;
61: $this->_driver = $driver;
62: $this->_type = $type;
63: $this->_duplicate = $duplicate;
64: }
65:
66: 67: 68:
69: public function display()
70: {
71: $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search/duplicate'));
72: new Horde_View_Helper_Text($view);
73:
74: $hasDuplicate = $this->_type && $this->_duplicate &&
75: isset($this->_duplicates[$this->_type]) &&
76: isset($this->_duplicates[$this->_type][$this->_duplicate]);
77: if ($hasDuplicate) {
78: $vars = new Horde_Variables();
79: $view->type = $GLOBALS['attributes'][$this->_type]['label'];
80: $view->value = $this->_duplicate;
81: echo $view->render('header');
82:
83: $view->contactUrl = Horde::url('contact.php');
84: $view->mergeUrl = Horde::url('merge.php');
85: $view->first = true;
86: $duplicate = $this->_duplicates[$this->_type][$this->_duplicate];
87: while ($contact = $duplicate->next()) {
88: $contact->lastModification();
89: }
90: $duplicate->sort(array(array('field' => '__modified', 'ascending' => false)));
91: $view->mergeTarget = $duplicate->reset()->getValue('__key');
92: while ($contact = $duplicate->next()) {
93: $view->source = $contact->getSource();
94: $view->id = $contact->getValue('__key');
95: $history = $contact->getHistory();
96: if (isset($history['modified'])) {
97: $view->changed = $history['modified'];
98: } elseif (isset($history['created'])) {
99: $view->changed = $history['created'];
100: } else {
101: unset($view->changed);
102: }
103: echo $view->render('contact_header');
104: $contactView = new Turba_Form_Contact($vars, $contact, false);
105: $contactView->renderInactive(new Horde_Form_Renderer(), $vars);
106: echo $view->render('contact_footer');
107: $view->first = false;
108: }
109:
110: echo $view->render('footer');
111: }
112:
113: $view->duplicates = $this->_duplicates;
114: $view->hasDuplicate = (bool)$hasDuplicate;
115: $view->attributes = $GLOBALS['attributes'];
116: $view->link = Horde::url('search.php')
117: ->add(array('source' => $this->_driver->getName(),
118: 'search_mode' => 'duplicate'));
119:
120: echo $view->render('list');
121: }
122: }
123: