| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Clients Widget |
| 4 |
* |
| 5 |
* Displays the Clients list. |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class MainWP_Clients |
| 14 |
* |
| 15 |
* Displays the Site Actions. |
| 16 |
*/ |
| 17 |
class MainWP_Clients { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 18 |
|
| 19 |
/** |
| 20 |
* Method get_class_name() |
| 21 |
* |
| 22 |
* @return string __CLASS__ Class name. |
| 23 |
*/ |
| 24 |
public static function get_class_name() { |
| 25 |
return __CLASS__; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Method render() |
| 30 |
* |
| 31 |
* @return mixed render_clients() |
| 32 |
*/ |
| 33 |
public static function render() { |
| 34 |
$clients = MainWP_DB_Client::instance()->get_wp_clients(); |
| 35 |
static::render_clients( $clients ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Render Clients Info. |
| 40 |
* |
| 41 |
* @param mixed $clients Clients data. |
| 42 |
*/ |
| 43 |
private static function render_clients( $clients ) { // phpcs:ignore -- NOSONAR - complex. |
| 44 |
?> |
| 45 |
<div class="mainwp-widget-header"> |
| 46 |
<h3 class="ui header handle-drag"> |
| 47 |
<?php |
| 48 |
/** |
| 49 |
* Filter: mainwp_clients_widget_title |
| 50 |
* |
| 51 |
* Filters the Clients widget title text. |
| 52 |
* |
| 53 |
* @since 4.4 |
| 54 |
*/ |
| 55 |
echo esc_html( apply_filters( 'mainwp_clients_widget_title', esc_html__( 'Clients', 'mainwp' ) ) ); |
| 56 |
?> |
| 57 |
<div class="sub header"><?php esc_html_e( 'Clients information', 'mainwp' ); ?></div> |
| 58 |
</h3> |
| 59 |
</div> |
| 60 |
<div id="mainwp-clients-widget" class="mainwp-scrolly-overflow"> |
| 61 |
<?php |
| 62 |
/** |
| 63 |
* Actoin: mainwp_clients_widget_top |
| 64 |
* |
| 65 |
* Fires at the top of the Clients widget on the overview page. |
| 66 |
* |
| 67 |
* @param object $clients Object containing the clients info. |
| 68 |
* |
| 69 |
* @since 4.4 |
| 70 |
*/ |
| 71 |
do_action( 'mainwp_clients_widget_top', $clients ); |
| 72 |
?> |
| 73 |
<?php if ( $clients ) : ?> |
| 74 |
<table class="ui table" id="mainwp-clients-widget-table"> |
| 75 |
<thead> |
| 76 |
<tr> |
| 77 |
<th scope="col" class="no-sort"></th> |
| 78 |
<th scope="col"><?php esc_html_e( 'Client', 'mainwp' ); ?></th> |
| 79 |
<th scope="col"><?php esc_html_e( 'Primary Contact', 'mainwp' ); ?></th> |
| 80 |
<th scope="col" class="no-sort"></th> |
| 81 |
</tr> |
| 82 |
</thead> |
| 83 |
<tbody> |
| 84 |
<?php foreach ( $clients as $client ) : ?> |
| 85 |
<?php $client_display_image = MainWP_Client_Handler::get_client_contact_image( $client ); ?> |
| 86 |
<tr> |
| 87 |
<td class="left aligned middle aligned"> |
| 88 |
<a href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"> |
| 89 |
<?php echo $client_display_image; //phpcs:ignore -- ok. ?> |
| 90 |
</a> |
| 91 |
</td> |
| 92 |
<td class="left aligned middle aligned"> |
| 93 |
<span><a href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php echo esc_html( $client['name'] ); ?></a></span><br/> |
| 94 |
<?php if ( isset( $client['client_email'] ) && '' !== $client['client_email'] ) : ?> |
| 95 |
<span class="ui small text"><a href="mailto:<?php echo esc_attr( $client['client_email'] ); ?>"><i class="envelope icon"></i> <?php echo esc_html( $client['client_email'] ); ?></a></span><br/> |
| 96 |
<?php endif; ?> |
| 97 |
<?php if ( isset( $client['client_phone'] ) && '' !== $client['client_phone'] ) : ?> |
| 98 |
<span class="ui small text"><a href="tel:<?php echo esc_attr( $client['client_phone'] ); ?>"><i class="phone alternate icon"></i> <?php echo esc_html( $client['client_phone'] ); ?></a></span> |
| 99 |
<?php endif; ?> |
| 100 |
</td> |
| 101 |
<td class="left aligned middle aligned"> |
| 102 |
<?php |
| 103 |
$contact = false; |
| 104 |
if ( isset( $client['primary_contact_id'] ) && '' !== $client['primary_contact_id'] ) { |
| 105 |
$contact = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $client['primary_contact_id'] ); |
| 106 |
if ( $contact ) { |
| 107 |
?> |
| 108 |
<span><?php echo esc_html( $contact->contact_name ); ?> <?php echo ( isset( $contact->contact_role ) && '' !== $contact->contact_role ) ? ' - ' . esc_html( $contact->contact_role ) : ''; ?></span><br/> |
| 109 |
<?php if ( isset( $contact->contact_email ) && '' !== $contact->contact_email ) : ?> |
| 110 |
<span class="ui small text"><a href="mailto:<?php echo esc_attr( $contact->contact_email ); ?>"><i class="envelope icon"></i> <?php echo esc_html( $contact->contact_email ); ?></a></span><br/> |
| 111 |
<?php endif; ?> |
| 112 |
<?php if ( isset( $contact->contact_phone ) && '' !== $contact->contact_phone ) : ?> |
| 113 |
<span class="ui small text"><a href="tel:<?php echo esc_attr( $contact->contact_phone ); ?>"><i class="phone alternate icon"></i> <?php echo esc_html( $contact->contact_phone ); ?></a></span> |
| 114 |
<?php endif; ?> |
| 115 |
<?php |
| 116 |
} |
| 117 |
} |
| 118 |
if ( empty( $contact ) ) { |
| 119 |
echo esc_html__( 'No Contacts', 'mainwp' ); |
| 120 |
} |
| 121 |
?> |
| 122 |
</td> |
| 123 |
<td> |
| 124 |
<div class="ui right pointing dropdown icon mini basic green button mainwp-768-hide" style="z-index:999"> |
| 125 |
<i class="ellipsis horizontal icon"></i> |
| 126 |
<div class="menu"> |
| 127 |
<a class="item" href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'View', 'mainwp' ); ?></a> |
| 128 |
<a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a> |
| 129 |
</div> |
| 130 |
</div> |
| 131 |
</td> |
| 132 |
</tr> |
| 133 |
<?php endforeach; ?> |
| 134 |
</tbody> |
| 135 |
</table> |
| 136 |
<div class="ui two columns stackable grid mainwp-widget-footer"> |
| 137 |
<div class="left aligned column"> |
| 138 |
<a href="admin.php?page=ManageClients" class="ui button mini fluid green"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a> |
| 139 |
</div> |
| 140 |
<div class="right aligned column"> |
| 141 |
<a href="admin.php?page=ClientAddNew" class="ui button basic mini fluid green"><?php esc_html_e( 'New Client', 'mainwp' ); ?></a> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
<script type="text/javascript"> |
| 145 |
jQuery( document ).ready( function() { |
| 146 |
jQuery.fn.DataTable.ext.pager.numbers_length = 4; |
| 147 |
jQuery( '#mainwp-clients-widget-table' ).DataTable( { |
| 148 |
"lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ], |
| 149 |
"stateSave" : true, |
| 150 |
"order" : [ [1, 'asc'] ], |
| 151 |
"columnDefs": [ { |
| 152 |
"targets": 'no-sort', |
| 153 |
"orderable": false |
| 154 |
} ], |
| 155 |
} ); |
| 156 |
} ); |
| 157 |
</script> |
| 158 |
<?php else : ?> |
| 159 |
<?php MainWP_UI::render_empty_element_placeholder(); ?> |
| 160 |
<?php endif; ?> |
| 161 |
<?php |
| 162 |
/** |
| 163 |
* Action: mainwp_clients_widget_bottom |
| 164 |
* |
| 165 |
* Fires at the bottom of the Clients widget on the overview page. |
| 166 |
* |
| 167 |
* @param object $clients Object containing the child site info. |
| 168 |
* |
| 169 |
* @since 4.4 |
| 170 |
*/ |
| 171 |
do_action( 'mainwp_clients_widget_bottom', $clients ); |
| 172 |
?> |
| 173 |
</div> |
| 174 |
<?php |
| 175 |
} |
| 176 |
} |
| 177 |
|