95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class Wiaas_Admin_CL_Contacts
|
|
*/
|
|
class Wiaas_Admin_CL_Contacts {
|
|
|
|
/**
|
|
* Displays table list of customers that are linked to commercial lead and brokers
|
|
*/
|
|
|
|
public static function init() {
|
|
add_action( 'admin_menu', array( __CLASS__, 'add_contacts_page' ), 9 );
|
|
|
|
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
|
}
|
|
|
|
public static function enqueue_scripts() {
|
|
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
|
|
|
wp_enqueue_style( 'wiaas_admin_cl_contacts', $plugin_url . '/assets/css/wiaas-admin-cl-contacts.css' );
|
|
wp_enqueue_script( 'wiaas_admin_cl_contacts', $plugin_url . '/assets/js/wiaas-admin-cl-contacts.js' );
|
|
}
|
|
|
|
/**
|
|
* Add customer menu page for commercial lead
|
|
*/
|
|
public static function add_contacts_page() {
|
|
add_menu_page(
|
|
__( 'Contacts', 'wiaas' ),
|
|
__( 'Contacts', 'wiaas' ),
|
|
'manage_wiaas_cl_customers',
|
|
'wiaas-cl-contacts',
|
|
array(__CLASS__, 'output_contacts'),
|
|
'dashicons-list-view',
|
|
'66.0' );
|
|
}
|
|
|
|
/**
|
|
* Render content for contacts menu page
|
|
*/
|
|
public static function output_contacts() {
|
|
$organization_id = wiaas_get_current_user_organization_id();
|
|
|
|
$related_customer_organizations = Wiaas_Shop::get_shop_customers($organization_id);
|
|
$ids_of_user_organizations_to_show = [];
|
|
|
|
//add customer organizations related to CL
|
|
foreach( $related_customer_organizations as $customer_organization){
|
|
$ids_of_user_organizations_to_show[] = $customer_organization['customer_id'];
|
|
}
|
|
|
|
//add brokers
|
|
$brokers = wiaas_get_brokers();
|
|
|
|
foreach ($brokers as $broker_id => $broker_name) {
|
|
$ids_of_user_organizations_to_show[] = $broker_id;
|
|
}
|
|
|
|
|
|
$args = array(
|
|
'meta_key' => '_wiaas_organization_id',
|
|
'meta_value' => $ids_of_user_organizations_to_show,
|
|
'compare' => 'IN'
|
|
);
|
|
|
|
$query = new WP_User_Query($args);
|
|
|
|
$list_of_users = $query->get_results();
|
|
$contacts = [];
|
|
|
|
foreach ($list_of_users as $user){
|
|
$roles_array = wiaas_get_organization_roles($user->_wiaas_organization_id);
|
|
|
|
$roles = '';
|
|
foreach($roles_array as $role){
|
|
$roles .= translate_user_role( wp_roles()->role_names[ $role ]) . ', ';
|
|
}
|
|
|
|
$roles = substr($roles, 0, -2);
|
|
|
|
$contacts[] = array(
|
|
'name' => $user->user_nicename,
|
|
'email' => $user->user_email,
|
|
'phone' => get_the_author_meta('phone', $user->ID),
|
|
'roles' => $roles
|
|
);
|
|
}
|
|
|
|
require 'views/html-admin-cl-contacts-page.php';
|
|
}
|
|
}
|
|
|
|
Wiaas_Admin_CL_Contacts::init();
|