Overview

Packages

  • Horde
    • Data
  • None
  • Turba

Classes

  • Turba
  • Turba_Api
  • Turba_Driver
  • Turba_Driver_Facebook
  • Turba_Driver_Favourites
  • Turba_Driver_Group
  • Turba_Driver_Imsp
  • Turba_Driver_Kolab
  • Turba_Driver_Ldap
  • Turba_Driver_Prefs
  • Turba_Driver_Share
  • Turba_Driver_Sql
  • Turba_Driver_Vbook
  • Turba_Exception
  • Turba_Factory_Driver
  • Turba_Form_AddContact
  • Turba_Form_Contact
  • Turba_Form_ContactBase
  • Turba_Form_CreateAddressBook
  • Turba_Form_DeleteAddressBook
  • Turba_Form_EditAddressBook
  • Turba_Form_EditContact
  • Turba_Form_EditContactGroup
  • Turba_List
  • Turba_LoginTasks_SystemTask_Upgrade
  • Turba_Object
  • Turba_Object_Group
  • Turba_Test
  • Turba_View_Browse
  • Turba_View_Contact
  • Turba_View_DeleteContact
  • Turba_View_Duplicates
  • Turba_View_EditContact
  • Turba_View_List
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Turba_View_Duplicates class provides an interface for displaying and
  4:  * resolving duplicate contacts.
  5:  *
  6:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file LICENSE for license information (ASL).  If you
  9:  * did not receive this file, see http://www.horde.org/licenses/apache.
 10:  *
 11:  * @author  Jan Schneider <jan@horde.org>
 12:  * @package Turba
 13:  */
 14: class Turba_View_Duplicates
 15: {
 16:     /**
 17:      * Hash of Turba_List objects.
 18:      *
 19:      * @var array
 20:      */
 21:     protected $_duplicates;
 22: 
 23:     /**
 24:      * A field name.
 25:      *
 26:      * @var string
 27:      */
 28:     protected $_type;
 29: 
 30:     /**
 31:      * A duplicate value.
 32:      *
 33:      * @var string
 34:      */
 35:     protected $_duplicate;
 36: 
 37:     /**
 38:      * A Turba_Driver instance.
 39:      *
 40:      * @var Turba_Driver
 41:      */
 42:     protected $_driver;
 43: 
 44:     /**
 45:      * Constructor.
 46:      *
 47:      * If the $type and $duplicate parameters are specified, they are used to
 48:      * lookup a single Turba_List from $duplicates with a list of duplicate
 49:      * contacts. The resolution interface for those duplicates is rendered
 50:      * above the overview tables then.
 51:      *
 52:      * @param array $duplicates     Hash of Turba_List objects.
 53:      * @param Turba_Driver $driver  A Turba_Driver instance.
 54:      * @param string $type          A field name.
 55:      * @param string $duplicate     A duplicate value.
 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:      * Renders this view.
 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: 
API documentation generated by ApiGen