Compare commits
No commits in common. "1a9d95bb0475f3557eafe7313d262462f0002307" and "7e749d7cf472c2082055d9a917acc3ada62c7809" have entirely different histories.
1a9d95bb04
...
7e749d7cf4
6 changed files with 8 additions and 238 deletions
|
@ -13,6 +13,6 @@ class Customer extends BaseCustomer {
|
|||
* Get the groups this Customer belongs to.
|
||||
*/
|
||||
public function groups() {
|
||||
return $this->belongsToMany(CustomersGroup::class, 'customers_group_customers');
|
||||
return $this->belongsToMany(CustomersGroup::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ namespace Modules\MMFCustomersGroups\Entities;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomersGroup extends Model {
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Get the Mailbox this group is linked to.
|
||||
*/
|
||||
|
@ -22,18 +20,6 @@ class CustomersGroup extends Model {
|
|||
* Get the Customers that are included in this group.
|
||||
*/
|
||||
public function customers() {
|
||||
return $this->belongsToMany(Customer::class, 'customers_group_customers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of Emails that are included in this group.
|
||||
*/
|
||||
public function emails() {
|
||||
$customers = $this->customers;
|
||||
// Get a list of Emails from the list of Customers.
|
||||
$emails = $customers
|
||||
->pluck('emails')
|
||||
->flatten();
|
||||
return $emails;
|
||||
return $this->belongsToMany(Customer::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
|
||||
namespace Modules\MMFCustomersGroups\Http\Controllers;
|
||||
|
||||
use Eventy;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
use App\Email;
|
||||
|
||||
use Modules\MMFCustomersGroups\Entities\Customer;
|
||||
use Modules\MMFCustomersGroups\Entities\CustomersGroup;
|
||||
|
||||
class CustomersGroupsController extends Controller {
|
||||
|
@ -33,57 +27,10 @@ class CustomersGroupsController extends Controller {
|
|||
}
|
||||
|
||||
public function create() {
|
||||
$group = new CustomersGroup();
|
||||
return $this->update($group);
|
||||
// TODO
|
||||
}
|
||||
|
||||
public function update(CustomersGroup $group) {
|
||||
// Get the list of Mailboxes the current User is allowed to access.
|
||||
$user = auth()->user();
|
||||
$mailboxes = $user->mailboxesCanView();
|
||||
|
||||
// Get the list of Customers that can be attached to a group.
|
||||
$customers_query = Customer::with('emails');
|
||||
// Set a hook so the query can be filtered by other modules.
|
||||
$customers_query = Eventy::filter('mmfcustomergroups.groups.create.customers-query', $customers_query);
|
||||
$customers = $customers_query->get();
|
||||
|
||||
// Get a list of Emails from the list of Customers.
|
||||
$emails = $customers
|
||||
->pluck('emails')
|
||||
->flatten()
|
||||
->sortBy('email');
|
||||
|
||||
return view('mmfcustomersgroups::groups/edit', [
|
||||
'mailboxes' => $mailboxes,
|
||||
'customers' => $customers,
|
||||
'emails' => $emails,
|
||||
'group' => $group,
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request) {
|
||||
// Get the Customer Group that should be updated,
|
||||
// or create a new one.
|
||||
$group = ( $request->customer_id ) ?
|
||||
CustomersGroup::find($request->customer_id):
|
||||
new CustomersGroup();
|
||||
|
||||
$group->name = $request->name;
|
||||
$group->mailbox_id = $request->mailbox;
|
||||
// Save early to set the Group id, before setting the relationships.
|
||||
$group->save();
|
||||
|
||||
// Convert the list of Emails into a list of Customers.
|
||||
foreach ( $request->emails as $email_id ) {
|
||||
$email = Email::find($email_id);
|
||||
$customers[] = $email->customer;
|
||||
}
|
||||
// Drop duplicates from the list of Customers.
|
||||
$customers = collect($customers)->unique();
|
||||
$customers_id = $customers->pluck('id');
|
||||
$group->customers()->sync($customers_id);
|
||||
|
||||
return $this->list();
|
||||
public function update() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,26 +13,8 @@ Route::group(
|
|||
'namespace' => 'Modules\MMFCustomersGroups\Http\Controllers'
|
||||
],
|
||||
function() {
|
||||
// TODO: Check if the "laroute" property is required.
|
||||
Route::get('/groups/list', [
|
||||
'uses' => CustomersGroupsController::class . '@list',
|
||||
'laroute' => true,
|
||||
])->name('groups.list');
|
||||
Route::get('/groups/create', [
|
||||
'uses' => CustomersGroupsController::class . '@create',
|
||||
'laroute' => true,
|
||||
])->name('groups.create');
|
||||
Route::post('/groups/create', [
|
||||
'uses' => CustomersGroupsController::class . '@save',
|
||||
'laroute' => true,
|
||||
]);
|
||||
Route::get('/groups/{group}/edit', [
|
||||
'uses' => CustomersGroupsController::class . '@update',
|
||||
'laroute' => true,
|
||||
])->name('groups.update');
|
||||
Route::post('/groups/{group}/edit', [
|
||||
'uses' => CustomersGroupsController::class . '@save',
|
||||
'laroute' => true,
|
||||
]);
|
||||
Route::get('/groups/list', ['uses' => CustomersGroupsController::class . '@list', 'laroute' => true])->name('groups.list');
|
||||
Route::get('/groups/create', ['uses' => CustomersGroupsController::class . '@create', 'laroute' => true])->name('groups.create');
|
||||
Route::get('/groups/update', ['uses' => CustomersGroupsController::class . '@update', 'laroute' => true])->name('groups.update');
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
|
||||
*/
|
||||
?>
|
||||
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', __('Add Customers Group'))
|
||||
|
||||
@section('content')
|
||||
@include('mmfcustomersgroups::groups/partials/edit_form', ['save_button_title' => __('Add')])
|
||||
@endsection
|
||||
|
||||
@section('javascript')
|
||||
@parent
|
||||
@endsection
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
|
||||
*/
|
||||
?>
|
||||
|
||||
@include('partials/flash_messages')
|
||||
|
||||
<div class="container form-container">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<form class="form-horizontal margin-top" method="POST" action="" enctype="multipart/form-data">
|
||||
{{ csrf_field() }}
|
||||
<!-- Hidden field: The id of the Customers Group that is currently being edited -->
|
||||
<input
|
||||
id="customer_id"
|
||||
type="hidden"
|
||||
name="customer_id"
|
||||
value="{{ $group->id }}"
|
||||
/>
|
||||
<!-- Mandatory field: The Mailbox this Customers Group is linked to -->
|
||||
<div class="form-group{{ $errors->has('mailbox') ? ' has-error' : '' }} margin-bottom-0">
|
||||
<label
|
||||
for="mailbox"
|
||||
class="col-sm-2 control-label"
|
||||
>
|
||||
{{ __('Mailbox') }}
|
||||
</label>
|
||||
<div class="col-sm-6">
|
||||
<div class="multi-container">
|
||||
<div class="multi-item">
|
||||
<div>
|
||||
<div class="input-group input-group-flex input-sized-lg">
|
||||
<select class="form-control" name="mailbox" required>
|
||||
@if($group->mailbox == null)
|
||||
<option value="" disabled selected>---</option>
|
||||
@endif
|
||||
@foreach($mailboxes as $mailbox)
|
||||
<option
|
||||
value="{{ $mailbox->id }}"
|
||||
@if($group->mailbox && $mailbox->id == $group->mailbox->id)
|
||||
selected
|
||||
@endif
|
||||
>
|
||||
{{ $mailbox->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('partials/field_error', ['field'=>'mailbox'])
|
||||
</div>
|
||||
</div>
|
||||
<!-- Mandatory field: The name of this Customers Group -->
|
||||
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
|
||||
<label
|
||||
for="name"
|
||||
class="col-sm-2 control-label"
|
||||
>
|
||||
{{ __('Name') }}
|
||||
</label>
|
||||
<div class="col-sm-6">
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
class="form-control input-sized-lg"
|
||||
name="name"
|
||||
value="{{ old('name', $group->name) }}"
|
||||
maxlength="255"
|
||||
/>
|
||||
@include('partials/field_error', ['field'=>'name'])
|
||||
</div>
|
||||
</div>
|
||||
<!-- Mandatory field: The list of Emails included in this Customer Group -->
|
||||
<div class="form-group margin-bottom-0">
|
||||
<label
|
||||
for="emails"
|
||||
class="col-sm-2 control-label"
|
||||
>
|
||||
{{ __('Emails') }}
|
||||
</label>
|
||||
<div class="col-sm-6">
|
||||
<div class="multi-container">
|
||||
@foreach ( $emails as $email )
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label
|
||||
class="control-label checkbox"
|
||||
for="email-{{ $email->id }}"
|
||||
style="text-align: left;"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="emails[]"
|
||||
id="email-{{ $email->id }}"
|
||||
value="{{ $email->id }}"
|
||||
@if ( $group->emails()->contains($email) )
|
||||
checked="checked"
|
||||
@endif
|
||||
>
|
||||
{{ $email->email }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
{{-- @include('partials/field_error', ['field'=>'emails.*']) --}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-6 col-sm-offset-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@if (!empty($save_button_title))
|
||||
{{ $save_button_title }}
|
||||
@else
|
||||
{{ __('Save Group') }}
|
||||
@endif
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue