Hints for imports

This commit is contained in:
David Bomba 2023-09-07 13:43:22 +10:00
parent be22f4bde9
commit 628f63ffb2
3 changed files with 41 additions and 20 deletions

View File

@ -115,7 +115,7 @@ class CompanyUserController extends BaseController
$auth_user = auth()->user();
$company = $auth_user->company();
$company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
$company_user = CompanyUser::query()->where('user_id', $user->id)->where('company_id',$company->id)->first();
if (! $company_user) {
throw new ModelNotFoundException(ctrans('texts.company_user_not_found'));
@ -128,6 +128,11 @@ class CompanyUserController extends BaseController
} else {
$company_user->settings = $request->input('company_user')['settings'];
$company_user->notifications = $request->input('company_user')['notifications'];
if(isset($request->input('company_user')['react_settings'])) {
$company_user->react_settings = $request->input('company_user')['react_settings'];
}
}
$company_user->save();

View File

@ -120,36 +120,49 @@ class ImportController extends Controller
foreach($headers as $key => $value) {
$hit = false;
$unsetKey = false;
// array_multisort(array_column($translated_keys, 'label'), SORT_ASC, $translated_keys);
foreach($translated_keys as $tkey => $tvalue)
{
if($this->testMatch($value, $tvalue['label'])) {
$hit = $available_keys[$tvalue['key']];
$unsetKey = $tkey;
$hit = $tvalue['key'];
$hints[$key] = $hit;
unset($translated_keys[$tkey]);
break;
}
else {
$hints[$key] = null;
}
// elseif($this->testMatch($value, $tvalue['index'])) {
// $hit = $available_keys[$tvalue['key']];
// $unsetKey = $tkey;
// }
}
if($hit) {
$hints[$key] = $hit;
unset($translated_keys[$unsetKey]);
} else {
$hints[$key] = null;
}
}
nlog($translated_keys);
//second pass using the index of the translation here
foreach($headers as $key => $value)
{
if(isset($hints[$key])) {
nlog($hints[$key]);
continue;
}
foreach($translated_keys as $tkey => $tvalue)
{
if($this->testMatch($value, $tvalue['index'])) {
$hit = $tvalue['key'];
$hints[$key] = $hit;
unset($translated_keys[$tkey]);
break;
} else {
$hints[$key] = null;
}
}
}
// nlog($translated_keys);
return $hints;
}

View File

@ -25,7 +25,10 @@ class UpdateCompanyUserRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin() || (auth()->user()->id == $this->user->id);
/** @var \App\Models\User $auth_user */
$auth_user = auth()->user();
return $auth_user->isAdmin() || ($auth_user->id == $this->user->id);
}
public function rules()