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:  * Base class for forms dealing with a contact.
  4:  *
  5:  * @package Turba
  6:  */
  7: abstract class Turba_Form_ContactBase extends Horde_Form
  8: {
  9:     /**
 10:      * Set up the Horde_Form fields for $contact's attributes.
 11:      *
 12:      * @param Turba_Object $contact  The contact
 13:      */
 14:     protected function _addFields(Turba_Object $contact, $useTabs = true)
 15:     {
 16:         // @TODO: inject this
 17:         global $attributes;
 18: 
 19:         // Run through once to see what form actions, if any, we need
 20:         // to set up.
 21:         $actions = array();
 22:         $map = $contact->driver->map;
 23:         $fields = array_keys($contact->driver->getCriteria());
 24:         foreach ($fields as $field) {
 25:             if (is_array($map[$field])) {
 26:                 foreach ($map[$field]['fields'] as $action_field) {
 27:                     if (!isset($actions[$action_field])) {
 28:                         $actions[$action_field] = array();
 29:                     }
 30:                     $actions[$action_field]['fields'] = $map[$field]['fields'];
 31:                     $actions[$action_field]['format'] = $map[$field]['format'];
 32:                     $actions[$action_field]['target'] = $field;
 33:                 }
 34:             }
 35:         }
 36: 
 37:         // Now run through and add the form variables.
 38:         $tabs = $contact->driver->tabs;
 39:         if (!count($tabs)) {
 40:             $tabs = array('' => $fields);
 41:         }
 42:         $i = 0;
 43:         foreach ($tabs as $tab => $tab_fields) {
 44:             if (!empty($tab)) {
 45:                 if ($useTabs) {
 46:                     $this->setSection($i++, $tab);
 47:                 } else {
 48:                     $this->addVariable($tab, '', 'header', false);
 49:                 }
 50:             }
 51:             foreach ($tab_fields as $field) {
 52:                 if (!in_array($field, $fields) ||
 53:                     !isset($attributes[$field])) {
 54:                     continue;
 55:                 }
 56: 
 57:                 $attribute = $attributes[$field];
 58:                 $params = isset($attribute['params']) ? $attribute['params'] : array();
 59:                 $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
 60: 
 61:                 if (is_array($map[$field])) {
 62:                     $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params);
 63:                     $v->disable();
 64:                 } else {
 65:                     $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null;
 66:                     $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params);
 67: 
 68:                     if (!empty($actions[$field])) {
 69:                         $actionfields = array();
 70:                         foreach ($actions[$field]['fields'] as $f) {
 71:                             $actionfields[] = $this->_getId('object[' . $f . ']');
 72:                         }
 73:                         $a = Horde_Form_Action::factory('updatefield',
 74:                                                         array('format' => $actions[$field]['format'],
 75:                                                               'target' => $this->_getId('object[' . $actions[$field]['target'] . ']'),
 76:                                                               'fields' => $actionfields));
 77:                         $v->setAction($a);
 78:                     }
 79:                 }
 80: 
 81:                 if (isset($attribute['default'])) {
 82:                     $v->setDefault($attribute['default']);
 83:                 }
 84:             }
 85:         }
 86:     }
 87: 
 88:     /**
 89:      * Converts a field name into an element ID as used in Horde_Form.
 90:      *
 91:      * @param string $id  A form field name.
 92:      *
 93:      * @return string  The ID for the form field.
 94:      */
 95:     protected function _getId($id)
 96:     {
 97:         return preg_replace('/[^A-Za-z0-9-_:.]+/', '_', $id);
 98:     }
 99: }
100: 
API documentation generated by ApiGen