Skip to content

Connection types #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 14 additions & 28 deletions dt-contacts/access-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,6 @@ public function dt_custom_fields_settings( $fields, $post_type ){
if ( isset( $fields['type']['default']['personal'] ) ){
$fields['type']['default']['personal']['default'] = false;
}
$fields['type']['default']['access'] = [
'label' => __( 'Standard Contact', 'disciple_tools' ),
'color' => '#2196F3',
'description' => __( 'A contact to collaborate on', 'disciple_tools' ),
'visibility' => __( 'Me and project leadership', 'disciple_tools' ),
'icon' => get_template_directory_uri() . '/dt-assets/images/share.svg?v=2',
'order' => 20,
'default' => true,
];
$fields['type']['default']['access_placeholder'] = [
'label' => __( 'Connection', 'disciple_tools' ),
'color' => '#FF9800',
'description' => __( 'Connected to a contact, or generational fruit', 'disciple_tools' ),
'icon' => get_template_directory_uri() . '/dt-assets/images/share.svg?v=2',
'order' => 40,
'visibility' => __( 'Collaborators', 'disciple_tools' ),
'in_create_form' => false,
];

$fields['assigned_to'] = [
'name' => __( 'Assigned To', 'disciple_tools' ),
'description' => __( 'Select the main person who is responsible for reporting on this contact.', 'disciple_tools' ),
Expand Down Expand Up @@ -777,7 +758,7 @@ public function dt_post_create_fields( $fields, $post_type ){
}
if ( isset( $fields['additional_meta']['created_from'] ) ){
$from_post = DT_Posts::get_post( 'contacts', $fields['additional_meta']['created_from'], true, false );
if ( !is_wp_error( $from_post ) && isset( $from_post['type']['key'] ) && $from_post['type']['key'] === 'access' ){
if ( !is_wp_error( $from_post ) && isset( $from_post['type']['key'] ) && in_array( $from_post['type']['key'], [ 'access', 'access_placeholder', 'user' ] ) ){
$fields['type'] = 'access_placeholder';
}
}
Expand All @@ -790,11 +771,19 @@ public function dt_post_create_fields( $fields, $post_type ){
if ( !isset( $fields['type'] ) && get_current_user_id() === 0 ){
$fields['type'] = 'access';
}

/**
* Stop here if the type is not "access"
*/
if ( !isset( $fields['type'] ) || $fields['type'] !== 'access' ){
return $fields;
}
if ( !isset( $fields['seeker_path'] ) ){
$fields['seeker_path'] = 'none';
if ( !isset( $fields['overall_status'] ) ){
if ( get_current_user_id() ){
$fields['overall_status'] = 'active';
} else {
$fields['overall_status'] = 'new';
}
}
if ( !isset( $fields['assigned_to'] ) ){
if ( get_current_user_id() ) {
Expand All @@ -814,13 +803,10 @@ public function dt_post_create_fields( $fields, $post_type ){
}
}
}
if ( !isset( $fields['overall_status'] ) ){
if ( get_current_user_id() ){
$fields['overall_status'] = 'active';
} else {
$fields['overall_status'] = 'new';
}
if ( !isset( $fields['seeker_path'] ) ){
$fields['seeker_path'] = 'none';
}

if ( !isset( $fields['sources'] ) ) {
$fields['sources'] = [ 'values' => [ [ 'value' => 'personal' ] ] ];
}
Expand Down
42 changes: 39 additions & 3 deletions dt-contacts/base-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function dt_custom_fields_settings( $fields, $post_type ){
'tile' => 'details',
'icon' => get_template_directory_uri() . '/dt-assets/images/nametag.svg?v=2',
];
$contact_preferences = get_option( 'dt_contact_preferences', [] );
$post_type_settings = get_option( 'dt_custom_post_types', [] );
$private_contacts_enabled = $post_type_settings['contacts']['enable_private_contacts'] ?? false;
$fields['type'] = [
'name' => __( 'Contact Type', 'disciple_tools' ),
'type' => 'key_select',
Expand All @@ -125,9 +126,27 @@ public function dt_custom_fields_settings( $fields, $post_type ){
'visibility' => __( 'Only me', 'disciple_tools' ),
'icon' => get_template_directory_uri() . '/dt-assets/images/locked.svg?v=2',
'order' => 50,
'hidden' => !empty( $contact_preferences['hide_personal_contact_type'] ),
'hidden' => !$private_contacts_enabled,
'default' => true
],
'access' => [
'label' => __( 'Standard Contact', 'disciple_tools' ),
'color' => '#2196F3',
'description' => __( 'A contact to collaborate on', 'disciple_tools' ),
'visibility' => __( 'Me and project leadership', 'disciple_tools' ),
'icon' => get_template_directory_uri() . '/dt-assets/images/share.svg?v=2',
'order' => 20,
'default' => true,
],
'access_placeholder' => [
'label' => __( 'Connection', 'disciple_tools' ),
'color' => '#FF9800',
'description' => __( 'Connected to a contact, or generational fruit', 'disciple_tools' ),
'icon' => get_template_directory_uri() . '/dt-assets/images/share.svg?v=2',
'order' => 40,
'visibility' => __( 'Collaborators', 'disciple_tools' ),
'in_create_form' => false,
]
],
'description' => 'See full documentation here: https://disciple.tools/user-docs/getting-started-info/contacts/contact-types',
'icon' => get_template_directory_uri() . '/dt-assets/images/circle-square-triangle.svg?v=2',
Expand Down Expand Up @@ -466,8 +485,25 @@ public function dt_post_updated( $post_type, $post_id, $update_fields, $old_post
//Add, remove or modify fields before the fields are processed in post create
public function dt_post_create_fields( $fields, $post_type ){
if ( $post_type === 'contacts' ){
if ( !isset( $fields['type'] ) && isset( $fields['additional_meta']['created_from'] ) ){
$from_post = DT_Posts::get_post( 'contacts', $fields['additional_meta']['created_from'], true, false );
if ( !is_wp_error( $from_post ) && isset( $from_post['type']['key'] ) ){
switch ( $from_post['type']['key'] ){
case 'personal':
case 'placeholder':
$fields['type'] = 'placeholder';
break;
case 'access':
case 'access_placeholder':
case 'user':
$fields['type'] = 'access_placeholder';
break;
}
}
}

if ( !isset( $fields['type'] ) ){
$fields['type'] = 'personal';
$fields['type'] = 'access';
}
}
return $fields;
Expand Down
9 changes: 3 additions & 6 deletions dt-contacts/dmm-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(){
public function dt_custom_fields_settings( $fields, $post_type ){
$declared_fields = $fields;
if ( $post_type === 'contacts' ){
$contact_preferences = get_option( 'dt_contact_preferences', [] );
$private_contacts_enabled = $post_type_settings['contacts']['enable_private_contacts'] ?? false;
$fields['type']['default']['placeholder'] = [
'label' => __( 'Private Connection', 'disciple_tools' ),
'color' => '#FF9800',
Expand All @@ -53,7 +53,7 @@ public function dt_custom_fields_settings( $fields, $post_type ){
'order' => 40,
'visibility' => __( 'Only me', 'disciple_tools' ),
'in_create_form' => false,
'hidden' => !empty( $contact_preferences['hide_personal_contact_type'] ),
'hidden' => !$private_contacts_enabled,
];
$fields['milestones'] = [
'name' => __( 'Faith Milestones', 'disciple_tools' ),
Expand Down Expand Up @@ -330,11 +330,8 @@ public function post_connection_removed( $post_type, $post_id, $post_key, $value
//Add, remove or modify fields before the fields are processed in post create
public function dt_post_create_fields( $fields, $post_type ){
if ( $post_type === 'contacts' ){
if ( !isset( $fields['type'] ) ){
$fields['type'] = 'placeholder';
}
//mark a new user contact as being coached be the user who added the new user.
if ( $fields['type'] === 'user' ){
if ( isset( $fields['type'] ) && $fields['type'] === 'user' ){
$current_user_contact = Disciple_Tools_Users::get_contact_for_user( get_current_user_id() );
if ( $current_user_contact && !is_wp_error( $current_user_contact ) ){
$fields['coached_by'] = [ 'values' => [ [ 'value' => $current_user_contact ] ] ];
Expand Down
18 changes: 11 additions & 7 deletions dt-core/admin/menu/tabs/tab-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,27 +829,31 @@ public function process_dt_contact_preferences(){
if ( isset( $_POST['dt_contact_preferences_nonce'] ) &&
wp_verify_nonce( sanitize_key( wp_unslash( $_POST['dt_contact_preferences_nonce'] ) ), 'dt_contact_preferences' . get_current_user_id() ) ) {

$contact_preferences = get_option( 'dt_contact_preferences' );
if ( isset( $_POST['hide_personal_contact_type'] ) && ! empty( $_POST['hide_personal_contact_type'] ) ) {
$contact_preferences['hide_personal_contact_type'] = false;
$post_type_settings = get_option( 'dt_custom_post_types', [] );
$contact_preferences = $post_type_settings['contacts'] ?? [];

if ( isset( $_POST['private_contacts_enabled'] ) && ! empty( $_POST['private_contacts_enabled'] ) ) {
$contact_preferences['enable_private_contacts'] = true;
} else {
$contact_preferences['hide_personal_contact_type'] = true;
$contact_preferences['enable_private_contacts'] = false;
}
$post_type_settings['contacts'] = $contact_preferences;

update_option( 'dt_contact_preferences', $contact_preferences, true );
update_option( 'dt_custom_post_types', $post_type_settings, true );
}

}

public function show_dt_contact_preferences(){
$contact_preferences = get_option( 'dt_contact_preferences', [] );
$post_type_settings = get_option( 'dt_custom_post_types', [] );
$private_contacts_enabled = $post_type_settings['contacts']['enable_private_contacts'] ?? false;
?>
<form method="post" >
<table class="widefat">
<tr>
<td>
<label>
<input type="checkbox" name="hide_personal_contact_type" <?php echo empty( $contact_preferences['hide_personal_contact_type'] ) ? 'checked' : '' ?> /> Personal Contact Type Enabled
<input type="checkbox" name="private_contacts_enabled" <?php echo $private_contacts_enabled ? 'checked' : '' ?> /> Private Contact Type Enabled. See <a href="https://disciple.tools/user-docs/getting-started-info/contacts/contact-types/" target="_blank">Contact Types Documentation</a>
</label>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion dt-core/configuration/class-migration-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Disciple_Tools_Migration_Engine
{

public static $migration_number = 56;
public static $migration_number = 57;

protected static $migrations = null;

Expand Down
35 changes: 35 additions & 0 deletions dt-core/migrations/0057-enabled-private-contacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
if ( !defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly

/**
* Class Disciple_Tools_Migration_0057
*
* move the hide_personal_contact_type option to the contacts post type settings
*/
class Disciple_Tools_Migration_0057 extends Disciple_Tools_Migration {
public function up() {
//skip this migration on a new install
if ( dt_get_initial_install_meta( 'migration_number' ) >= 57 ){
return;
}

$contact_preferences = get_option( 'dt_contact_preferences', [] );
$hide_personal_contact_type = $contact_preferences['hide_personal_contact_type'] ?? false;

$post_type_custom_settings = $custom_settings['contacts'] ?? [];
$post_type_custom_settings['enable_private_contacts'] = !$hide_personal_contact_type;
$custom_settings['contacts'] = $post_type_custom_settings;
update_option( 'dt_custom_post_types', $custom_settings );
delete_option( 'dt_contact_preferences' );
}

public function down() {
}

public function test() {
}

public function get_expected_tables(): array {
return [];
}
}
Loading