$date,'timezone'=>wp_timezone()->getName(),'admin_notes'=>[],'customer_notes'=>[],'cancelled_bookings'=>[]]; foreach($this->repository->daily(Time::sql($from),Time::sql($to)) as $b){ $row=array_intersect_key($b,array_flip(['id','reference','resource_name','customer_name','admin_note','customer_note'])); $row['starts_at']=Time::iso(Time::fromSql($b['starts_at']));$row['ends_at']=Time::iso(Time::fromSql($b['ends_at'])); if($b['status']==='cancelled'){ $id=$b['history_actor_id']??$b['cancelled_by_user_id'];$stamp=$b['history_cancelled_at']??$b['cancelled_at']; $row+=['cancelled_at'=>$stamp?Time::iso(Time::fromSql($stamp)):null,'cancelled_by_name'=>CancellationActor::name($b['cancellation_metadata'],$id,$b['actor_current_name']),'cancelled_by_role'=>CancellationActor::role($b['cancellation_metadata']),'cancellation_reason'=>$b['history_reason']??$b['cancellation_reason']]; $result['cancelled_bookings'][]=$row; }else{ if(trim($b['admin_note']??'')!=='')$result['admin_notes'][]=$row; if(trim($b['customer_note']??'')!=='')$result['customer_notes'][]=$row; } }return $result; } }