build version 400

This commit is contained in:
Mohit Panjwani
2020-12-02 17:54:08 +05:30
parent 326508e567
commit 89ee58590c
963 changed files with 62887 additions and 48868 deletions

View File

@@ -1,6 +1,8 @@
<?php
use Crater\CompanySetting;
use Crater\Currency;
use Crater\Models\CompanySetting;
use Crater\Models\Currency;
use Crater\Models\CustomField;
use Illuminate\Support\Str;
/**
* Set Active Path
@@ -25,16 +27,45 @@ function is_url($path)
}
/**
* @param $string
* @param string $type
* @return string
*/
function clean_slug($string)
function getCustomFieldValueKey(string $type)
{
// Replaces all spaces with hyphens.
$string = str_replace(' ', '-', $string);
switch ($type) {
case 'Input':
return 'string_answer';
// Removes special chars.
return \Illuminate\Support\Str::lower(preg_replace('/[^A-Za-z0-9\-]/', '', $string));
case 'TextArea':
return 'string_answer';
case 'Phone':
return 'number_answer';
case 'Url':
return 'string_answer';
case 'Number':
return 'number_answer';
case 'Dropdown':
return 'string_answer';
case 'Switch':
return 'boolean_answer';
case 'Date':
return 'date_answer';
case 'Time':
return 'time_answer';
case 'DateTime':
return 'date_time_answer';
default:
return 'string_answer';
}
}
/**
@@ -64,3 +95,40 @@ function format_money_pdf($money, $currency = null)
}
return $currency_with_symbol;
}
/**
* @param $string
* @return string
*/
function clean_slug($model, $title, $id = 0)
{
// Normalize the title
$slug = Str::upper('CUSTOM_'.$model.'_'.Str::slug($title, '_'));
// Get any that could possibly be related.
// This cuts the queries down by doing it once.
$allSlugs = getRelatedSlugs($model, $slug, $id);
// If we haven't used it before then we are all good.
if (!$allSlugs->contains('slug', $slug)) {
return $slug;
}
// Just append numbers like a savage until we find not used.
for ($i = 1; $i <= 10; $i++) {
$newSlug = $slug . '_' . $i;
if (!$allSlugs->contains('slug', $newSlug)) {
return $newSlug;
}
}
throw new \Exception('Can not create a unique slug');
}
function getRelatedSlugs($type, $slug, $id = 0)
{
return CustomField::select('slug')->where('slug', 'like', $slug . '%')
->where('model_type', $type)
->where('id', '<>', $id)
->get();
}