/[drupal]/contributions/modules/civinode/contrib/civicrmdata/civicrmdata.module
ViewVC logotype

Diff of /contributions/modules/civinode/contrib/civicrmdata/civicrmdata.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.8.2.2, Thu Jun 21 05:00:34 2007 UTC revision 1.8.2.3, Mon Sep 17 22:42:44 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: civicrmdata.module,v 1.11 2007/06/21 04:40:59 torenware Exp $  // $Id: civicrmdata.module,v 1.4 2006/05/24 15:19:36 mfredrickson Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 12  Line 12 
12  function civicrmdata_help($section) {  function civicrmdata_help($section) {
13    switch ($section) {    switch ($section) {
14      case 'admin/modules#description':      case 'admin/modules#description':
15        return t('Old, deprecated module that defines field types for referencing CiviCRM data from a node. You should be using CiviNode CCK instead! <em>Note: Requires content.module, civicrm.module.</em>');        return t('Defines field types for referencing CiviCRM data from a node. <em>Note: Requires content.module, civicrm.module.</em>');
16    }    }
17  }  }
18    
# Line 28  function civicrmdata_field_formatter_inf Line 28  function civicrmdata_field_formatter_inf
28    
29    //make the default view for all of them    //make the default view for all of them
30    return array(    return array(
31      'civiformat' => array(      'default' => array(
32        'label' => 'CiviField',        'label' => t('Default (title)'),
33        'field types' => $types,        'field types' => $types,
34      ),      ),
35    
36        'profiled' => array(
37          'label' => t('Using Profile'),
38          'field_types' => array('civicrmdata_contact'),
39        ),
40    );    );
41  }  }
42    
43    
44    function civicrmdata_field_formatter($field, $item, $formatter) {
45       switch ($formatter) {
46        case 'profiled':
47          if ($field['type'] == 'civicrmdata_contact')
48            return theme('civinode_cck_profiled_contact', $item);
49          break;
50        case 'default':
51          if ($field['type'] == 'civicrmdata__contact')
52            return theme('civinode_cck_formatter_contact', $item);
53          else if ($field['type'] == 'civicrmdata_group')
54            return theme('civinode_cck_formatter_group', $item);
55          else
56            return theme('civinode_cck_formatter_default', $item);
57          break;
58      }
59    }
60    
61    
62  /**  /**
63   * Implementation of hook_field_info().   * Implementation of hook_field_info().
64   */   */
# Line 381  function civicrmdata_handle_ac_contacts( Line 404  function civicrmdata_handle_ac_contacts(
404    
405  }  }
406    
407    /**
408     * Options fields
409     *
410     */
411    
412    function civicrmdata_contact_field_options() {
413    
414      $field_options =
415        array(
416          'display_name' => t('Display Name'),
417          'sort_name' => t('Sort Name'),
418          'last_name' => t('Last Name'),
419          'first_name' => t('First Name'),
420          'street_address' => t('Street Address'),
421          'city' => t('City'),
422          'postal_code' => t('Zip/Postal Code'),
423          'other' => t('Other (Enter Below)')
424        );
425      $form =
426        array(
427          'main_option' =>
428            array(
429                '#type' => 'select',
430                '#options' => $field_options,
431            ),
432            'other_option' =>
433            array(
434                 '#type' => 'textfield',
435                 '#size' => 20,
436            ),
437            '#type' => 'civicrmdata_option',
438            '#process' => 'civicrmdata_option_process',
439            '#after_build' => 'civicrmdata_option_builder'
440    
441        );
442    
443        return $form;
444    }
445    
446    
447    /**
448    * The #process takes the serialized #default_value and feeds
449    * the forms beneath it.
450    */
451    function civicrmdata_option_process($element) {
452      $values = unserialize($element['#default_value']);
453      if (!is_array($values)) {
454        // set default values for options that have no stored value.
455        $values = array('main_option' => 'display_name', 'other_option' => '');
456      }
457      $element['main_option']['#default_value'] = $values['main_option'];
458      $element['other_option']['#default_value'] = $values['other_option'];
459      return $element;
460    }
461    
462    /**
463    * Put the value back.
464    */
465    function civicrmdata_option_builder($element) {
466      $values = array();
467      $values['main_option'] = $element['main_option']['#value'];
468      if ($values['main_option'] != 'other')
469        $other = '';
470      else
471        $other = $element['other_option']['#value'];
472      $values['other_option'] = $other;
473      $element['#value'] = serialize($values);
474      form_set_value($element, $element['#value']);
475      return $element;
476    }
477    
478    /**
479    * this forces the #value to not be printed as it would be if we put in
480    * no #type.
481    */
482    function theme_civicrmdata_option($element) {
483      return $element['#children'];
484    }
485    
486    /**
487     * callback functions for the theme
488     */
489    
490    function theme_civicrmdata_formatter_contact($item, $crm_field = 'display_name', $fmt = 'plain') {
491      $output = '';
492      $object_id = $item['object_id'];
493      $contact = array();
494      _civicrmdata_cache_mgr('fetch', NULL, $object_id, $contact);
495      if (civinode_check_error($contact))
496        return "oops $object_id";
497      $desc = $contact[$crm_field];
498      switch ($fmt) {
499        case 'link':
500          break;
501       case 'plain':
502       default:
503         $desc = check_plain($desc);
504         break;
505      }
506      $output .= $desc;
507      return $output;
508    }
509    
510    
511    
512    function theme_civicrmdata_profiled_contact($item) {
513      $output = '';
514      $object_id = $item['object_id'];
515      $default_profile = civinode_get_default_profile_id(0);
516      $output .= theme('crm_profile_cid', $profile, $object_id);
517      return $output;
518    }
519    
520    function theme_civicrmdata_formatter_group($item) {
521      $output = '';
522      $object_id = $item['object_id'];
523      $group_obj = civinode_get_group_by_id($object_id);
524      if (!$group_obj) {
525        //do something lame that will help us debug
526        return theme('civicrmdata_formatter_default', $item);
527      }
528      $desc = t('%name (gid=%id)',
529                array('%name' => $group_obj->title,
530                      '%id' => $group_obj->id)
531               );
532      $output .= $desc;
533      return $output;
534    }
535    
536    function theme_civicrmdata_formatter_default($item) {
537      $output = '';
538    
539      $output .= "{$item['entity_type']} ID = {$item['object_id']}";
540      return $output;
541    }
542    
543    function _civicrmdata_cache_mgr($op, $field, &$contact_id, &$data) {
544      //our "singleton simulcrum"
545      static $cache;
546      if (!isset($cache)) {
547        $cache = array();
548      }
549      if ($op == 'fetch') {
550        if (!isset($cache[$field][$contact_id])) {
551          $data = civinode_util_load_cdata($contact_id);
552          $cache[$field][$contact_id] = $data;
553        }
554        else
555          $data = $cache[$field][$contact_id];
556      }
557    
558      return NULL;
559    }
560    
561  function _civicrmdata_includer() {  function _civicrmdata_includer() {
562    include_once(dirname(__FILE__) . '/../../civinode_utils.inc');    include_once(dirname(__FILE__) . '/../../civinode_utils.inc');

Legend:
Removed from v.1.8.2.2  
changed lines
  Added in v.1.8.2.3

  ViewVC Help
Powered by ViewVC 1.1.2