Commit d2081fd6 authored by pingers's avatar pingers

Code clean up.

parent 691cfa03
......@@ -108,4 +108,3 @@ function crm_core_activity_entity_property_info() {
return $info;
}
......@@ -206,6 +206,7 @@ function crm_core_activity_update_7002(&$sandbox) {
if ($sandbox['#finished']) {
drupal_flush_all_caches();
return t('Added and populated field values for new {crm_core_activity}.activity_type_id field');
$t = get_t();
return $t('Added and populated field values for new {crm_core_activity}.activity_type_id field');
}
}
......@@ -157,13 +157,14 @@ function crm_core_activity_access($op, $activity, $account = NULL, $entity_type
return (user_access('administer crm_core_activity entities', $account)
|| user_access('delete any crm_core_activity entity', $account)
|| user_access('delete any crm_core_activity entity of bundle ' . $activity_type));
case 'create_view':
// Check if user has access permission to a view with create activity links.
if (user_access('administer crm_core_activity entities', $account)
|| user_access('create crm_core_activity entities', $account)) {
return TRUE;
}
// Allow access if account has create permissions for any crm core activity type .
// Allow access if account has create permissions for any crm core activity type.
foreach (array_keys(crm_core_activity_types()) as $type) {
if (entity_access('create', 'crm_core_activity', $type, $account)) {
return TRUE;
......
......@@ -65,7 +65,7 @@ class CRMFeedsActivityProcessor extends FeedsProcessor {
}
/**
* Save a activity.
* Save an activity.
*/
public function entitySave($entity) {
crm_core_activity_save($entity);
......@@ -273,6 +273,7 @@ class CRMFeedsActivityProcessor extends FeedsProcessor {
case 'activity_id':
$activity_id = db_query("SELECT activity_id FROM {crm_core_activity} WHERE activity_id = :activity_id", array(':activity_id' => $value))->fetchField();
break;
case 'feeds_source':
if ($id = feeds_get_importer_id($this->config['activity_type'])) {
$activity_id = db_query("SELECT fs.feed_activity_id FROM {crm_core_activity} c JOIN {feeds_source} fs ON c.activity_id = fs.feed_activity_id WHERE fs.id = :id AND fs.source = :source", array(':id' => $id, ':source' => $value))->fetchField();
......
......@@ -5,8 +5,8 @@
* Theme implementation for activity entity.
*
* Available variables:
* - $content: An array of comment items. Use render($content) to print them all, or
* print a subset such as render($content['field_example']). Use
* - $content: An array of comment items. Use render($content) to print them
* all, or print a subset such as render($content['field_example']). Use
* hide($content['field_example']) to temporarily suppress the printing of a
* given element.
*
......
......@@ -89,4 +89,3 @@ class crm_core_activity_handler_field_link_delete extends crm_core_activity_hand
}
}
}
......@@ -167,7 +167,7 @@ function crm_core_activity_form_delete_confirm($form, &$form_state, $activity) {
// Always provide entity id in the same form key as in the entity edit form.
$form['activity_id'] = array(
'#type' => 'value',
'#value' => $activity->activity_id
'#value' => $activity->activity_id,
);
return confirm_form($form,
......
......@@ -159,4 +159,3 @@ function crm_core_activity_ui_views_default_views() {
return $views;
}
......@@ -14,9 +14,6 @@
*/
function crm_core_contact_type_form($form, &$form_state, $contact_type) {
// Ensure this include file is loaded when the form is rebuilt from the cache.
// $form_state['build_info']['file'] = drupal_get_path('module', 'commerce_product') . '/includes/commerce_product.forms.inc';
// Store the initial product type in the form state.
$form_state['contact_type'] = $contact_type;
......@@ -58,7 +55,7 @@ function crm_core_contact_type_form($form, &$form_state, $contact_type) {
'#attached' => array(
'js' => array(
drupal_get_path('module', 'system') . '/system.js',
$js_settings
$js_settings,
),
),
);
......@@ -137,7 +134,7 @@ function crm_core_contact_type_form($form, &$form_state, $contact_type) {
}
/**
* Validation callback
* Validation callback.
*/
function crm_core_contact_type_form_validate($form, &$form_state) {
$contact_type = $form_state['contact_type'];
......
......@@ -47,6 +47,7 @@ function crm_core_contact_context_page_condition() {
case '':
$op = 'view';
break;
case 'edit':
$op = 'form';
break;
......
......@@ -46,6 +46,14 @@ function crm_core_contact_uninstall() {
}
}
/**
* Implements hook_enable().
*/
function crm_core_contact_enable() {
// Clear the cache to display in Feeds as available plugin.
cache_clear_all('plugins:feeds:plugins', 'cache');
}
/**
* Implements hook_schema().
*/
......
......@@ -9,21 +9,21 @@
* Class for evaluating email fields.
*/
class EmailMatchField extends SelectMatchField {
public function fieldRender($field, $field_info, &$form) {
$field_name = $field['field_name'];
$field_item = 'email';
$separator = empty($field_item) ? $field_name : $field_name . '_' . $field_item;
$field_label = $field['label'];
$contact_type = $field['bundle'];
$config = crm_core_default_matching_engine_load_field_config($contact_type, $field_name, $field_item);
$display_weight = self::WEIGHT_DELTA;
if ($config['weight'] == 0) {
// Table row positioned incorrectly if "#weight" is 0.
......@@ -79,7 +79,7 @@ class EmailMatchField extends SelectMatchField {
'#disabled' => FALSE,
'#options' => $this->operators(),
);
$form['field_matching'][$separator]['operator'] = $operator;
$form['field_matching'][$separator]['options'] = array(
......@@ -108,8 +108,8 @@ class EmailMatchField extends SelectMatchField {
'#delta' => self::WEIGHT_DELTA,
);
}
/**
* Field query to search matches.
*
......@@ -122,20 +122,20 @@ class EmailMatchField extends SelectMatchField {
* Founded matches.
*/
public function fieldQuery($contact, $rule) {
$results = array();
$contact_wrapper = entity_metadata_wrapper('crm_core_contact', $contact);
$needle = '';
$field_item = '';
if(isset($contact_wrapper->{$rule->field_name}->{$rule->field_item})){
if (isset($contact_wrapper->{$rule->field_name}->{$rule->field_item})) {
$needle = $contact_wrapper->{$rule->field_name}->{$rule->field_item}->value();
} else {
$needle = $contact_wrapper->{$rule->field_name}->value();
}
$field_item = $rule->field_item;
if (!empty($needle)) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'crm_core_contact')->entityCondition('bundle', $contact->type);
......@@ -167,6 +167,6 @@ class EmailMatchField extends SelectMatchField {
return isset($results['crm_core_contact']) ? array_keys($results['crm_core_contact']) : $results;
}
}
......@@ -9,18 +9,19 @@
* Implements hook_install().
*/
function crm_core_relationship_install() {
$t = get_t();
// Add default relationships
$relation_types_info = array(
array(
'relation_type' => 'crm_friend',
'label' => st('Friend of'),
'label' => $t('Friend of'),
'source_bundles' => array('crm_core_contact:individual'),
'r_unique' => TRUE,
),
array(
'relation_type' => 'crm_employee',
'label' => st('Employee of'),
'reverse_label' => st('Employer of'),
'label' => $t('Employee of'),
'reverse_label' => $t('Employer of'),
'directional' => TRUE,
'r_unique' => TRUE,
'source_bundles' => array('crm_core_contact:individual'),
......@@ -28,8 +29,8 @@ function crm_core_relationship_install() {
),
array(
'relation_type' => 'crm_member',
'label' => st('Member of'),
'reverse_label' => st('Household for'),
'label' => $t('Member of'),
'reverse_label' => $t('Household for'),
'directional' => TRUE,
'r_unique' => TRUE,
'source_bundles' => array('crm_core_contact:individual'),
......@@ -84,11 +85,14 @@ function crm_core_relationship_update_7000() {
foreach (crm_core_relationship_get_relationships() as $crm_relation) {
crm_core_relationship_field_attach_create_bundle('relation', $crm_relation->relation_type);
}
$t = get_t();
// Rename "Friend" relationship to "Friend of", if not renamed yet.
$crm_friend = relation_type_load('crm_friend');
if ($crm_friend->label == 'Friend') {
$crm_friend->label = st('Friend of');
$crm_friend->reverse_label = st('Friend of');
$crm_friend->label = $t('Friend of');
$crm_friend->reverse_label = $t('Friend of');
relation_type_save($crm_friend, array('relation_type'));
}
// Fill in "status" field for existing relationships.
......
......@@ -4,11 +4,13 @@
* Implements hook_install()
*/
function crm_core_user_sync_install() {
$t = get_t();
// Add relation type
$relation_type_info = array(
'relation_type' => 'crm_core_user_sync',
'label' => st('Contact'),
'reverse_label' => st('User'),
'label' => $t('Contact'),
'reverse_label' => $t('User'),
'source_bundles' => array('user:user'),
'target_bundles' => array('crm_core_contact:*'),
'r_unique' => TRUE,
......
......@@ -560,7 +560,7 @@ function crm_core_user_sync_views_pre_execute(&$view) {
function _crm_core_user_sync_get_entity_id_from_text($text, $entity_type) {
$entity_info = entity_get_info($entity_type);
if (empty($entity_info) || empty($entity_info['entity keys']['id'])){
if (empty($entity_info) || empty($entity_info['entity keys']['id'])) {
return FALSE;
}
......
<?php
/**
* Admin form for Og Synchronization
* Admin form for Og Synchronization.
*/
function crm_og_sync_admin_form($form, &$form_state) {
......@@ -12,7 +12,7 @@ function crm_og_sync_admin_form($form, &$form_state) {
'#default_value' => variable_get('crm_og_sync_reverse', 0),
);
// need to get default value from database as well
// Need to get default value from database as well.
$og_nodes = _crm_og_sync_og_types();
if (empty($og_nodes)) {
$form['message'] = array(
......@@ -58,14 +58,14 @@ function crm_og_sync_admin_form($form, &$form_state) {
$contact_types[$_contact_type->type] = $_contact_type->name;
}
$form[$og_entity_type]['contact_type'] = array(
'#type' => 'select',
'#title' => t('Contact type to be synced'),
'#options' => $contact_types,
'#default_value' => (!empty($default_settings)) ? $default_settings['crm_contact_type'] : 'organization',
'#ajax' => array(
'callback' => 'crm_og_sync_admin_form_ajax_callback',
'wrapper' => 'form_target',
),
'#type' => 'select',
'#title' => t('Contact type to be synced'),
'#options' => $contact_types,
'#default_value' => (!empty($default_settings)) ? $default_settings['crm_contact_type'] : 'organization',
'#ajax' => array(
'callback' => 'crm_og_sync_admin_form_ajax_callback',
'wrapper' => 'form_target',
),
);
$form[$og_entity_type]['mapping'] = array(
......@@ -82,9 +82,9 @@ function crm_og_sync_admin_form($form, &$form_state) {
'__none' => t('--Do not sync--'),
);
// ajax callback based on contact type
// Ajax callback based on contact type.
if (!empty($selected_contact_type)) {
$options += _crm_og_sync_contact_fields($form_state['values'][$og_entity_type]['contact_type']);
$options += _crm_og_sync_contact_fields($form_state['values'][$og_entity_type]['contact_type']);
}
else {
$default_contact_type = (isset($default_settings['crm_contact_type'])) ? $default_settings['crm_contact_type'] : 'organization';
......@@ -127,7 +127,7 @@ function crm_og_sync_admin_form_validate($form, &$form_state) {
}
/**
* submission handler
* Submission handler.
*/
function crm_og_sync_admin_form_submit($form, &$form_state) {
......@@ -137,17 +137,17 @@ function crm_og_sync_admin_form_submit($form, &$form_state) {
variable_set('crm_og_sync_reverse', $values['crm_og_sync_reverse']);
foreach ($og_node_types as $og_entity_type) {
// save the record
$record = array(
'og_bundle_type' => $og_entity_type,
'og_entity_type' => 'node',
'crm_contact_type' => $values[$og_entity_type]['contact_type'],
'status' => $values[$og_entity_type]['toggle'],
'field_mapping' => $values[$og_entity_type]['mapping'],
);
crm_og_sync_save_config($record, $values[$og_entity_type]['is_new']);
// Save the record.
$record = array(
'og_bundle_type' => $og_entity_type,
'og_entity_type' => 'node',
'crm_contact_type' => $values[$og_entity_type]['contact_type'],
'status' => $values[$og_entity_type]['toggle'],
'field_mapping' => $values[$og_entity_type]['mapping'],
);
crm_og_sync_save_config($record, $values[$og_entity_type]['is_new']);
}
drupal_set_message(t('Configuration settings saved'));
}
\ No newline at end of file
}
......@@ -2,15 +2,17 @@
/**
* Implements hook_install()
* Implements hook_install().
*/
function crm_og_sync_install() {
// Add relation type
// future: this should include more entity type to be synced
$t = get_t();
// Add relation type.
// TODO: this should include more entity type to be synced.
$relation_type_info = array(
'relation_type' => 'crm_og_sync',
'label' => st('Contact'),
'reverse_label' => st('Organic Group: Node'),
'label' => $t('Contact'),
'reverse_label' => $t('Organic Group: Node'),
'source_bundles' => array('node:*'),
'target_bundles' => array('crm_core_contact:*'),
'r_unique' => TRUE,
......@@ -21,14 +23,14 @@ function crm_og_sync_install() {
}
/**
* Implements hook_install()
* Implements hook_install().
*/
function crm_og_sync_uninstall() {
relation_type_delete('crm_og_sync');
}
/**
* Implements hook_schema()
* Implements hook_schema().
*/
function crm_og_sync_schema() {
$schema['crm_og_sync_settings'] = array(
......@@ -67,8 +69,8 @@ function crm_og_sync_schema() {
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of field mapping between the entity bundle and the crm contact type',
),
),
),
'primary key' => array('og_bundle_type', 'og_entity_type'),
);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment