use App\Enablex\Campaign;
use App\Enablex\CampaignFaceaiWidget;
use App\Enablex\CandidateCampaignTrack;
use App\Enablex\City;
use App\Enablex\Client;
use App\Enablex\Company;
use App\Enablex\CompanyFaceaiWidget;
use App\Enablex\Country;
use App\Enablex\FaceaiWidget;
use App\Enablex\Invitee;
use App\Enablex\InviteesInterview;
use App\Enablex\State;
use App\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
if (!function_exists('user_email')) {
function user_email()
{
$user = Auth::user();
return $user->email;
}
}
if (!function_exists('get_logo')) {
function get_logo()
{
return asset('branding/' . Auth::user()->company->logo);
}
}
if (!function_exists('get_favicon')) {
function get_favicon()
{
return asset('branding/' . Auth::user()->company->favicon);
}
}
if (!function_exists('get_user_timezone')) {
function get_user_timezone()
{
if(auth()->check())
$timezone = Auth::user()->company->timezone;
else
$timezone = 'Asia/Kolkata';
return $timezone;
}
}
if (!function_exists('get_current_date_time')) {
function get_current_date_time($format = 'Y-m-d')
{
$timezone = get_user_timezone();
$date = Carbon::now();
return $date->setTimezone($timezone)->format($format);
}
}
if (!function_exists('get_current_day')) {
function get_current_day()
{
$timezone = get_user_timezone();
$day = Carbon::now()->format('l');
return $day;
}
}
if (!function_exists('utc_to_current_date_time')) {
function utc_to_current_date_time($date, $format = 'Y-m-d')
{
$timezone = get_user_timezone();
$date = Carbon::parse($date);
return $date->setTimezone($timezone)->format($format);
}
}
if (!function_exists('utc_to_current_time')) {
function utc_to_current_time($date, $format = 'H:i')
{
$timezone = get_user_timezone();
$date = Carbon::parse($date);
return $date->setTimezone($timezone)->format($format);
}
}
if (!function_exists('get_company_id')) {
function get_company_id()
{
return Auth::user()->company->id;
}
}
if (!function_exists('does_company_have_interviewer')) {
function does_company_have_interviewer()
{
$has_interviers = false;
if (Company::find(Auth::user()->company->id)->interviewers->isNotEmpty()) {
$has_interviers = true;
}
return $has_interviers;
}
}
if (!function_exists('get_company')) {
function get_company()
{
$host = request()->getHttpHost();
$company = Company::select('id', 'company', 'legal_name', 'logo', 'favicon', 'tnc', 'pp', 'portal_domain')->where('portal_domain', $host)->first();
if (!$company) {
$company = Company::select('id', 'company', 'legal_name', 'logo', 'favicon', 'tnc', 'pp', 'portal_domain')->first();
}
return $company;
}
}
if (!function_exists('getCompanyUrl')) {
function getCompanyUrl($company_id)
{
$company = Company::find($company_id);
$app_url = config('app.url');
if (isset($company->portal_domain)) {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$scheme = "https://";
} else {
$scheme = "http://";
}
$app_url = $scheme . '' . $company->portal_domain;
}
return $app_url;
}
}
if (!function_exists('get_active_campaigns')) {
function get_active_campaigns($company , $screening=false, $interview=false)
{
$query = Campaign::query();
if($screening){
$query->where('go_screening', 'Y');
}
if($interview){
$query->where('go_interview', 'Y');
}
if (auth()->user()->user_type === config('app.user_type.customer_executive')) {
$query->where('user_id', auth()->user()->id );
}
if (is_array($company)) {
$query->whereIn('company_id', $company);
} else {
$query->where('company_id', $company);
}
$query->orderBy('campaign', 'ASC');
// $active_campaigns = $query->where('close_date', '>=', Carbon::now('UTC')->addMinutes(5)->format('Y-m-d H:i:s'))
// ->where('start_date', '>=', Carbon::now('UTC')->addMinutes(5)->format('Y-m-d H:i:s'))
$active_campaigns = $query->pluck('campaign', 'id');
return $active_campaigns;
}
}
/**
* Function to return option list for the select box with the selected options.
* @param array $list_array
* @param string $sel_value
* @return string
*/
if (!function_exists('create_OptionList')) {
function create_OptionList($list_array = [], $sel_value = "", $newlink='')
{
$list = "";
if($newlink !='')
$list = '';
foreach ($list_array as $key => $value) {
$sel = $key == $sel_value ? "selected='selected'" : "";
$list .= "";
}
return $list;
}
}
if (!function_exists('create_MultiOptionList')) {
function create_MultiOptionList($list_array = [], $sel_arr = [], $newlink='')
{
$list = "";
if($newlink !='')
$list = '';
foreach ($list_array as $key => $value) {
$sel = in_array($key, $sel_arr) ? "selected='selected'" : "";
$list .= "";
}
return $list;
}
}
if (!function_exists('get_duration_array')) {
function get_duration_array()
{
return $duration = [
'30' => '30 Minutes',
'60' => '60 Minutes',
'90' => '90 Minutes',
'120' => '120 Minutes',
];
}
}
if (!function_exists('get_company_users')) {
function get_company_users($company_id, $orderByColoumn='first_name', $orderBy='ASC')
{
return User::where('company_id', $company_id)
->where('user_type', 'CE')
->where('status', 'A')
->orderBy($orderByColoumn, $orderBy)
->get()
->pluck('full_name', 'id');
}
}
if (!function_exists('get_company_clients')) {
function get_company_clients($company_id, $orderByColoumn='company_name', $orderBy='ASC')
{
return Client::where('company_id', $company_id)
->orderBy($orderByColoumn, $orderBy)
->get()
->pluck('company_name', 'id');
}
}
if (!function_exists('get_countries_list')) {
function get_countries_list()
{
return Country::orderBy('country_name', 'ASC')
->get()
->pluck('country_name', 'country_code');
}
}
if (!function_exists('get_countries_list_with_id')) {
function get_countries_list_with_id()
{
return Country::orderBy('country_name', 'ASC')
->get()
->pluck('country_name', 'id');
}
}
if (!function_exists('get_states_list')) {
function get_states_list()
{
return State::orderBy('name', 'ASC')
->get()
->pluck('name','id');
}
}
if (!function_exists('get_cities_list')) {
function get_cities_list()
{
return City::orderBy('name', 'ASC')
->get()
->pluck('name', 'id');
}
}
if (!function_exists('get_country_by_code')) {
function get_country_by_code($country_code)
{
if($country_code!=''){
$country = Country::select('country_name')->where('country_code', $country_code)->first();
return $country->country_name;
}
return '';
}
}
if (!function_exists('get_country_code_by_name')) {
function get_country_code_by_name($country_name)
{
if($country_name !=''){
$country = Country::select('country_code')->where('country_name', $country_name)->first();
return $country->country_code;
}
return '';
}
}
if (!function_exists('get_timezone_list')) {
function get_timezone_list($default_selected = '')
{
$tzlist = array_combine(DateTimeZone::listIdentifiers(DateTimeZone::ALL), DateTimeZone::listIdentifiers(DateTimeZone::ALL));
return create_OptionList($tzlist, $default_selected);
}
}
if (!function_exists('display_date')) {
function display_date($date, $format = "")
{
$date = Carbon::createFromFormat('Y-m-d H:i:s', $date, 'UTC');
return $date->setTimezone(!empty(auth()->user()->company->timezone) ? auth()->user()->company->timezone : config('app.timezone'))->format($format);
}
}
if (!function_exists('get_company_faceai_widgets')) {
function get_company_faceai_widgets($company_id)
{
$company = Company::where('id', $company_id)->first();
return $company->faceai_widgets;
}
}
if (!function_exists('company_face_widget_checkif_is_default_true')) {
function company_face_widget_checkif_is_default_true($company_id, $widget_id)
{
$is_default = 'N';
$companyWidget = CompanyFaceaiWidget::select('is_default')->where('company_id', $company_id)
->where('faceai_widget_id', $widget_id)
->first();
if ($companyWidget) {
$is_default = $companyWidget->is_default;
}
return $is_default;
}
}
if (!function_exists('company_face_widget_check_order')) {
function company_face_widget_check_order($company_id, $widget_id)
{
$order_by = '';
$companyWidget = CompanyFaceaiWidget::select('order_by')->where('company_id', $company_id)
->where('faceai_widget_id', $widget_id)
->first();
if ($companyWidget) {
$order_by = $companyWidget->order_by;
}
return $order_by;
}
}
if (!function_exists('campaign_face_widget_check_order')) {
function campaign_face_widget_check_order($campaign_id, $widget_id)
{
$order_by = '';
$campaignWidget = CampaignFaceaiWidget::select('order_by')->where('campaign_id', $campaign_id)
->where('faceai_widget_id', $widget_id)
->first();
if ($campaignWidget) {
$order_by = $campaignWidget->order_by;
}
return $order_by;
}
}
function get_dynamic_table_head_face_ai($widget, $showSorting=false)
{
$faceai_th_html = '';
$head_count = 0;
$faceai['count'] = 0;
$faceai['html'] = '';
$faceai = [];
if ($widget) {
$widget_array = explode(',', str_replace(' ', '', $widget));
$head_count = count($widget_array);
$faceai['count'] = $head_count;
$f_html = view('_partials.face-ai-header', compact('widget_array', 'showSorting'))->render();
$faceai['html'] = $f_html ;
// foreach ($widget_array as $widget) {
// $faceai_th_html .= '
' . $widget . ' | ';
// $faceai['html'] = $faceai_th_html;
// }
}
return $faceai;
}
if (!function_exists('get_dynamic_head_face_ai')) {
function get_dynamic_head_face_ai($widget)
{
$faceai_head = [];
if ($widget) {
$widget_array = explode(',', str_replace(' ', '', $widget));
foreach ($widget_array as $widget) {
$faceai_head[] = $widget;
}
}
return $faceai_head;
}
}
if (!function_exists('get_dynamic_table_data_face_ai_screening_arr')) {
function get_dynamic_table_data_face_ai_screening_arr($widget, $invite)
{
$campaign = Campaign::select('company_id')->where('id', $invite->campaign_id)->first();
$threshold = getCompanyFaceAIThreshold($campaign->company_id);
$td_html = '';$widgetArr=[];
if ($widget) {
$widget_array = explode(',', str_replace(' ', '', $widget));
foreach ($widget_array as $widget) {
if ($widget === 'Attention') {
$widgetArr['Attention']= $invite->average_attention ;
}
if ($widget === 'Confident') {
$widgetArr['Confident']= $invite->average_confident ;
}
if ($widget === 'Interested') {
$widgetArr['Interested']= $invite->average_interested ;
}
if ($widget === 'Determined') {
$widgetArr['Determined']= $invite->average_determined ;
}
if ($widget === 'Enthusiastic') {
$widgetArr['Enthusiastic']= $invite->average_enthusiastic ;
}
if ($widget === 'Happy') {
$widgetArr['Happy']= $invite->average_happy ;
}
if ($widget === 'Relaxed') {
$widgetArr['Relaxed']= $invite->average_relaxed ;
}
if ($widget === 'Anxious') {
$widgetArr['Anxious']= $invite->average_anxious ;
}
if ($widget === 'Uncomfortable') {
$widgetArr['Uncomfortable']= $invite->average_uncomfortable ;
}
if ($widget === 'Bored') {
$widgetArr['Bored']= $invite->average_bored ;
}
if ($widget === 'Dissatisfied') {
$widgetArr['Dissatisfied']= $invite->average_dissatisfied ;
}
if ($widget === 'Age') {
$widgetArr['Age']= $invite->average_age ;
}
if ($widget === 'Gender') {
$widgetArr['Gender']= $invite->invite_gender ;
}
if ($widget === 'AssessmentScore') {
$widgetArr['AssessmentScore']= $invite->assessment_score ;
}
}
}
return $widgetArr;
}
}
if (!function_exists('get_dynamic_table_data_face_ai_screening')) {
function get_dynamic_table_data_face_ai_screening($widget, $invite)
{
$td_html = '';
if ($widget) {
$widget_array = explode(',', str_replace(' ', '', $widget));
foreach ($widget_array as $widget) {
if ($widget === 'Attention') {
$td_html .= '' . $invite->average_attention . ' | ';
}
if ($widget === 'Confident') {
$td_html .= '' . $invite->average_confident . ' | ';
}
if ($widget === 'Interested') {
$td_html .= '' . $invite->average_interested . ' | ';
}
if ($widget === 'Determined') {
$td_html .= '' . $invite->average_determined . ' | ';
}
if ($widget === 'Enthusiastic') {
$td_html .= '' . $invite->average_enthusiastic . ' | ';
}
if ($widget === 'Happy') {
$td_html .= '' . $invite->average_happy . ' | ';
}
if ($widget === 'Relaxed') {
$td_html .= '' . $invite->average_relaxed . ' | ';
}
if ($widget === 'Anxious') {
$td_html .= '' . $invite->average_anxious . ' | ';
}
if ($widget === 'Uncomfortable') {
$td_html .= '' . $invite->average_uncomfortable . ' | ';
}
if ($widget === 'Bored') {
$td_html .= '' . $invite->average_bored . ' | ';
}
if ($widget === 'Dissatisfied') {
$td_html .= '' . $invite->average_dissatisfied . ' | ';
}
if ($widget === 'Age') {
$td_html .= '' . $invite->average_age . ' | ';
}
if ($widget === 'Gender') {
$td_html .= '' . $invite->invite_gender . ' | ';
}
}
}
return $td_html;
}
}
if (!function_exists('get_dynamic_data_face_ai_screening_for_export')) {
function get_dynamic_data_face_ai_screening_for_export($widget, $invite)
{
$data_val = '';
if ($widget === 'Attention') {
$data_val = $invite->average_attention;
}
if ($widget === 'Confident') {
$data_val = $invite->average_confident;
}
if ($widget === 'Interested') {
$data_val = $invite->average_interested;
}
if ($widget === 'Determined') {
$data_val = $invite->average_determined;
}
if ($widget === 'Enthusiastic') {
$data_val = $invite->average_enthusiastic;
}
if ($widget === 'Happy') {
$data_val = $invite->average_happy;
}
if ($widget === 'Relaxed') {
$data_val = $invite->average_relaxed;
}
if ($widget === 'Anxious') {
$data_val = $invite->average_anxious;
}
if ($widget === 'Uncomfortable') {
$data_val = $invite->average_uncomfortable;
}
if ($widget === 'Bored') {
$data_val = $invite->average_bored;
}
if ($widget === 'Dissatisfied') {
$data_val = $invite->average_dissatisfied;
}
if ($widget === 'Age') {
$data_val = $invite->average_age;
}
if ($widget === 'Gender') {
$data_val = $invite->invite_gender;
}
return $data_val;
}
}
if (!function_exists('convertTimeToSecond')) {
function convertTimeToSecond(string $time): int
{
$d = explode(':', $time);
return ($d[0] * 3600) + ($d[1] * 60) + $d[2];
}
}
if (!function_exists('getStarByRating')) {
function getStarByRating($rating=1){
$starHtml = '';
if($rating == '5'){
$starHtml = '
';
}else if($rating == '4'){
$starHtml = '
';
}else if($rating == '3'){
$starHtml = '
';
}else if($rating == '2'){
$starHtml = '
';
}else if($rating == '1'){
$starHtml = '
';
}else {
$starHtml = '
';
}
return $starHtml;
}
}
if (!function_exists('getStarByRatingForDisplay')) {
function getStarByRatingForDisplay($rating=1){
$starHtml = '';
if ($rating == 5){
$starHtml .= '
';
} elseif($rating == 4){
$starHtml .= '
';
}
elseif($rating == 3){
$starHtml .= '
';
}
elseif($rating == 2){
$starHtml .= '
';
}
elseif($rating == 1){
$starHtml .= '
';
}
else{
$starHtml .= '
';
}
$starHtml .= '
';
return $starHtml;
}
}
if (!function_exists('screening_filters')) {
function screening_filters()
{
return [
'' => '-- All --',
// config('app.screening_cancelled') => 'Cancelled',
config('app.screening_feedback_pending') => 'Feedback Pending',
config('app.screening_hold') => 'Hold',
config('app.screening_invited') => 'Invited',
config('app.interview_invited') => 'Interview Invited',
// config('app.offered') => 'Offered',
config('app.screening_rejected') => 'Rejected',
config('app.screening_shortlisted') => 'Shortlisted'
];
}
}
if (!function_exists('interview_filters')) {
function interview_filters()
{
return [
'' => '-- All --',
// config('app.interview_cancelled') => 'Cancelled',
config('app.interview_feedback_pending') => 'Feedback Pending',
config('app.interview_hold') => 'Hold',
config('app.interview_invited') => 'Invited',
// config('app.offered') => 'Offered',
config('app.interview_rejected') => 'Rejected',
config('app.interview_shortlisted') => 'Shortlisted'
];
}
}
if (!function_exists('get_faceai_components_widgets')) {
function get_faceai_components_widgets($camaignId)
{
$campaign = Campaign::where('id', $camaignId)->first();
$faceai_models = '';
if ($campaign->faceai_widgets) {
$faceai_components['faceai'] = explode(',', $campaign->faceai_component_list);
$faceai_models = base64_encode(json_encode($faceai_components));
} else if (auth()->user()->company->faceai_widgets->count()) {
$faceai_components['faceai'] = explode(',', auth()->user()->company->faceai_component_list);
$faceai_models = base64_encode(json_encode($faceai_components));
}
return $faceai_models;
}
}
if (!function_exists('screening_actions')) {
function screening_actions($inviteId)
{
$query = Invitee::query();
// $query->where('id', 54);
$query->withTrashed();
$query->where('id', $inviteId);
$query->with('candidate', 'campaign', 'recording');
$screening = $query->first();
$faceai_models = get_faceai_components_widgets($screening->campaign_id);
$app_url = getCompanyUrl($screening->campaign->company->id);
$link = $app_url . '/candidate/campaign/screening?access=' . $screening->key . '&faceai=' . $faceai_models;
$screening->link = $link;
$screening->record = $screening->recording;
$ifInvitedForInterview = InviteesInterview::where('campaign_id', $screening->campaign_id)->where('candidate_id', $screening->candidate_id)->where('status', '!=', config('app.interview_cancelled'))->first();
return view('clients.actions.screening-actions', compact('screening', 'ifInvitedForInterview'));
}
}
if (!function_exists('interview_actions')) {
function interview_actions($inviteId)
{
$query = InviteesInterview::query();
// $query->where('id', 54);
$query->withTrashed();
$query->where('id', $inviteId);
$query->with('candidate', 'campaign', 'recordings', 'interviewers');
$interview = $query->first();
$faceai_models = get_faceai_components_widgets($interview->campaign_id);
$app_url = getCompanyUrl($interview->campaign->company->id);
if ((Carbon::parse($interview->getInterviewDateNormal())->addMinutes($interview->duration)->format('Y-m-d H:i') > utc_to_current_date_time(Carbon::now()->format('Y-m-d H:i'), 'Y-m-d H:i'))) {
$interview->copy_links = true;
} else {
$interview->copy_links = false;
}
$app_url = getCompanyUrl($interview->campaign->company_id);
$interview->app_url = $app_url;
$participant_access = base64_encode('campaign_id=' . $interview->campaign->id . '&candidate_id=' . $interview->candidate->id . '&email=' . $interview->candidate->email);
$p_link = $app_url . '/candidate/campaign/interview?access=' . $participant_access;
$interview->p_link = $p_link;
return view('clients.actions.interview-actions', compact('interview'));
}
if (!function_exists('ifInterviewCandidateHadGivenScreening')) {
function ifInterviewCandidateHadGivenScreening($campaign_id, $candidate_id)
{
$screening = '';
$invitee = Invitee::where('campaign_id', $campaign_id)->where('candidate_id', $candidate_id)->first();
if($invitee){
$screening = $invitee->id;
}
return $screening;
}
}
if (!function_exists('ifScreeningCandidateHadGivenInterview')) {
function ifScreeningCandidateHadGivenInterview($campaign_id, $candidate_id)
{
$interview = '';
$invitee = InviteesInterview::where('campaign_id', $campaign_id)->where('candidate_id', $candidate_id)->first();
if($invitee){
$interview = $invitee->id;
}
return $interview;
}
}
if (!function_exists('getCompanyFaceAIThreshold')) {
function getCompanyFaceAIThreshold($companyId)
{
$company = Company::where('id', $companyId)->first();
return (int) $company->face_ai_threshold;
}
}
if (!function_exists('statusBreak')) {
function statusBreak($status)
{
$pos = 1;
$string = $status;
$words = explode(" ", $string);
array_splice($words, $pos, 0, '
');
$new_string = join(" ", $words);
return $new_string;
}
}
if (!function_exists('updateCandidateTrack')) {
function updateCandidateTrack($candidate_id, $campaign_id, $status)
{
$query = CandidateCampaignTrack::query();
$query->where('campaign_id', $campaign_id)->where('candidate_id', $candidate_id);
$candidate = $query->first();
if ($candidate) {
$candidate->status = config('app.status.' . $status);
$candidate->save();
} else {
$candidate_status = new CandidateCampaignTrack();
$candidate_status->candidate_id = $candidate_id;
$candidate_status->campaign_id = $campaign_id;
$candidate_status->status = config('app.status.' . $status);
$candidate_status->save();
}
}
}
if (!function_exists('getFaceAIFilters')) {
function getFaceAIFilters($campaign, $for_interivew=false)
{
$filter = [];
if($for_interivew==false){
$filter['AssessmentScore'] = 'Assessment Score';
}
$widgets = explode(',',$campaign->widget_list);
foreach($widgets as $widget){
$filter[trim($widget)] = trim($widget);
}
return $filter;
}
}
}