Files
Global-Jain/app/Helpers/Helpers.php

1473 lines
45 KiB
PHP
Raw Normal View History

2025-11-05 10:37:10 +05:30
<?php
use Carbon\Carbon;
use App\Models\Jati;
use App\Models\Dharma;
use App\Models\UserMeta;
use App\Constant\Constant;
use App\Models\ChaturmasDate;
use App\Models\BloodGroup;
use App\Models\MotherTongue;
use App\Models\Relationship;
use App\Models\Sampraday;
use App\Models\UserRelation;
use Carbon\CarbonPeriod;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use Illuminate\Contracts\Encryption\DecryptException;
if (!function_exists('app_name')) {
/**
* Helper to grab the application name.
*
* @return mixed
*/
function app_name()
{
return config('app.name');
}
}
if (!function_exists('includeRouteFiles')) {
/**
* Loops through a folder and requires all PHP files
* Searches sub-directories as well.
*
* @param $folder
*/
function includeRouteFiles($folder)
{
try {
$rdi = new recursiveDirectoryIterator($folder);
$it = new recursiveIteratorIterator($rdi);
while ($it->valid()) {
if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
require $it->key();
}
$it->next();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
if (!function_exists('loggedInUser')) {
/**
* Helper to grab the application name.
*
* @return mixed
*/
function loggedInUser()
{
return Auth::user();
}
}
if (!function_exists('loggedUserDetails')) {
/**
* Helper to grab the application name.
*
* @return mixed
*/
function loggedUserDetails($user)
{
$userData = [
'id' => $user->id,
'name' => $user->fullname,
'email' => $user->email,
'role' => $user->roles[0] ? $user->roles[0]['name'] : null
];
return $userData;
}
}
if (!function_exists('getLoggedUserRolesName')) {
/**
* @param $userObj
*
* @return string
*/
function getLoggedUserRolesName($userObj): string
{
$userRolesArray = $userObj->getRoleNames()->toArray();
$rolesName = !empty($userRolesArray) ? implode(', ', $userRolesArray) : '';
$rolesName = ucwords(mb_strtolower($rolesName));
return $rolesName;
}
}
if (!function_exists('jsonToArray')) {
/**
* @param string $name
* @return arrau
*/
function jsonToArray($names)
{
$names = json_decode($names);
if (!empty($names)) {
$nameArray = [];
// Create all tags (unassociet)
foreach ($names as $k => $name) {
array_push($nameArray,$name->value);
}
// dd($nameArray);
return $nameArray;
}
}
}
if (!function_exists('stringToArray')) {
/**
* @param string $name
* @return arrau
*/
function stringToArray($string)
{
if (!empty($string)) {
$stringToArray = explode(',', $string);
return $stringToArray;
}
return '';
}
}
if (!function_exists('uploadFile')) {
/**
* @param $request
* @param string $inputName
* @param string $uploadPath
* @param string $fileName
* @param string $oldFileName
*
* @return array
*/
function uploadFile($request, string $inputName, string $uploadPath, $fileName = '', $oldFileName = ''): array
{
$response = [];
try {
$file = $request->file($inputName);
if (!empty($fileName)) {
$fileName = $fileName . '_' . time() . '.' . $file->getClientOriginalExtension();
} else {
$fileName = time() . '.' . $file->getClientOriginalExtension();
}
$destinationPath = $uploadPath;
if (!empty($oldFileName)) {
deleteFile($destinationPath, $oldFileName);
}
Storage::put($destinationPath . '/' . $fileName, file_get_contents($file));
$response = [
'file_name' => $fileName,
'uploaded_path' => $destinationPath,
];
} catch (\Exception $ex) {
Log::error($ex);
}
return $response;
}
}
if (!function_exists('uploadImage')) {
/**
* @param $request
* @param string $inputName
* @param string $uploadPath
* @param string $oldFileName
*
* @return array
*/
function uploadImage($request, string $inputName, string $uploadPath, $oldFileName = ''): array
{
$image = $request->file($inputName);
$fileName = rand(1, 1000) . time() . '.jpeg';
// $fileName = rand(1, 1000) . time() . '.' . $image->getClientOriginalExtension();
$destinationPath = $uploadPath;
// if (!empty($oldFileName)) {
// deleteFile($destinationPath, $oldFileName);
// Assign old image name in new image for notification issue
// $fileName = substr($oldFileName, 0, strrpos($oldFileName, '.')) . '.' . $image->getClientOriginalExtension();
// $fileName = $oldFileName;
// }
$resizeImage = \Image::make($image->getPathname());
$resizeImage->resize(150, 150, function ($constraint) {
$constraint->aspectRatio();
})->stream();
// Storage::put($destinationPath . '/small/' . $fileName, $resizeImage);
Storage::disk('public')->put($destinationPath . '/small/' . $fileName, $resizeImage);
$resizeImage = \Image::make($image->getPathname());
$resizeImage->resize(300, 300, function ($constraint) {
$constraint->aspectRatio();
})->stream();
// Storage::put($destinationPath . '/medium/' . $fileName, $resizeImage);
Storage::disk('public')->put($destinationPath . '/medium/' . $fileName, $resizeImage);
$resizeImage = \Image::make($image->getPathname())->stream();
// Storage::put($destinationPath . '/' . $fileName, $resizeImage);
Storage::disk('public')->put($destinationPath . '/' . $fileName, $resizeImage);
return [
'image_name' => $fileName,
'uploaded_path' => $destinationPath,
];
}
}
if (!function_exists('uploadMultipleImage')) {
/**
* @param $request
* @param string $inputName
* @param string $uploadPath
* @param string $oldFileName
*
* @return array
*/
function uploadMultipleImage($request, string $inputName, string $uploadPath, $oldFileName = ''): array
{
$fileDataArr = [];
foreach ($request->file($inputName) as $image) {
$fileName = rand(1, 1000) . time() . '.jpeg';
// $fileName = rand(1, 1000) . time() . '.' . $image->getClientOriginalExtension();
$destinationPath = $uploadPath;
if (!empty($oldFileName)) {
deleteFile($destinationPath, $oldFileName);
}
$resizeImage = \Image::make($image->getPathname());
$resizeImage->resize(150, 150, function ($constraint) {
$constraint->aspectRatio();
})->stream();
Storage::put($destinationPath . '/small/' . $fileName, $resizeImage);
$resizeImage = \Image::make($image->getPathname());
$resizeImage->resize(300, 300, function ($constraint) {
$constraint->aspectRatio();
})->stream();
Storage::put($destinationPath . '/medium/' . $fileName, $resizeImage);
$resizeImage = \Image::make($image->getPathname())->stream();
Storage::put($destinationPath . '/' . $fileName, $resizeImage);
$fileData['image_name'] = $fileName;
$fileData['uploaded_path'] = $fileName;
$fileDataArr[] = $fileData;
}
return $fileDataArr;
}
}
if (!function_exists('deleteFile')) {
/**
* @param string $destinationPath
* @param string $oldFileName
*
* @return bool
*/
function deleteFile(string $destinationPath, $oldFileName = ''): bool
{
Storage::delete($destinationPath . $oldFileName);
Storage::delete($destinationPath . 'small/' . $oldFileName);
Storage::delete($destinationPath . 'medium/' . $oldFileName);
return true;
}
}
if (!function_exists('deleteFolder')) {
/**
* @param string $destinationPath
* @param $folderName
*
* @return bool
*/
function deleteFolder(string $destinationPath, $folderName): bool
{
Storage::deleteDirectory($destinationPath . '/' . $folderName);
return true;
}
}
if (!function_exists('getImage')) {
/**
* @param string $imageName
* @param string $basePath
* @param string $size
*
* @return string
*/
function getImage(string $imageName, $basePath = '', $size = ''): string
{
$destinationPath = $basePath;
if (!empty($size)) {
$destinationPath = $destinationPath . $size . '/';
}
$filePath = asset('storage' . $destinationPath . $imageName);
// if (Storage::exists($destinationPath . $imageName)) {
return Storage::url($destinationPath . $imageName);
// }
return '';
}
}
if (!function_exists('getFile')) {
/**
* @param string $fileName
* @param string $basePath
*
* @return string
*/
function getFile(string $fileName, $basePath = ''): string
{
$destinationPath = $basePath;
$filePath = asset('storage/' . $destinationPath . '/' . $fileName);
if (Storage::exists($destinationPath . '/' . $fileName)) {
return $filePath;
}
return '';
}
}
if (!function_exists('convertDateFormat')) {
/**
* @param $date
* @param string $dateTimeFormat
*
* @return false|string
*/
function convertDateFormat($date, $dateTimeFormat = 'Y-m-d H:i:s')
{
return date($dateTimeFormat, strtotime($date));
}
}
if (!function_exists('getUserMetaValue')) {
/**
* @param null $userId
* @param null $key
* @return mixed
* @since 2020-06-09
*
* Getting User meta values by meta key
*
* @author Jaynil Parekh
*/
function getUserMetaValue($userId = null, $key = null)
{
if (!empty($userId) && !empty($key)) {
return UserMeta::where('user_id', $userId)->where('meta_key', $key)->pluck('meta_value')->first();
}
}
}
if (!function_exists('addUserSingleMetaValue')) {
/**
* @param null $userId
* @param null $key
* @param null $value
* @return bool
* @author Jaynil Parekh
* @since 2020-06-09
*
* Store single user meta key and value
*
*/
function addUserSingleMetaValue($userId = null, $key = null, $value = null)
{
if (!empty($userId) && !empty($key) && !empty($value)) {
$data['user_id'] = $userId;
$data['meta_key'] = $key;
$data['meta_value'] = $value;
if (UserMeta::create($data)) {
return true;
}
return false;
} else {
return false;
}
}
}
if (!function_exists('addUserMultipleMetaValue')) {
/**
* @param null $data
* @return bool
* @author Jaynil Parekh
* @since 2020-06-09
*
*
* Store multiple user meta keys and values
*
*/
function addUserMultipleMetaValue($data = null)
{
if (!empty($data)) {
if (UserMeta::insert($data)) {
return true;
}
return false;
} else {
return false;
}
}
}
if (!function_exists('updateUserMetaValue')) {
/**
* @param null $userId
* @param null $key
* @param null $value
* @return bool
* @author Jaynil Parekh
* @since 2020-06-09
*
* Update user meta value
*
*/
function updateUserMetaValue($userId = null, $key = null, $value = null)
{
if (!empty($userId) && !empty($key) && !empty($value)) {
UserMeta::where('user_id', $userId)->where('meta_key', $key)->update(['meta_value' => $value]);
return true;
}
}
}
if (!function_exists('removeUserMetaValue')) {
/**
* @param null $userId
* @param null $key
* @param null $value
* @return bool
* @author Jaynil Parekh
* @since 2020-06-09
*
* Update user meta value
*
*/
function removeUserMetaValue($userId = null, $key = null, $value = null)
{
if (!empty($userId) && !empty($key)) {
UserMeta::where('user_id', $userId)->where('meta_key', $key)->delete();
return true;
}
}
}
if (!function_exists('generateConfirmationCode')) {
/**
* @param int $length
* @return false|string
* @author Jaynil Parekh
* @since 2020-06-09
*
* Generate confirmation code
*
*/
function generateConfirmationCode($length = 6)
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
}
if (!function_exists('generateOtp')) {
/**
* @param int $length
* @return false|string
* @author Jaynil Parekh
* @since 2020-06-09
*
* Generate confirmation code
*
*/
function generateOtp($length = 6)
{
$pool = '0123456789';
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
}
if (!function_exists('generateUsername')) {
/**
* @param $string
* @return string
* @author Jaynil Parekh
* @since 2020-06-19
*
* Generate username
*
*/
function generateUsername($string)
{
$pattern = " ";
$firstPart = substr(strstr(strtolower($string), $pattern, true), 0, 2);
$secondPart = substr(strstr(strtolower($string), $pattern, false), 0, 3);
$nrRand = rand(0, 100);
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$str_result = substr(str_shuffle($str_result), 0, 3);
return trim($firstPart) . trim($secondPart) . trim($nrRand) . trim($str_result);
}
}
if (!function_exists('hideEmailAddress')) {
/**
* @param $string
* @return string
* @author Shailesh Jakhaniya
* @since 2020-06-19
*
* Hide the email address
*
*/
function hideEmailAddress($email)
{
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
list($first, $last) = explode('@', $email);
$first = str_replace(substr($first, '1'), str_repeat('*', strlen($first)-1), $first);
$last = explode('.', $last);
$last_domain = str_replace(substr($last['0'], '1'), str_repeat('*', strlen($last['0'])-1), $last['0']);
$hideEmailAddress = $first.'@'.$last_domain.'.'.$last['1'];
return $hideEmailAddress;
}
}
}
if (!function_exists('defaultDateTimeFormat')) {
/**
* @param $date
* @param null $format
* @return mixed
*/
function defaultDateTimeFormat($date, $format = Constant::NULL)
{
if (empty($format)) {
$format = config('config-variables.default_date_time_format');
}
return Carbon::parse($date)->format($format);
}
}
if (!function_exists('defaulTimeFormat')) {
/**
* @param $date
* @param null $format
* @return mixed
*/
function defaulTimeFormat($time, $format = Constant::NULL)
{
if (empty($format)) {
$format = config('config-variables.default_time_format');
}
return Carbon::parse($time)->format($format);
}
}
if (!function_exists('defaulTimeFormat24')) {
/**
* @param $date
* @param null $format
* @return mixed
*/
function defaulTimeFormat24($time, $format = Constant::NULL)
{
if (empty($format)) {
$format = config('config-variables.24_time_format');
}
return Carbon::parse($time)->format($format);
}
}
if (!function_exists('encryptMe')) {
/**
* @param $string
*
* @return string
*/
function encryptMe($string)
{
$response = Constant::NULL;
try {
if (!empty($string)) {
$response = Crypt::encryptString($string);
}
} catch (DecryptException $ex) {
Log::error($ex);
}
return $response;
}
}
if (!function_exists('decryptMe')) {
/**
* @param $string
*
* @return string
*/
function decryptMe($string)
{
$response = Constant::NULL;
try {
if (!empty($string)) {
$response = Crypt::decryptString($string);
}
} catch (DecryptException $ex) {
Log::error($ex);
}
return $response;
}
if (!function_exists('getPlatform')) {
/**
* @param $type
*
* @return string
*/
function getPlatform($type)
{
$platformTypes = config('config-variables.platform_type');
foreach($platformTypes as $platformType){
if($platformType['id'] == $type){
return $platformType['value'];
}
}
}
}
if (!function_exists('getGenderType')) {
/**
* @param $type
*
* @return string
*/
function getGenderType($type)
{
$genderTypes = config('config-variables.gender_type');
foreach ($genderTypes as $genderType) {
if ($genderType['value'] == $type) {
return $genderType['id'];
}
}
}
}
if (!function_exists('getGenderTypeName')) {
/**
* @param $type
*
* @return string
*/
function getGenderTypeName($type)
{
$genderTypes = config('config-variables.gender_type_sharavak');
foreach ($genderTypes as $genderType) {
if ($genderType['id'] == $type) {
return $genderType['value'];
}
}
}
}
if (!function_exists('getDharmaName')) {
/**
* @param $id
*
* @return string
*/
function getDharmaName($id)
{
$dharmaName = Dharma::where('id', $id)->value('name');
return $dharmaName;
}
}
if (!function_exists('getJatiName')) {
/**
* @param $id
*
* @return string
*/
function getJatiName($id)
{
$jatiName = Jati::where('id', $id)->value('name');
return $jatiName;
}
}
if (!function_exists('getMotherTongue')) {
/**
* @param $id
*
* @return string
*/
function getMotherTongue($id)
{
$motherTongue = MotherTongue::where('id', $id)->value('name');
return $motherTongue;
}
}
if (!function_exists('getBloodGroup')) {
/**
* @param $id
*
* @return string
*/
function getBloodGroup($id)
{
$bloodGroup = BloodGroup::where('id', $id)->value('name');
return $bloodGroup;
}
}
if (!function_exists('getRelationName')) {
/**
* @param $id
*
* @return string
*/
function getRelationName($id)
{
$relationName = Relationship::where('id', $id)->value('name');
return $relationName;
}
}
if (!function_exists('getDharmaID')) {
/**
* @param $id
*
* @return string
*/
function getDharmaID($dharmaName)
{
$dharma = Dharma::where('name', 'LIKE', "%{$dharmaName}%")->value('id');
return $dharma;
}
}
if (!function_exists('getSampradayID')) {
/**
* @param $id
*
* @return string
*/
function getSampradayID($sampradayName)
{
$sampraday = Sampraday::where('name', 'LIKE', "%{$sampradayName}%")->value('id');
return $sampraday;
}
}
if (!function_exists('messageNotificationStatusUpdate')) {
/**
* @param $userID
* @param $messageThread
*
*/
function messageNotificationStatusUpdate($userID, $messageThread)
{
try {
if ($userID == '') {
$userID = loggedInUser()->id;
}
$result = DB::table('messages as m')
->where('m.user_id', '!=', $userID)
->where('m.message_thread_id', '=', $messageThread)
->update(['m.status' => '1']);
return $result;
} catch (\Exception $ex) {
Log::error($ex->getMessage());
return 0;
}
}
}
if (!function_exists('getUserRelation')) {
/**
* @param $relationID
*
*/
function getUserRelation($relationID)
{
$relation = "";
try {
$user = loggedInUser();
$relationName = Relationship::where('id', $relationID)->value('name');
//Returns son / daughter
if($relationName == config('config-variables.relationships.father') || $relationName == config('config-variables.relationships.mother')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.son'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.daughter'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns father / mother
if($relationName == config('config-variables.relationships.son') || $relationName == config('config-variables.relationships.daughter')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.father'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.mother'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns brother / sister
if($relationName == config('config-variables.relationships.brother') || $relationName == config('config-variables.relationships.sister')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.brother'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.sister'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns grandson / granddaughter
if($relationName == config('config-variables.relationships.grandfather') || $relationName == config('config-variables.relationships.grandmother')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.grandson'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.granddaughter'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns grandfather / grandmother
if($relationName == config('config-variables.relationships.grandson') || $relationName == config('config-variables.relationships.granddaughter')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.grandfather'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.grandmother'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns nephew / niece
if($relationName == config('config-variables.relationships.uncle') || $relationName == config('config-variables.relationships.aunt')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.nephew'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.niece'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns uncle / aunt
if($relationName == config('config-variables.relationships.nephew') || $relationName == config('config-variables.relationships.niece')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.uncle'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.aunt'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns son-in-law / daughter-in-law
if($relationName == config('config-variables.relationships.father_in_law') || $relationName == config('config-variables.relationships.mother_in_law')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.son_in_law'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.daughter_in_law'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns father-in-law / mother-in-law
if($relationName == config('config-variables.relationships.son_in_law') || $relationName == config('config-variables.relationships.daughter_in_law')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.father_in_law'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.mother_in_law'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns brother-in-law / sister-in-law
if($relationName == config('config-variables.relationships.brother_in_law') || $relationName == config('config-variables.relationships.sister_in_law')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.brother_in_law'))->value('id');
} else if ($user->gender == Constant::STATUS_TWO || $user->gender == Constant::STATUS_THREE) {
$relation = Relationship::where('name', config('config-variables.relationships.sister_in_law'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns wife
if($relationName == config('config-variables.relationships.husband')) {
if ($user->gender == Constant::STATUS_TWO) {
$relation = Relationship::where('name', config('config-variables.relationships.wife'))->value('id');
} else {
$relation = Constant::NULL;
}
}
//Returns husband
if($relationName == config('config-variables.relationships.wife')) {
if ($user->gender == Constant::STATUS_ONE) {
$relation = Relationship::where('name', config('config-variables.relationships.husband'))->value('id');
} else {
$relation = Constant::NULL;
}
}
return $relation;
} catch (\Exception $ex) {
Log::error($ex->getMessage());
return 0;
}
}
}
}
if (!function_exists('listOfDatesBasedOnDateRange')) {
/**
* Generate api token
*
* @return mixed
*/
function listOfDatesBasedOnDateRange($startDate, $endDate)
{
try {
$period = CarbonPeriod::create($startDate, $endDate);
foreach ($period as $date) {
// Insert Dates into listOfDates Array
$listOfDates[] = $date->format('Y');
}
return $listOfDates;
} catch (\Exception $ex) {
Log::error($ex);
}
}
}
if (!function_exists('checkUserPrivacy')) {
/**
* Check user's privacy
*
* @return mixed
*/
function checkUserPrivacy($privacy, $value, $isFriend)
{
try {
if ($privacy === Constant::STATUS_ONE) {
return $value;
} else if ($privacy === Constant::STATUS_TWO && $isFriend === Constant::STATUS_ONE) {
return $value;
} else if ($privacy === Constant::STATUS_THREE) {
return "";
} else {
return "";
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}
if (!function_exists('checkWorkPrivacy')) {
/**
* Check user's work privacy
*
* @return mixed
*/
function checkWorkPrivacy($data, $isFriend)
{
$responseData = [];
try {
if (!empty($data)) {
foreach ($data as $companyData) {
$responseData[] = [
'id' => $companyData['id'] ?? "",
'user_id' => $companyData['user_id'] ?? "",
'company_name' => checkUserPrivacy($companyData['company_name_privacy'], $companyData['company_name'], $isFriend) ?? "",
'company_name_privacy' => $companyData['company_name_privacy'] ?? "",
'profession_id' => $companyData['profession_id'] ?? "",
'profession' => checkUserPrivacy($companyData['profession_privacy'], $companyData['profession'], $isFriend) ?? "",
'profession_privacy' => $companyData['profession_privacy'] ?? "",
'profession_speciality' => checkUserPrivacy($companyData['profession_speciality_privacy'], $companyData['profession_speciality'], $isFriend) ?? "",
'profession_speciality_privacy' => $companyData['profession_speciality_privacy'] ?? "",
'position' => checkUserPrivacy($companyData['position_privacy'], $companyData['position'], $isFriend) ?? "",
'position_privacy' => $companyData['position_privacy'] ?? "",
'city' => checkUserPrivacy($companyData['city_privacy'], $companyData['city'], $isFriend) ?? "",
'city_privacy' => $companyData['city_privacy'] ?? "",
'website' => checkUserPrivacy($companyData['website_privacy'], $companyData['website'], $isFriend) ?? "",
'website_privacy' => $companyData['website_privacy'] ?? "",
'about' => checkUserPrivacy($companyData['about_privacy'], $companyData['about'], $isFriend) ?? "",
'about_privacy' => $companyData['about_privacy'] ?? "",
'is_working' => $companyData['is_working'] ?? "",
'start_year' => checkUserPrivacy($companyData['work_duration_privacy'], $companyData['start_year'], $isFriend) ?? "",
'end_year' => checkUserPrivacy($companyData['work_duration_privacy'], $companyData['end_year'], $isFriend) ?? "",
'work_duration_privacy' => $companyData['work_duration_privacy'] ?? "",
'created_at' => $companyData['created_at'] ?? "",
'updated_at' => $companyData['updated_at'] ?? "",
];
}
return $responseData;
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}
if (!function_exists('checkQualificationPrivacy')) {
/**
* Check user's qualification privacy
*
* @return mixed
*/
function checkQualificationPrivacy($data, $isFriend)
{
$responseData = [];
try {
if (!empty($data)) {
foreach ($data['schools'] as $qualificationData) {
if (($qualificationData['privacy'] != Constant::STATUS_THREE && $isFriend === Constant::STATUS_ONE) || ($qualificationData['privacy'] === Constant::STATUS_ONE)) {
$responseData['schools'][] = [
'id' => $qualificationData['id'] ?? "",
'user_id' => $qualificationData['user_id'] ?? "",
'qualification' => $qualificationData['qualification'] ?? "",
'university' => $qualificationData['university'] ?? "",
'highschool' => $qualificationData['highschool'] ?? "",
'is_graduate' => $qualificationData['is_graduate'] ?? "",
'is_pursuing' => $qualificationData['is_pursuing'] ?? "",
'passing_year' => $qualificationData['passing_year'] ?? "",
'starting_year' => $qualificationData['starting_year'] ?? "",
'start_date' => $qualificationData['start_date'] ?? "",
'end_date' => $qualificationData['end_date'] ?? "",
'type' => $qualificationData['type'] ?? "",
'privacy' => $qualificationData['privacy'] ?? "",
'created_at' => $qualificationData['created_at'] ?? "",
'updated_at' => $qualificationData['updated_at'] ?? "",
];
}
}
foreach ($data['colleges'] as $qualificationData) {
if (($qualificationData['privacy'] != Constant::STATUS_THREE && $isFriend === Constant::STATUS_ONE) || ($qualificationData['privacy'] === Constant::STATUS_ONE)) {
$responseData['colleges'][] = [
'id' => $qualificationData['id'] ?? "",
'user_id' => $qualificationData['user_id'] ?? "",
'qualification' => $qualificationData['qualification'] ?? "",
'university' => $qualificationData['university'] ?? "",
'highschool' => $qualificationData['highschool'] ?? "",
'is_graduate' => $qualificationData['is_graduate'] ?? "",
'is_pursuing' => $qualificationData['is_pursuing'] ?? "",
'passing_year' => $qualificationData['passing_year'] ?? "",
'starting_year' => $qualificationData['starting_year'] ?? "",
'start_date' => $qualificationData['start_date'] ?? "",
'end_date' => $qualificationData['end_date'] ?? "",
'type' => $qualificationData['type'] ?? "",
'privacy' => $qualificationData['privacy'] ?? "",
'created_at' => $qualificationData['created_at'] ?? "",
'updated_at' => $qualificationData['updated_at'] ?? "",
];
}
}
return $responseData;
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}
if (!function_exists('checkRelationPrivacy')) {
/**
* Check user's relation privacy
*
* @return mixed
*/
function checkRelationPrivacy($data, $isFriend)
{
$responseData = [];
try {
if (!empty($data)) {
foreach ($data as $relationData) {
if (($relationData['relation_privacy'] != Constant::STATUS_THREE && $isFriend === Constant::STATUS_ONE) || ($relationData['relation_privacy'] === Constant::STATUS_ONE)) {
$responseData[] = $relationData;
}
}
return $responseData;
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}
if (!function_exists('getChaturmasYears')) {
/**
*
*/
function getChaturmasYears()
{
return ChaturmasDate::pluck('year', 'id');
}
}
if (!function_exists('getPlatFormKey')) {
function getPlatFormKey($type)
{
$platformTypes = config('config-variables.platform_type');
foreach ($platformTypes as $platformType) {
if ($platformType['value'] == $type) {
return $platformType['id'];
}
}
}
}
if (!function_exists('randomStrings')) {
/**
* @param $lengthOfString
* @param string $stringType
*
* @return string
*/
function randomStrings($lengthOfString, $stringType = ''): string
{
if ($stringType == 'number') {
$str_result = '0123456789';
} else if ($stringType == 'upper') {
$str_result = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
} else if ($stringType == 'lower') {
$str_result = 'abcdefghijklmnopqrstuvwxyz';
} else {
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
}
// Shufle the $str_result and returns substring
// of specified length
return substr(str_shuffle($str_result),
0, $lengthOfString);
}
}
if (!function_exists('objectToArray')) {
/**
* @param $collection
*
* @return array
*/
function objectToArray($collection)
{
$collectionArray = [];
try {
foreach ($collection as $key => $value) {
$collectionDetails['id'] = $key;
$collectionDetails['name'] = html_entity_decode($value);
$collectionArray[] = $collectionDetails;
}
return $collectionArray;
} catch (\Exception $ex) {
return $collectionArray;
}
}
}
/**
* @param null $model
* @param int|null $authUser
* @param array|null $properties
* @param string|null $logName
*
* @return bool
*/
function logActivity($model = null, $authUser = null, array $properties = null, string $logName = null, $name = 'default'): bool
{
try {
activity($name)->performedOn($model)
->causedBy($authUser)
->withProperties($properties)
->log($logName);
return true;
} catch (\Exception $ex) {
Log::error($ex->getMessage());
return false;
}
}
if (!function_exists('calculateActivity')) {
/**
* @param array $array
* @param $slug
*
* @return array
*/
function calculateActivity(array $array)
{
$basicInfo = config('config-variables.profile_activity_fields_count.basic_info.fields');
$otherInfo = config('config-variables.profile_activity_fields_count.user_detail.fields');
$workInfo = config('config-variables.profile_activity_fields_count.work_info.fields');
$qualification = config('config-variables.profile_activity_fields_count.qualification_info.fields');
$basicInfoFilled = 0;
$otherInfoFilled = 0;
$workInfoFilled = 0;
$qualificationFilled = 0;
if ($array) {
foreach ($array as $key => $val) {
if (in_array($key, $basicInfo)) {
if ($val !== null && $val !== '') {
$basicInfoFilled++;
}
}
}
}
if (!empty($array['user_detail'])) {
foreach ($array['user_detail'][0] as $key => $val) {
if (in_array($key, $otherInfo)) {
if ($val !== null && $val !== '' && $val !== []) {
$otherInfoFilled++;
}
}
}
}
if (!empty($array['user_work_detail'])) {
foreach ($array['user_work_detail'][0] as $key => $val) {
if (in_array($key, $workInfo)) {
if ($val !== null && $val !== '' && $val !== []) {
$workInfoFilled++;
}
}
}
}
if (!empty($array['user_qualification'])) {
foreach ($array['user_qualification'][0] as $key => $val) {
if (in_array($key, $qualification)) {
if ($val !== null && $val !== '' && $val !== []) {
$qualificationFilled++;
}
}
}
}
$totalFilled = ($basicInfoFilled) + ($otherInfoFilled) + ($workInfoFilled) + ($qualificationFilled);
$percentage = calculatePercentage(config('config-variables.profile_activity_fields_count.total_fields'), $totalFilled);
return [
'basic_info' => $basicInfoFilled,
'other_info' => $otherInfoFilled,
'qualification' => $qualificationFilled,
'work' => $workInfoFilled,
'total_filled' => $totalFilled,
'profile_completion_percentage' => $percentage,
];
}
}
if (!function_exists('calculateSantActivity')) {
/**
* @param array $array
* @param $slug
*
* @return array
*/
function calculateSantActivity(array $array)
{
$basicInfo = config('config-variables.sant_profile_activity_fields_count.basic_info.fields');
$dikshaInfo = config('config-variables.sant_profile_activity_fields_count.diksha_info.fields');
$parentsInfo = config('config-variables.sant_profile_activity_fields_count.parents_info.fields');
$avatar = config('config-variables.sant_profile_activity_fields_count.avatar.fields');
// dd($basicInfo, $location, $contact_info, $qualification, $work);
$basicInfoFilled = 0;
$dikshaInfoFilled = 0;
$parentsInfoFilled = 0;
$avatarFilled = 0;
if ($array) {
foreach ($array as $key => $val) {
if (in_array($key, $basicInfo)) {
if ($val !== null && $val !== '' && $val != []) {
$basicInfoFilled++;
}
}
if (in_array($key, $dikshaInfo)) {
if ($val !== null && $val !== '' && $val != []) {
$dikshaInfoFilled++;
}
}
if (in_array($key, $parentsInfo)) {
if ($val !== null && $val !== '' && $val != []) {
$parentsInfoFilled++;
}
}
if (in_array($key, $avatar)) {
if ($val !== null && $val !== '' && count(array_filter($avatar)) > 0) {
$avatarFilled++;
}
}
}
}
$totalFilled = ($basicInfoFilled) + ($dikshaInfoFilled) + ($parentsInfoFilled) + ($avatarFilled);
$percentage = calculatePercentage(config('config-variables.sant_profile_activity_fields_count.total_fields'), $totalFilled);
return [
'basic_info' => $basicInfoFilled,
'diksha_info' => $dikshaInfoFilled,
'parent_info' => $parentsInfoFilled,
'avatar' => $avatarFilled,
'total_filled' => $totalFilled,
'profile_completion_percentage' => $percentage,
];
}
}
if (!function_exists('calculatePercentage')) {
/**
* @param int $total
* @param int $obtain
* @param int $percentage
*
* @return float
*/
function calculatePercentage(int $total, int $obtain, int $percentage = 100)
{
try {
$percentage = ($obtain * $percentage) / $total;
$precision = config('config-variables.profile_progress_float_decimal_notation', 1);
return convertToRound($percentage, $precision);
} catch (\Exception $ex) {
return 0;
}
}
}
if (!function_exists('convertToRound')) {
/**
* @param $value
* @param $precision
*
* @return int
*/
function convertToRound(int $value, int $precision = 1): int
{
return round(abs($value), $precision);
}
}
if(!function_exists('requestNumberFormat')) {
/**
* @param $number
* @return mixed
*/
function requestNumberFormat($number)
{
$baseFormat = "GHC-0001";
return str_replace("0001", str_pad($number, 4, "0", STR_PAD_LEFT), $baseFormat);
}
}