Index: civicrmdata.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/civinode/contrib/civicrmdata/civicrmdata.module,v retrieving revision 1.4 diff -u -r1.4 civicrmdata.module --- civicrmdata.module 24 May 2006 15:19:36 -0000 1.4 +++ civicrmdata.module 10 Jun 2006 22:45:20 -0000 @@ -1,209 +1,236 @@ -Note: Requires content.module, civicrm.module.'); - } -} - -/** - * Implementation of hook_field_info(). - */ -function civicrmdata_field_info() { - return array( - 'civicrmdata_group' => array('label' => 'CiviCRM Group Reference'), - 'civicrmdata_profile' => array('label' => 'CiviCRM Profile Reference'), - 'civicrmdata_contact' => array('label' => 'CiviCRM Contact Reference'), - 'civicrmdata_location' => array('label' => 'CiviCRM Location Reference'), - 'civicrmdata_activity' => array('label' => 'CiviCRM Activity Reference'), - 'civicrmdata_relationship' => array('label' => 'CiviCRM Relationship Reference'), - 'civicrmdata_tag' => array('label' => 'CiviCRM Tag Reference'), - //'civicrmdata_field' => array('label' => 'CiviCRM Field Reference'), - //'civicrmdata_search' => array('label' => 'CiviCRM Saved Search'), - ); -} - -/** - * Implementation of hook_field_settings(). - */ -function civicrmdata_field_settings($op, $field) { - switch ($op) { - - case 'database columns': - $columns = array( - 'crmid' => array('type' => 'int', 'not null' => FALSE, 'default' => '0'), - ); - return $columns; - } -} - -/** - * Implementation of hook_field(). - */ -function civicrmdata_field($op, &$node, $field, &$node_field, $teaser, $page) -{ - $crm_entity = substr($field['type'], 12); - - switch ($op) { - case 'view': - switch ($crm_entity) { - case 'contact': - case 'group': - foreach ($node_field as $delta => $item) { - $node_field[$delta]['view'] = _civicrmdata_view($crm_entity, $item['crmid']); - } - break; - - default: - return; - } - - return theme('field', $node, $field, $node_field, $teaser, $page); - } -} - -function _civicrmdata_view($crm_entity, $crm_id) { - - switch($crm_entity) { - case 'contact': - global $user; - _civicrmdata_includer(); // get our helper functions - $pid = civinode_get_default_profile_id(0); return theme('crm_profile_cid', $pid, $crm_id); - case 'group': - _civicrmdata_includer(); // get our helper functions - if (civinode_check_init()) { - $params = array('id' => $crm_id); - $returns = array('title'); - $groups = crm_get_groups($params, $returns); - if ($group = array_pop($groups)) { - // todo: check perms and return to links to viewing the contacts - return check_plain($group->title); - } - } +Note: Requires content.module, civicrm.module.'); + } +} + +/** + * Implementation of hook_field_info(). + */ +function civicrmdata_field_info() { + return array( + 'civicrmdata_group' => array('label' => 'CiviCRM Group Reference'), + 'civicrmdata_profile' => array('label' => 'CiviCRM Profile Reference'), + 'civicrmdata_contact' => array('label' => 'CiviCRM Contact Reference'), + 'civicrmdata_location' => array('label' => 'CiviCRM Location Reference'), + 'civicrmdata_activity' => array('label' => 'CiviCRM Activity Reference'), + 'civicrmdata_relationship' => array('label' => 'CiviCRM Relationship Reference'), + 'civicrmdata_tag' => array('label' => 'CiviCRM Tag Reference'), + //'civicrmdata_field' => array('label' => 'CiviCRM Field Reference'), + //'civicrmdata_search' => array('label' => 'CiviCRM Saved Search'), + ); +} + +/** + * Implementation of hook_field_settings(). + */ +function civicrmdata_field_settings($op, $field) { + switch ($op) { + case 'form': + if ($field['type'] = 'civicrmdata_contact') { + $form = array(); + $default_group = isset($field['group_id']) ? $field['group_id'] : 0; //look in field... + $group_widget = civinode_group_selector(t('Choose Contacts From Group'), + t('Optionally, restrict contacts to a single group (Recommended)'), + $default_group); + $form['group_id'] = $group_widget; + return $form; + } + break; + case 'save': + if ($field['type'] = 'civicrmdata_contact') { + return array('group_id'); + } + break; + case 'database columns': + $columns = array( + 'crmid' => array('type' => 'int', 'not null' => FALSE, 'default' => '0'), + //'crm_group' => array('type' => 'int', 'not null' => FALSE, 'default' => '0'), + ); + return $columns; + } +} + +/** + * Implementation of hook_field(). + */ +function civicrmdata_field($op, &$node, $field, &$node_field, $teaser, $page) +{ + $crm_entity = substr($field['type'], 12); + + switch ($op) { + case 'view': + switch ($crm_entity) { + case 'contact': + case 'group': + foreach ($node_field as $delta => $item) { + $node_field[$delta]['view'] = _civicrmdata_view($crm_entity, $item['crmid']); + } + break; + + default: + return; + } + + return theme('field', $node, $field, $node_field, $teaser, $page); + } +} + +function _civicrmdata_view($crm_entity, $crm_id) { + + switch($crm_entity) { + case 'contact': + global $user; + _civicrmdata_includer(); // get our helper functions + $pid = civinode_get_default_profile_id(0); + return theme('crm_profile_cid', $pid, $crm_id); + case 'group': + _civicrmdata_includer(); // get our helper functions + if (civinode_check_init()) { + $params = array('id' => $crm_id); + $returns = array('title'); + $groups = crm_get_groups($params, $returns); + if ($group = array_pop($groups)) { + // todo: check perms and return to links to viewing the contacts + return check_plain($group->title); + } + } break; - - } -} - -/** - * Implementation of hook_widget_info(). - */ -function civicrmdata_widget_info() { - return array( - 'civicrmdata_select' => array( - 'label' => 'Select List', - 'field types' => array( - 'civicrmdata_group', - 'civicrmdata_profile', - 'civicrmdata_contact', - 'civicrmdata_location', - 'civicrmdata_activity', - 'civicrmdata_relationship', - 'civicrmdata_tag', - //'civicrmdata_field', - //'civicrmdata_search', - ), - ), - /* We don't have autocomplete features yet. Some day.... - 'civicrmdata_autocomplete' => array( - 'label' => 'Autocomplete Text Field', - 'field types' => array( - 'civicrmdata_group', - 'civicrmdata_profile', - 'civicrmdata_contact', - 'civicrmdata_location', - 'civicrmdata_activity', - 'civicrmdata_relationship', - 'civicrmdata_tag', - 'civicrmdata_field', - ), - ),*/ - ); -} - -/** - * Implementation of hook_widget_settings(). - */ -function civicrmdata_widget_settings($op, $widget) { - switch ($op) { - case 'form': - return array(); - - case 'validate': - break; - - case 'save': - return array(); - } -} - -/** - * Implementation of hook_widget(). - */ -function civicrmdata_widget($op, &$node, $field, &$node_field) { - - - $widget = substr($field['widget']['type'], 12); - $crm_entity = substr($field['type'], 12); - - switch($op) { - case 'prepare form values': - $node_field_transposed = content_transpose_array_rows_cols($node_field); - $node_field['default crmids'] = $node_field_transposed['crmid']; - break; - - case 'form': - $options = array(); - if (!$field['required']) { - $options[0] = '<' . t('None') . '>'; - } - - _civicrmdata_includer(); - $options += civinode_get_allowed_options($crm_entity); - - - $form = array(); - - $form[$field['field_name']] = array('#tree' => TRUE); - $form[$field['field_name']]['crmids'] = array( - '#type' => 'select', - '#title' => t($field['widget']['label']), - '#default_value' => $node_field['default crmids'], - '#multiple' => $field['multiple'], - '#options' => $options, - '#required' => $field['required'], - '#description' => $field['widget']['description'], - ); - - return $form; - - break; - - case 'process form values': - if ($field['multiple']) { - $node_field = content_transpose_array_rows_cols(array('crmid' => $node_field['crmids'])); - } - else { - $node_field[0]['crmid'] = $node_field['crmids']; - } - // Remove the widget's data representation so it isn't saved. - unset($node_field['crmids']); - - break; - } - -} - -function _civicrmdata_includer() { - include_once(dirname(__FILE__) . '/../../civinode_utils.inc'); -} + + } +} + +/** + * Implementation of hook_widget_info(). + */ +function civicrmdata_widget_info() { + return array( + 'civicrmdata_select' => array( + 'label' => 'Select List', + 'field types' => array( + 'civicrmdata_group', + 'civicrmdata_profile', + 'civicrmdata_contact', + 'civicrmdata_location', + 'civicrmdata_activity', + 'civicrmdata_relationship', + 'civicrmdata_tag', + //'civicrmdata_field', + //'civicrmdata_search', + ), + ), + + //'civicrm_select_by_group' => array( + // 'label' => t('Select From Group Memembers'), + // 'field types' => array('civicrmdata_contact') + // ), + /* We don't have autocomplete features yet. Some day.... + 'civicrmdata_autocomplete' => array( + 'label' => 'Autocomplete Text Field', + 'field types' => array( + 'civicrmdata_group', + 'civicrmdata_profile', + 'civicrmdata_contact', + 'civicrmdata_location', + 'civicrmdata_activity', + 'civicrmdata_relationship', + 'civicrmdata_tag', + 'civicrmdata_field', + ), + ),*/ + ); +} + +/** + * Implementation of hook_widget_settings(). + */ +function civicrmdata_widget_settings($op, $widget) { + switch ($op) { + case 'form': + return array(); + + case 'validate': + break; + + case 'save': + return array(); + } +} + +/** + * Implementation of hook_widget(). + */ +function civicrmdata_widget($op, &$node, $field, &$node_field) { + + + $widget = substr($field['widget']['type'], 12); + $crm_entity = substr($field['type'], 12); + $params = array(); //restriction for items returned + if ($crm_entity == 'contact') { + if (isset($field['group_id']) and $field['group_id']) + $params['groups'] = array($field['group_id']); + } + + switch($op) { + case 'prepare form values': + $node_field_transposed = content_transpose_array_rows_cols($node_field); + $node_field['default crmids'] = $node_field_transposed['crmid']; + break; + + case 'form': + $options = array(); + if (!$field['required']) { + $options[0] = '<' . t('None') . '>'; + } + + _civicrmdata_includer(); + $options += civinode_get_allowed_options($crm_entity, $params); + + + $form = array(); + + $form[$field['field_name']] = array('#tree' => TRUE); + $form[$field['field_name']]['crmids'] = array( + '#type' => 'select', + '#title' => t($field['widget']['label']), + '#default_value' => $node_field['default crmids'], + '#multiple' => $field['multiple'], + '#options' => $options, + '#required' => $field['required'], + '#description' => $field['widget']['description'], + ); + + return $form; + + break; + + case 'process form values': + if ($field['multiple']) { + $node_field = content_transpose_array_rows_cols(array('crmid' => $node_field['crmids'])); + } + else { + $node_field[0]['crmid'] = $node_field['crmids']; + } + // Remove the widget's data representation so it isn't saved. + unset($node_field['crmids']); + + break; + } + +} + +function _civicrmdata_includer() { + include_once(dirname(__FILE__) . '/../../civinode_utils.inc'); +}