php [约会] - 显示不可用的约会计划段的最后计划用户名。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [约会] - 显示不可用的约会计划段的最后计划用户名。相关的知识,希望对你有一定的参考价值。
<?php
/*
Plugin Name: Show Last User in Calendar
Description: Shows last scheduled user name for unavailable appointment schedule segments.
Plugin URI: http://premium.wpmudev.org/project/appointments-plus/
Version: 1.0
AddonType: Schedule
Author: Panos @ WPMU DEV
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WPMUDEV_App_Last_Scheduled_User' ) ) {
class WPMUDEV_App_Last_Scheduled_User {
private static $_instance = null;
public static function get_instance() {
if( is_null( self::$_instance ) ){
self::$_instance = new WPMUDEV_App_Last_Scheduled_User();
}
return self::$_instance;
}
private function __construct() {
if( ! function_exists( 'appointments_delete_timetables_cache' ) ){
return;
}
appointments_delete_timetables_cache();
add_filter( 'app-schedule_cell-title', array( $this, 'process_cell_title' ), 10, 5 );
add_action( 'wp_footer', array( $this, 'footer_scripts' ), 10 );
add_action( 'wp_head', array( $this, 'head_styles' ), 10 );
}
public function process_cell_title ($title, $is_busy, $start, $end, $schedule_key) {
if ( ! $is_busy || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ){
return $title;
}
$customers = $this->_get_appointments_by_interval($start, $end, $schedule_key);
if (empty($customers)) return $title;
$names = join("\n", array_unique(wp_list_pluck($customers, 'name')));
return $names;
}
private function _get_appointments_by_interval ($start, $end, $schedule_key) {
$apps = $this->_get_appointments_for_scheduled_interval($schedule_key, $start);
if (!$apps) return false;
$ret = array();
$period = new App_Period($start, $end);
foreach ($apps as $app) {
if ($period->contains($app->start, $app->end)) $ret[] = $app;
}
return $ret;
}
private function _get_appointments_for_scheduled_interval( $schedule_key, $start ) {
$data = explode( 'x', $schedule_key );
if ( count( $data ) != 2 ) {
$interval_start = current_time( 'timestamp' );
$interval_end = strtotime( 'next month', $interval_start );
} else {
$interval_start = $data[0];
$interval_end = $data[1];
}
$appointments = appointments();
$args = array(
'status' => array( 'pending', 'paid', 'confirmed', 'reserved' )
);
if ( $appointments->service ) {
$args['service'] = $appointments->service;
}
if ( $appointments->worker ) {
$args['worker'] = $appointments->service;
}
$start = date( "Y-m-d H:i:s", $start );
$args['date_query'] = array(
array(
'field' => 'start',
'compare' => '=',
'value' => $start
)
);
$args['order'] = 'DESC';
$args['per_page'] = 1;
$apps = appointments_get_appointments( $args );
$res = array();
foreach ( $apps as $app ) {
if ( strtotime( $app->start ) > $interval_start && strtotime( $app->end ) < $interval_end ) {
$res[] = $app;
}
}
return $res;
}
public function footer_scripts(){
global $post;
if ( ! has_shortcode( $post->post_content, 'app_monthly_schedule' ) ) {
return;
}
?>
<script type="text/javascript">
(function($){
$(document).ready(function(){
$( '.app_timetable_cell.busy' ).each(function(){
const el = $(this);
let title = el.attr( 'title' );
if( ! app_isDate( title ) ){
el.append( '<div class="app_user">' + title + '</div>' );
}
});
});
})(jQuery);
let app_isDate = function(date) {
return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));
}
</script>
<?php
}
public function head_styles(){
global $post;
if ( ! has_shortcode( $post->post_content, 'app_monthly_schedule' ) ) {
return;
}
?>
<style type="text/css">
.app_timetable_cell{
min-height: 45px;
}
.app_timetable_cell .app_user{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
<?php
}
}
add_action( 'plugins_loaded', function(){
$GLOBALS['WPMUDEV_App_Last_Scheduled_User'] = WPMUDEV_App_Last_Scheduled_User::get_instance();
}, 10 );
}
以上是关于php [约会] - 显示不可用的约会计划段的最后计划用户名。的主要内容,如果未能解决你的问题,请参考以下文章