PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.2
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / agent_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
agent_helper.php
352 lines
1 <?php
2
3 class OsAgentHelper {
4
5 static $agents;
6 static $selected_agent = false;
7 static $total_agents;
8 static $filtered_total_agents;
9
10
11 public static function quick_agent_btn_html( $agent_id = false, $params = array() ) {
12 $html = '';
13 if ( $agent_id ) {
14 $params['agent_id'] = $agent_id;
15 }
16 $route = OsRouterHelper::build_route_name( 'agents', !empty($agent_id) ? 'quick_edit' : 'quick_new' );
17
18 $params_str = http_build_query( $params );
19 $html = 'data-os-params="' . esc_attr($params_str) . '"
20 data-os-action="' . esc_attr($route) . '"
21 data-os-output-target="side-panel"
22 data-os-after-call="latepoint_init_quick_agent_form"';
23
24 return $html;
25 }
26
27 /**
28 * @return OsAgentModel[]
29 */
30 public static function get_allowed_active_agents(): array {
31 $agents = new OsAgentModel();
32
33 return $agents->should_be_active()->filter_allowed_records()->get_results_as_models();
34 }
35
36 /**
37 * @param bool $filter_allowed_records
38 *
39 * @return int
40 */
41 public static function count_agents( bool $filter_allowed_records = false ): int {
42 if ( $filter_allowed_records ) {
43 if ( self::$filtered_total_agents ) {
44 return self::$filtered_total_agents;
45 }
46 } else {
47 if ( self::$total_agents ) {
48 return self::$total_agents;
49 }
50 }
51 $agents = new OsAgentModel();
52 if ( $filter_allowed_records ) {
53 $agents->filter_allowed_records();
54 }
55 $agents = $agents->should_be_active()->get_results_as_models();
56 if ( $filter_allowed_records ) {
57 self::$filtered_total_agents = $agents ? count( $agents ) : 0;
58
59 return self::$filtered_total_agents;
60 } else {
61 self::$total_agents = $agents ? count( $agents ) : 0;
62
63 return self::$total_agents;
64 }
65 }
66
67
68 public static function create_default_agent() {
69 $agent_model = new OsAgentModel();
70
71 $current_user = wp_get_current_user();
72
73 $agent_model->first_name = $current_user->user_firstname ?? '';
74 $agent_model->last_name = $current_user->user_lastname ?? '';
75 $agent_model->email = get_bloginfo( 'admin_email' );
76 if ( $agent_model->save() ) {
77 $connector = new OsConnectorModel();
78 $incomplete_connections = $connector->where( [ 'agent_id' => 'IS NULL' ] )->get_results_as_models();
79 if ( $incomplete_connections ) {
80 foreach ( $incomplete_connections as $incomplete_connection ) {
81 $incomplete_connection->update_attributes( [ 'agent_id' => $agent_model->id ] );
82 }
83 }
84 $bookings = new OsBookingModel();
85 $incomplete_bookings = $bookings->where( [ 'agent_id' => 'IS NULL' ] )->get_results_as_models();
86 if ( $incomplete_bookings ) {
87 foreach ( $incomplete_bookings as $incomplete_booking ) {
88 $incomplete_booking->update_attributes( [ 'agent_id' => $agent_model->id ] );
89 }
90 }
91 }
92
93 return $agent_model;
94 }
95
96
97 public static function get_default_agent(): OsAgentModel {
98 $agent_model = new OsAgentModel();
99 $agent = $agent_model->should_be_active()->set_limit( 1 )->get_results_as_models();
100 if ( $agent && $agent->id ) {
101 return $agent;
102 } else {
103 // no active agents found, try searching disabled agent
104 $disabled_agent = $agent_model->set_limit( 1 )->get_results_as_models();
105 // create agent only if we truly haven't found anything unfiltered
106 if ( $disabled_agent && $disabled_agent->id ) {
107 return $disabled_agent;
108 } else {
109 return self::create_default_agent();
110 }
111 }
112 }
113
114
115 public static function get_default_agent_id() {
116 $agent = self::get_default_agent();
117
118 return $agent->is_new_record() ? 0 : $agent->id;
119 }
120
121 public static function generate_summary_for_agent( OsBookingModel $booking ): void {
122 if ( OsAgentHelper::count_agents() > 1 && OsSettingsHelper::is_off( 'steps_hide_agent_info' ) && $booking->agent_id && $booking->agent_id != LATEPOINT_ANY_AGENT ) { ?>
123 <div class="summary-box summary-box-agent-info">
124 <div class="summary-box-heading">
125 <div class="sbh-item"><?php esc_html_e( 'Agent', 'latepoint' ) ?></div>
126 <div class="sbh-line"></div>
127 </div>
128 <div class="summary-box-content with-media">
129 <div class="os-avatar-w"
130 style="background-image: url(<?php echo ( $booking->agent->avatar_image_id ) ? esc_url($booking->agent->get_avatar_url()) : ''; ?>)">
131 <?php if ( ! $booking->agent->avatar_image_id ) {
132 echo '<div class="os-avatar"><span>' . esc_html($booking->agent->get_initials()) . '</span></div>';
133 } ?>
134 </div>
135 <div class="sbc-content-i">
136 <div class="sbc-main-item"><?php echo esc_html($booking->agent->full_name); ?></div>
137 <?php
138 if ( OsSettingsHelper::steps_show_agent_bio() ) {
139 echo '<div class="os-trigger-item-details-popup sbc-link-item" data-item-details-popup-id="osItemDetailsPopupAgent_' . esc_attr($booking->agent_id) . '">' . esc_html__( 'Learn More', 'latepoint' ) . '</div>';
140 echo OsAgentHelper::generate_bio( $booking->agent );
141 }
142 ?>
143 </div>
144 </div>
145 </div>
146 <?php
147 }
148 }
149
150 public static function generate_agents_list( array $agents ): void {
151 if ( ! empty( $agents ) ) { ?>
152 <div class="os-agents os-animated-parent os-items os-selectable-items os-as-grid os-three-columns">
153 <?php $show_agent_bio = OsSettingsHelper::steps_show_agent_bio(); ?>
154 <?php if ( OsSettingsHelper::is_on( 'allow_any_agent' ) ) { ?>
155 <div class="os-animated-child os-item os-selectable-item"
156 data-summary-field-name="agent"
157 data-summary-value="<?php esc_attr_e( 'Any Agent', 'latepoint' ); ?>"
158 data-id-holder=".latepoint_agent_id"
159 data-cart-item-item-data-key="agent_id"
160 data-item-id="<?php echo esc_attr(LATEPOINT_ANY_AGENT); ?>">
161 <div class="os-animated-self os-item-i">
162 <div class="os-item-img-w os-with-avatar">
163 <div class="os-avatar"
164 style="background-image: url(<?php echo esc_url(LATEPOINT_IMAGES_URL . 'default-avatar.jpg'); ?>);"></div>
165 </div>
166 <div class="os-item-name-w">
167 <div class="os-item-name"><?php esc_html_e( 'Any Agent', 'latepoint' ); ?></div>
168 </div>
169 </div>
170 </div>
171 <?php } ?>
172 <?php foreach ( $agents as $agent ) { ?>
173 <div class="os-animated-child os-item os-selectable-item <?php echo $show_agent_bio ? 'with-details' : ''; ?>"
174 tabindex="0"
175 data-summary-field-name="agent"
176 data-summary-value="<?php echo esc_attr( $agent->name_for_front ); ?>"
177 data-id-holder=".latepoint_agent_id"
178 data-cart-item-item-data-key="agent_id"
179 data-item-id="<?php echo esc_attr($agent->id); ?>">
180 <div class="os-animated-self os-item-i">
181 <div class="os-item-img-w os-with-avatar">
182 <div class="os-avatar"
183 style="background-image: url(<?php echo esc_url($agent->avatar_url); ?>);"></div>
184 </div>
185 <div class="os-item-name-w">
186 <div class="os-item-name"><?php echo esc_html($agent->name_for_front); ?></div>
187 </div>
188 <?php if ( $show_agent_bio ) { ?>
189 <div class="os-item-details-popup-btn os-trigger-item-details-popup"
190 data-item-details-popup-id="osItemDetailsPopupAgent_<?php echo esc_attr($agent->id); ?>">
191 <span><?php esc_html_e( 'Learn More', 'latepoint' ); ?></span></div>
192 <?php } ?>
193 </div>
194 </div>
195 <?php } ?>
196 </div>
197 <?php
198 if ( $show_agent_bio ) {
199 foreach ( $agents as $agent ) {
200 echo OsAgentHelper::generate_bio( $agent );
201 }
202 }
203 }
204 }
205
206 public static function generate_bio( OsAgentModel $agent ) {
207 $html = '';
208 $agent_features_html = '';
209 foreach ( $agent->features_arr as $feature ) {
210 $agent_features_html .= '<div class="item-details-popup-feature">
211 <div class="item-details-popup-feature-value">' . esc_html( $feature['value'] ) . '</div>
212 <div class="item-details-popup-feature-label">' . esc_html( $feature['label'] ) . '</div>
213 </div>';
214 }
215 $html .= '<div class="os-item-details-popup" id="osItemDetailsPopupAgent_' . $agent->id . '">
216 <a href="#" class="os-item-details-popup-close"><span>' . __( 'Close Details', 'latepoint' ) . '</span><i class="latepoint-icon latepoint-icon-common-01"></i></a>
217 <div class="os-item-details-popup-inner">
218 <div class="item-details-popup-head" style="background-image: url(' . esc_url( $agent->bio_image_url ) . ')">
219 <h3>' . esc_html( $agent->name_for_front ) . '</h3>
220 <div class="item-details-popup-title">' . esc_html( $agent->title ) . '</div>
221 </div>
222 <div class="item-details-popup-content">
223 <img class="bio-curve" src="' . LATEPOINT_IMAGES_URL . 'white-curve.png" alt="">
224 <div class="item-details-popup-features">' . $agent_features_html . '</div>
225 <div class="item-details-popup-content-i">
226 ' . esc_html( $agent->bio ) . '
227 </div>
228 </div>
229 </div>
230 </div>';
231
232 return $html;
233 }
234
235 public static function generate_day_schedule_info( $filter ) {
236 $today_date = new OsWpDateTime( 'today' );
237 $target_date = new OsWpDateTime( $filter->date_from ); ?>
238 <div class="agent-schedule-info">
239 <div class="agent-today-info">
240 <?php echo ( $target_date->format( 'Y-m-d' ) == $today_date->format( 'Y-m-d' ) ) ? esc_html__( 'Today', 'latepoint' ) : esc_html($target_date->format( OsSettingsHelper::get_readable_date_format() )); ?>
241 <?php
242
243 $booking_request = new \LatePoint\Misc\BookingRequest();
244 $booking_request->agent_id = $filter->agent_id;
245 $booking_request->start_date = $target_date->format( 'Y-m-d' );
246 $resources = OsResourceHelper::get_resources_grouped_by_day( $booking_request, $target_date, $target_date );
247
248 $day_work_periods = [];
249
250 $periods = [];
251 foreach ( $resources[ $target_date->format( 'Y-m-d' ) ] as $resource ) {
252 if ( ! empty( $resource->work_time_periods ) ) {
253 foreach ( $resource->work_time_periods as $work_time_period ) {
254 if ( $work_time_period->start_time == $work_time_period->end_time ) {
255 continue;
256 }
257 $periods[] = $work_time_period->start_time . ':' . $work_time_period->end_time;
258 }
259 }
260 }
261 $periods = array_unique( $periods );
262 foreach ( $periods as $work_time_period ) {
263 $period = explode( ':', $work_time_period );
264 $work_time_period = new \LatePoint\Misc\WorkPeriod();
265 $work_time_period->start_time = $period[0];
266 $work_time_period->end_time = $period[1];
267 $day_work_periods[] = $work_time_period;
268 }
269
270 $is_working_today = ! empty( $day_work_periods );
271 ?>
272 <span class="today-status <?php echo ( $is_working_today ) ? 'is-on-duty' : 'is-off-duty'; ?>"><?php echo ( $is_working_today ) ? esc_html__( 'On Duty', 'latepoint' ) : esc_html__( 'Off Duty', 'latepoint' ); ?></span>
273 <div class="today-schedule">
274 <?php if ( $is_working_today ) { ?>
275 <?php foreach ( $day_work_periods as $period ) {
276 echo '<span>' . esc_html(OsTimeHelper::minutes_to_hours_and_minutes( $period->start_time ) . ' - ' . OsTimeHelper::minutes_to_hours_and_minutes( $period->end_time )) . '</span>';
277 } ?>
278 <?php } else {
279 esc_html_e( 'Not Available', 'latepoint' );
280 } ?>
281 </div>
282 </div>
283 <div class="today-bookings">
284 <?php esc_html_e( 'Bookings', 'latepoint' ); ?>
285 <div class="today-bookings-count"><?php echo esc_html(OsBookingHelper::count_bookings( $filter )); ?></div>
286 </div>
287 </div>
288 <?php
289 }
290
291 public static function get_full_name( $agent ) {
292 return join( ' ', array( $agent->first_name, $agent->last_name ) );
293 }
294
295
296 public static function get_agent_ids_for_service_and_location( $service_id = false, $location_id = false ): array {
297 $all_agent_ids = OsConnectorHelper::get_connected_object_ids( 'agent_id', [
298 'service_id' => $service_id,
299 'location_id' => $location_id
300 ] );
301 $agents = new OsAgentModel();
302 $active_agent_ids = $agents->select( 'id' )->should_be_active()->get_results( ARRAY_A );
303 if ( $active_agent_ids ) {
304 $active_agent_ids = array_column( $active_agent_ids, 'id' );
305 $all_agent_ids = array_intersect( $active_agent_ids, $all_agent_ids );
306 } else {
307 $all_agent_ids = [];
308 }
309
310 return $all_agent_ids;
311 }
312
313
314 /**
315 * @param bool $filter_allowed_records
316 * @param array $agent_ids
317 *
318 * @return array
319 */
320 public static function get_agents_list( bool $filter_allowed_records = false, array $agent_ids = [] ): array {
321 $agents = new OsAgentModel();
322 if ( $filter_allowed_records ) {
323 $agents->filter_allowed_records();
324 }
325
326 if (!empty($agent_ids)) {
327 $agents->where_in( 'id', $agent_ids );
328 }
329
330 $agents = $agents->get_results_as_models();
331 $agents_list = [];
332 if ( $agents ) {
333 foreach ( $agents as $agent ) {
334 $agents_list[] = [ 'value' => $agent->id, 'label' => $agent->full_name ];
335 }
336 }
337
338 return $agents_list;
339 }
340
341 public static function get_avatar_url( $agent ) {
342 $default_avatar = LATEPOINT_DEFAULT_AVATAR_URL;
343
344 return OsImageHelper::get_image_url_by_id( $agent->avatar_image_id, 'thumbnail', $default_avatar );
345 }
346
347 public static function get_bio_image_url( $agent ) {
348 $default_bio_image = LATEPOINT_DEFAULT_AVATAR_URL;
349
350 return OsImageHelper::get_image_url_by_id( $agent->bio_image_id, 'large', $default_bio_image );
351 }
352 }