mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
commit
24769559bb
@ -1,4 +1,4 @@
|
||||
function crudAjax(params, url, type, callback, async = false) {
|
||||
function crudAjax(params, url, type, callback = () => {}, async = false) {
|
||||
return $.ajax({
|
||||
type: type,
|
||||
data: params,
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller;
|
||||
|
||||
use Anomaly\Streams\Platform\Http\Controller\PublicController;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface;
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
|
||||
@ -112,4 +115,43 @@ class AjaxController extends PublicController
|
||||
|
||||
return $query->orderBy($sorting_column, $sorting_type)->get();
|
||||
}
|
||||
|
||||
public function findLocation()
|
||||
{
|
||||
try {
|
||||
$validator = Validator::make(request()->all(), [
|
||||
'type' => [
|
||||
'required',
|
||||
Rule::in(['countries', 'cities', 'districts', 'neighborhoods', 'village'])
|
||||
],
|
||||
'id' => 'required|exists:location_' . request()->type,
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new \Exception($validator->messages()->first());
|
||||
}
|
||||
|
||||
$dBName = 'location_' . request()->type;
|
||||
$location = DB::table($dBName)
|
||||
->join(
|
||||
$dBName . '_translations as location_trans',
|
||||
$dBName . '.id',
|
||||
'=',
|
||||
'location_trans.entry_id'
|
||||
)
|
||||
->where($dBName . '.id', request()->id)
|
||||
->first();
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $location
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'msg' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -76,6 +76,7 @@ class LocationModuleServiceProvider extends AddonServiceProvider
|
||||
'admin/location/neighborhoods/create' => 'Visiosoft\LocationModule\Http\Controller\Admin\NeighborhoodsController@create',
|
||||
'admin/location/neighborhoods/edit/{id}' => 'Visiosoft\LocationModule\Http\Controller\Admin\NeighborhoodsController@edit',
|
||||
|
||||
// AjaxController
|
||||
'ajax/getCountry' => [
|
||||
'as' => 'location::getCountry',
|
||||
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getCountries'
|
||||
@ -97,6 +98,10 @@ class LocationModuleServiceProvider extends AddonServiceProvider
|
||||
'as' => 'location::getVillage',
|
||||
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@getVillage'
|
||||
],
|
||||
'api/find-location' => [
|
||||
'as' => 'visiosoft.module.location::api_find_location',
|
||||
'uses' => 'Visiosoft\LocationModule\Http\Controller\AjaxController@findLocation'
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Anomaly\Streams\Platform\Database\Migration\Migration;
|
||||
|
||||
class VisiosoftModuleProfileCreateProfessionAndEducationalFields extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
if ($stream = $this->streams()->findBySlugAndNamespace('users', 'users')) {
|
||||
$fields = [
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.education.name'),
|
||||
'slug' => 'education',
|
||||
],
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.state_of_education.name'),
|
||||
'slug' => 'state_of_education',
|
||||
],
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.profession.name'),
|
||||
'slug' => 'profession',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$exists = $this->fields()
|
||||
->newQuery()
|
||||
->where('slug', $field['slug'])
|
||||
->where('namespace', 'users')
|
||||
->first();
|
||||
|
||||
if (!$exists) {
|
||||
$userField = $this->fields()->create([
|
||||
'name' => $field['name'],
|
||||
'namespace' => 'users',
|
||||
'slug' => $field['slug'],
|
||||
'type' => 'anomaly.field_type.text',
|
||||
'locked' => 0,
|
||||
]);
|
||||
|
||||
$this->assignments()->create([
|
||||
'stream_id' => $stream->id,
|
||||
'field_id' => $userField->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
/*
|
||||
* I never go back on my word!
|
||||
* That's my nindo: my ninja way!
|
||||
* NARUTO
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -1,29 +1,17 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Seed;
|
||||
|
||||
use Anomaly\Streams\Platform\Assignment\AssignmentModelTranslation;
|
||||
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Database\Seeder\Seeder;
|
||||
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Field\FieldModelTranslation;
|
||||
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Country\CountryModel;
|
||||
|
||||
class UsersFieldsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the seeder.
|
||||
* @param FieldRepositoryInterface $fieldRepository
|
||||
* @param AssignmentRepositoryInterface $assignmentRepository
|
||||
* @param StreamRepositoryInterface $streamRepository
|
||||
* @param FieldModelTranslation $fieldModelTranslation
|
||||
* @param AssignmentModelTranslation $assignmentModelTranslation
|
||||
*/
|
||||
public function run(
|
||||
FieldRepositoryInterface $fieldRepository,
|
||||
AssignmentRepositoryInterface $assignmentRepository,
|
||||
StreamRepositoryInterface $streamRepository,
|
||||
FieldModelTranslation $fieldModelTranslation,
|
||||
AssignmentModelTranslation $assignmentModelTranslation
|
||||
StreamRepositoryInterface $streamRepository
|
||||
)
|
||||
{
|
||||
$namespace = 'users';
|
||||
@ -31,7 +19,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
$stream = $streamRepository->findBySlugAndNamespace('users', 'users');
|
||||
|
||||
$customFields = [
|
||||
0 => [
|
||||
[
|
||||
'name' => 'File',
|
||||
'slug' => 'file',
|
||||
'type' => 'visiosoft.field_type.singlefile',
|
||||
@ -40,7 +28,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
'mode' => 'upload',
|
||||
]
|
||||
],
|
||||
1 => [
|
||||
[
|
||||
'name' => 'Country',
|
||||
'slug' => 'country',
|
||||
'type' => 'anomaly.field_type.relationship',
|
||||
@ -49,7 +37,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
"default_value" => 0,
|
||||
],
|
||||
],
|
||||
2 => [
|
||||
[
|
||||
'name' => 'City',
|
||||
'slug' => 'city',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -57,7 +45,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
"options" => [],
|
||||
]
|
||||
],
|
||||
3 => [
|
||||
[
|
||||
'name' => 'District',
|
||||
'slug' => 'district',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -65,7 +53,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
"options" => [],
|
||||
]
|
||||
],
|
||||
4 => [
|
||||
[
|
||||
'name' => 'Neighborhood',
|
||||
'slug' => 'neighborhood',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -73,7 +61,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
"options" => [],
|
||||
]
|
||||
],
|
||||
5 => [
|
||||
[
|
||||
'name' => 'Village',
|
||||
'slug' => 'village',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -81,22 +69,22 @@ class UsersFieldsSeeder extends Seeder
|
||||
"options" => [],
|
||||
]
|
||||
],
|
||||
6 => [
|
||||
[
|
||||
'name' => 'Gsm Phone',
|
||||
'slug' => 'gsm_phone',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
7 => [
|
||||
[
|
||||
'name' => 'Land Phone',
|
||||
'slug' => 'land_phone',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
8 => [
|
||||
[
|
||||
'name' => 'Office Phone',
|
||||
'slug' => 'office_phone',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
9 => [
|
||||
[
|
||||
'name' => 'Register Type',
|
||||
'slug' => 'register_type',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -107,12 +95,12 @@ class UsersFieldsSeeder extends Seeder
|
||||
],
|
||||
]
|
||||
],
|
||||
10 => [
|
||||
[
|
||||
'name' => 'Identification Number',
|
||||
'slug' => 'identification_number',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
11 => [
|
||||
[
|
||||
'name' => 'Notified New Updates',
|
||||
'slug' => 'notified_new_updates',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -122,7 +110,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
'separator' => ':',
|
||||
]
|
||||
],
|
||||
12 => [
|
||||
[
|
||||
'name' => 'Notified About Ads',
|
||||
'slug' => 'notified_about_ads',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -132,7 +120,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
'separator' => ':',
|
||||
]
|
||||
],
|
||||
13 => [
|
||||
[
|
||||
'name' => 'Receive Messages Email',
|
||||
'slug' => 'receive_messages_email',
|
||||
'type' => 'anomaly.field_type.select',
|
||||
@ -142,7 +130,7 @@ class UsersFieldsSeeder extends Seeder
|
||||
'separator' => ':',
|
||||
]
|
||||
],
|
||||
14 => [
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.birthday.name'),
|
||||
'slug' => 'birthday',
|
||||
'type' => 'anomaly.field_type.datetime',
|
||||
@ -151,50 +139,49 @@ class UsersFieldsSeeder extends Seeder
|
||||
"picker" => true,
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.education.name'),
|
||||
'slug' => 'education',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.state_of_education.name'),
|
||||
'slug' => 'state_of_education',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
[
|
||||
'name' => trans('visiosoft.module.profile::field.profession.name'),
|
||||
'slug' => 'profession',
|
||||
'type' => 'anomaly.field_type.text',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($customFields as $customField) {
|
||||
$fields = $fieldRepository
|
||||
$field = $fieldRepository
|
||||
->newQuery()
|
||||
->where('slug', $customField['slug'])
|
||||
->where('namespace', $namespace)
|
||||
->get();
|
||||
->first();
|
||||
|
||||
if ($fields) {
|
||||
foreach ($fields as $field) {
|
||||
$fieldModelTranslation->newQuery()->where('field_id', $field->id)->delete();
|
||||
|
||||
$assignment = $assignmentRepository
|
||||
->newQuery()
|
||||
->where('stream_id', $stream->id)
|
||||
->where('field_id', $field->id)
|
||||
->first();
|
||||
if ($assignment) {
|
||||
$assignmentModelTranslation->newQuery()->where('assignment_id', $assignment->id)->delete();
|
||||
$assignment->delete();
|
||||
}
|
||||
|
||||
$field->delete();
|
||||
if (!$field) {
|
||||
$data = [
|
||||
'name' => $customField['name'],
|
||||
'namespace' => $namespace,
|
||||
'slug' => $customField['slug'],
|
||||
'type' => $customField['type'],
|
||||
'locked' => $locked
|
||||
];
|
||||
if (isset($customField['config'])) {
|
||||
$data['config'] = $customField['config'];
|
||||
}
|
||||
|
||||
$field = $fieldRepository->create($data);
|
||||
|
||||
$assignmentRepository->create([
|
||||
'stream_id' => $stream->id,
|
||||
'field_id' => $field->id
|
||||
]);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $customField['name'],
|
||||
'namespace' => $namespace,
|
||||
'slug' => $customField['slug'],
|
||||
'type' => $customField['type'],
|
||||
'locked' => $locked
|
||||
];
|
||||
if (isset($customField['config'])) {
|
||||
$data['config'] = $customField['config'];
|
||||
}
|
||||
|
||||
$field = $fieldRepository->create($data);
|
||||
|
||||
$assignmentRepository->create([
|
||||
'stream_id' => $stream->id,
|
||||
'field_id' => $field->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user