Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c4fbdffc
authored
May 20, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19462 Добавление в настройки городов переменных.
1 parent
a46b84a8
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
225 additions
and
185 deletions
app/Http/Controllers/CampaignVariablesController.php
app/Http/Controllers/TokensController.php
app/Models/Campaigns.php
app/Models/Dictionary.php
app/Models/Pivots/DictionaryCampaignPivot.php → app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/DictionaryCampaignVariablePivot.php → app/Models/Pivots/DictionaryCampaignVariable.php
app/Models/Variable.php
database/migrations/2021_05_17_101048_create_variables_table.php
database/migrations/2021_05_17_151448_create_dictionary_campaign_variables_table.php
resources/js/Pages/CampaignVariables/Edit.vue
routes/web.php
tests/Unit/CityTest.php
tests/Unit/ReplaceByVariablesTest.php
app/Http/Controllers/CampaignVariablesController.php
View file @
c4fbdff
...
@@ -2,9 +2,7 @@
...
@@ -2,9 +2,7 @@
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaignPivot
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\Redirect
;
...
@@ -14,12 +12,12 @@ use Inertia\Inertia;
...
@@ -14,12 +12,12 @@ use Inertia\Inertia;
class
CampaignVariablesController
extends
Controller
class
CampaignVariablesController
extends
Controller
{
{
pr
otected
$rule_variable
=
'required|exists:variables,id'
;
pr
ivate
$rule_variable
=
'required|exists:variables,id'
;
pr
otected
$rule_variable_name
=
'required|alpha|regex:/[a-zA-z]/
'
;
pr
ivate
$rule_variable_name
=
'required|alpha|regex:/[a-zA-z]/|unique:'
.
Variable
::
class
.
',name
'
;
pr
otected
$rule_default_value
=
'required'
;
pr
ivate
$rule_default_value
=
'required'
;
pr
otected
$rule_value
=
''
;
pr
ivate
$rule_value
=
''
;
function
__invoke
(
Tokens
$token
,
$dictionary_id
,
$campaign_id
)
public
function
index
(
Tokens
$token
,
$dictionary_id
,
$campaign_id
)
{
{
if
(
$token
->
isMain
())
{
if
(
$token
->
isMain
())
{
return
Redirect
::
back
();
return
Redirect
::
back
();
...
@@ -38,91 +36,125 @@ class CampaignVariablesController extends Controller
...
@@ -38,91 +36,125 @@ class CampaignVariablesController extends Controller
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$dictionary_campaign
=
DictionaryCampaign
Pivot
::
where
(
'campaign_id'
,
$campaign
->
getKey
())
$dictionary_campaign
=
DictionaryCampaign
::
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
first
();
->
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
first
();
switch
(
request
()
->
method
())
{
if
(
!
$dictionary_campaign
)
{
case
'GET'
:
return
Redirect
::
back
();
}
$variables
=
Variable
::
defaultOrderBy
()
->
get
();
$variables
=
Variable
::
defaultOrderBy
()
->
get
();
return
Inertia
::
render
(
'CampaignVariables/Edit'
,
[
'variables'
=>
$variables
->
transform
(
function
(
Variable
$variable
)
use
(
$dictionary_campaign
)
{
$data
=
$variable
->
toArray
();
$data
[
'dictionaryCampaign'
]
=
$variable
->
values
()
->
where
(
'dictionary_campaign_id'
,
$dictionary_campaign
->
getKey
())
->
first
();
return
$data
;
}),
'token'
=>
$token
,
'campaign'
=>
$campaign
,
'dictionary'
=>
$dictionary
,
]);
}
return
Inertia
::
render
(
'CampaignVariables/Edit'
,
[
public
function
addVariable
(
Tokens
$token
,
$dictionary_id
,
$campaign_id
)
'variables'
=>
$variables
->
transform
(
function
(
Variable
$variable
)
use
(
$dictionary_campaign
)
{
{
$data
=
$variable
->
toArray
();
if
(
$token
->
isMain
())
{
$data
[
'dictionaryCampaign'
]
=
$variable
->
values
()
->
where
(
'dictionary_campaign_id'
,
$dictionary_campaign
->
getKey
())
->
first
();
return
Redirect
::
back
();
return
$data
;
}
}),
'token'
=>
$token
,
'campaign'
=>
$campaign
,
'dictionary'
=>
$dictionary
,
]);
case
'POST'
:
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
()
->
campaignsForManaged
()
->
find
(
$campaign_id
);
if
(
request
(
'variable'
)
===
'add'
)
{
Request
::
validate
([
'name'
=>
$this
->
rule_variable_name
,
'default_value'
=>
$this
->
rule_default_value
,
]);
$variable_new
=
Variable
::
create
(
Request
::
only
([
'name'
,
'default_value'
,
]));
$variable_id
=
$variable_new
->
getKey
();
$value
=
request
(
'value'
);
}
else
{
Request
::
validate
([
'variable'
=>
$this
->
rule_variable
,
]);
$variable_id
=
request
(
'variable'
);
$value
=
request
(
'value'
);
}
$this
->
putCampaignVariableValue
(
$dictionary_campaign
,
$variable_id
,
$value
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable added.'
);
break
;
case
'PUT'
:
Request
::
validate
([
'value'
=>
$this
->
rule_value
]);
$this
->
putCampaignVariableValue
(
$dictionary_campaign
,
request
(
'id'
),
request
(
'value'
));
if
(
!
$campaign
)
{
return
Redirect
::
back
();
}
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable updated.'
);
$dictionary
=
$token
->
cities
()
->
find
(
$dictionary_id
);
break
;
if
(
!
$dictionary
)
{
return
Redirect
::
back
();
}
case
'PATCH'
:
$dictionary_campaign
=
DictionaryCampaign
::
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
first
();
if
(
!
$dictionary_campaign
)
{
return
Redirect
::
back
();
}
$variable
=
Variable
::
find
(
request
(
'id'
));
if
(
request
(
'variable'
)
===
'add'
)
{
Request
::
validate
([
'name'
=>
$this
->
rule_variable_name
,
'default_value'
=>
$this
->
rule_default_value
,
]);
if
(
!
$variable
)
{
$variable_new
=
Variable
::
create
(
Request
::
only
([
return
Redirect
::
back
();
'name'
,
}
'default_value'
,
]));
$variable_id
=
$variable_new
->
getKey
();
$value
=
request
(
'value'
);
}
else
{
Request
::
validate
([
'variable'
=>
$this
->
rule_variable
,
]);
$variable_id
=
request
(
'variable'
);
$value
=
request
(
'value'
);
}
$variable
->
update
(
Request
::
validate
([
$this
->
putCampaignVariableValue
(
$dictionary_campaign
,
$variable_id
,
$value
);
'name'
=>
$this
->
rule_variable_name
,
'default_value'
=>
$this
->
rule_default_value
,
]));
return
Redirect
::
back
()
->
with
(
'success'
,
'Variable name updat
ed.'
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable add
ed.'
);
break
;
}
}
public
function
editVariable
(
Variable
$variable
)
{
$variable
->
update
(
Request
::
validate
([
'name'
=>
$this
->
rule_variable_name
,
'default_value'
=>
$this
->
rule_default_value
,
]));
return
Redirect
::
back
();
return
Redirect
::
back
()
->
with
(
'success'
,
'Variable name updated.'
)
;
}
}
public
function
destroy
(
Tokens
$token
,
$dictionary_id
,
$campaign_id
,
$variable
_id
)
public
function
editDictionaryCampaignVariable
(
Tokens
$token
,
$dictionary_id
,
$campaign
_id
)
{
{
if
(
$token
->
isMain
())
{
if
(
$token
->
isMain
())
{
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
()
->
campaignsForManaged
()
->
find
(
$campaign_id
);
if
(
!
$campaign
)
{
return
Redirect
::
back
();
}
$dictionary
=
$token
->
cities
()
->
find
(
$dictionary_id
);
if
(
!
$dictionary
)
{
return
Redirect
::
back
();
}
$dictionary_campaign
=
DictionaryCampaign
::
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
first
();
if
(
!
$dictionary_campaign
)
{
return
Redirect
::
back
();
}
Request
::
validate
([
'value'
=>
$this
->
rule_value
]);
$this
->
putCampaignVariableValue
(
$dictionary_campaign
,
request
(
'variable_id'
),
request
(
'value'
));
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable updated.'
);
}
public
function
destroy
(
$variable_id
)
{
$variable
=
Variable
::
find
(
$variable_id
);
$variable
=
Variable
::
find
(
$variable_id
);
if
(
!
$variable
)
{
if
(
!
$variable
)
{
...
@@ -135,7 +167,7 @@ class CampaignVariablesController extends Controller
...
@@ -135,7 +167,7 @@ class CampaignVariablesController extends Controller
}
}
/**
/**
* @param DictionaryCampaign
Pivot
$dictionary_campaign
* @param DictionaryCampaign $dictionary_campaign
* @param integer $variable_id
* @param integer $variable_id
* @param string|null $value
* @param string|null $value
*/
*/
...
@@ -145,10 +177,19 @@ class CampaignVariablesController extends Controller
...
@@ -145,10 +177,19 @@ class CampaignVariablesController extends Controller
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
where
(
'variable_id'
,
$variable_id
)
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
where
(
'variable_id'
,
$variable_id
)
->
delete
();
->
delete
();
}
else
{
}
else
{
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
create
([
$dictionary_campaign_variable
=
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
firstWhere
(
'variable_id'
,
$variable_id
);
'variable_id'
=>
$variable_id
,
'value'
=>
$value
,
if
(
$dictionary_campaign_variable
)
{
]);
$dictionary_campaign_variable
->
update
([
'value'
=>
$value
,
]);
}
else
{
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
create
([
'variable_id'
=>
$variable_id
,
'value'
=>
$value
,
]);
}
}
}
}
}
...
...
app/Http/Controllers/TokensController.php
View file @
c4fbdff
...
@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
...
@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
use
App\Models\Campaigns
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
...
@@ -169,7 +169,7 @@ class TokensController extends Controller
...
@@ -169,7 +169,7 @@ class TokensController extends Controller
if
(
$token_main
->
campaignsForManaged
->
count
())
{
if
(
$token_main
->
campaignsForManaged
->
count
())
{
$city
->
campaigns
()
->
syncWithoutDetaching
(
$city
->
campaigns
()
->
syncWithoutDetaching
(
$token_main
->
campaignsForManaged
->
keyBy
(
$token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
$token_main
->
campaignsForManaged
->
keyBy
(
$token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
}
}
...
...
app/Models/Campaigns.php
View file @
c4fbdff
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\DictionaryCampaignVariable
Pivot
;
use
App\Models\Pivots\DictionaryCampaignVariable
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
...
@@ -115,7 +115,7 @@ class Campaigns extends Model
...
@@ -115,7 +115,7 @@ class Campaigns extends Model
if
(
$campaign
->
manage
)
{
if
(
$campaign
->
manage
)
{
Dictionary
::
whereNotNull
(
'token_id'
)
->
each
(
function
(
Dictionary
$dictionary
)
use
(
$campaign
)
{
Dictionary
::
whereNotNull
(
'token_id'
)
->
each
(
function
(
Dictionary
$dictionary
)
use
(
$campaign
)
{
$campaign
->
dictionaries
()
->
syncWithoutDetaching
([
$campaign
->
dictionaries
()
->
syncWithoutDetaching
([
$dictionary
->
getKey
()
=>
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
),
$dictionary
->
getKey
()
=>
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
),
]);
]);
});
});
}
else
{
}
else
{
...
@@ -140,14 +140,14 @@ class Campaigns extends Model
...
@@ -140,14 +140,14 @@ class Campaigns extends Model
public
function
dictionaryCampaignVariables
()
public
function
dictionaryCampaignVariables
()
{
{
return
$this
->
hasManyThrough
(
DictionaryCampaignVariable
Pivot
::
class
,
DictionaryCampaignPivot
::
class
,
'campaign_id'
,
'dictionary_campaign_id'
);
return
$this
->
hasManyThrough
(
DictionaryCampaignVariable
::
class
,
DictionaryCampaign
::
class
,
'campaign_id'
,
'dictionary_campaign_id'
);
}
}
public
function
dictionaries
()
public
function
dictionaries
()
{
{
return
$this
->
belongsToMany
(
Dictionary
::
class
,
'dictionary_campaigns'
,
'campaign_id'
,
'dictionary_id'
)
return
$this
->
belongsToMany
(
Dictionary
::
class
,
'dictionary_campaigns'
,
'campaign_id'
,
'dictionary_id'
)
->
using
(
DictionaryCampaign
Pivot
::
class
)
->
using
(
DictionaryCampaign
::
class
)
->
withPivot
(
DictionaryCampaign
Pivot
::
getWithPivot
())
->
withPivot
(
DictionaryCampaign
::
getWithPivot
())
->
withTimestamps
();
->
withTimestamps
();
}
}
...
...
app/Models/Dictionary.php
View file @
c4fbdff
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaignVariable
Pivot
;
use
App\Models\Pivots\DictionaryCampaignVariable
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
/**
/**
...
@@ -63,8 +63,8 @@ class Dictionary extends Model
...
@@ -63,8 +63,8 @@ class Dictionary extends Model
public
function
campaigns
()
public
function
campaigns
()
{
{
return
$this
->
belongsToMany
(
Campaigns
::
class
,
'dictionary_campaigns'
,
'dictionary_id'
,
'campaign_id'
)
return
$this
->
belongsToMany
(
Campaigns
::
class
,
'dictionary_campaigns'
,
'dictionary_id'
,
'campaign_id'
)
->
using
(
DictionaryCampaign
Pivot
::
class
)
->
using
(
DictionaryCampaign
::
class
)
->
withPivot
(
DictionaryCampaign
Pivot
::
getWithPivot
())
->
withPivot
(
DictionaryCampaign
::
getWithPivot
())
->
withTimestamps
();
->
withTimestamps
();
}
}
...
...
app/Models/Pivots/DictionaryCampaign
Pivot
.php
→
app/Models/Pivots/DictionaryCampaign.php
View file @
c4fbdff
...
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
...
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
*
*
* @property-read Campaigns $campaign
* @property-read Campaigns $campaign
* @property-read Dictionary $dictionary
* @property-read Dictionary $dictionary
* @property-read DictionaryCampaignVariable
Pivot
[] $dictionaryCampaignVariables
* @property-read DictionaryCampaignVariable[] $dictionaryCampaignVariables
* @property-read Variable[] $variables
* @property-read Variable[] $variables
* @mixin \Eloquent
* @mixin \Eloquent
* @property int $id
* @property int $id
...
@@ -26,20 +26,20 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
...
@@ -26,20 +26,20 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read int|null $dictionary_campaign_variables_count
* @property-read int|null $dictionary_campaign_variables_count
* @property-read int|null $variables_count
* @property-read int|null $variables_count
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereDictionaryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereDictionaryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereExcludedSites($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereExcludedSites($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereNegativeKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereNegativeKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereUpdated($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereUpdated($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
Pivot
whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign whereUpdatedAt($value)
*/
*/
class
DictionaryCampaign
Pivot
extends
Pivot
class
DictionaryCampaign
extends
Pivot
{
{
protected
$table
=
'dictionary_campaigns'
;
protected
$table
=
'dictionary_campaigns'
;
...
@@ -96,14 +96,14 @@ class DictionaryCampaignPivot extends Pivot
...
@@ -96,14 +96,14 @@ class DictionaryCampaignPivot extends Pivot
public
function
dictionaryCampaignVariables
()
public
function
dictionaryCampaignVariables
()
{
{
return
$this
->
hasMany
(
DictionaryCampaignVariable
Pivot
::
class
,
'dictionary_campaign_id'
);
return
$this
->
hasMany
(
DictionaryCampaignVariable
::
class
,
'dictionary_campaign_id'
);
}
}
public
function
variables
()
public
function
variables
()
{
{
return
$this
->
belongsToMany
(
Variable
::
class
,
'dictionary_campaign_variables'
,
'dictionary_campaign_id'
,
'variable_id'
)
return
$this
->
belongsToMany
(
Variable
::
class
,
'dictionary_campaign_variables'
,
'dictionary_campaign_id'
,
'variable_id'
)
->
using
(
DictionaryCampaignVariable
Pivot
::
class
)
->
using
(
DictionaryCampaignVariable
::
class
)
->
withPivot
(
DictionaryCampaignVariable
Pivot
::
getWithPivot
())
->
withPivot
(
DictionaryCampaignVariable
::
getWithPivot
())
->
withTimestamps
();
->
withTimestamps
();
}
}
...
...
app/Models/Pivots/DictionaryCampaignVariable
Pivot
.php
→
app/Models/Pivots/DictionaryCampaignVariable.php
View file @
c4fbdff
...
@@ -18,17 +18,17 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
...
@@ -18,17 +18,17 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
* @property string $value
* @property string $value
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereDictionaryCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereDictionaryCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereValue($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereValue($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable
Pivot
whereVariableId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariable whereVariableId($value)
*/
*/
class
DictionaryCampaignVariable
Pivot
extends
Pivot
class
DictionaryCampaignVariable
extends
Pivot
{
{
protected
$table
=
'dictionary_campaign_variables'
;
protected
$table
=
'dictionary_campaign_variables'
;
...
@@ -53,7 +53,7 @@ class DictionaryCampaignVariablePivot extends Pivot
...
@@ -53,7 +53,7 @@ class DictionaryCampaignVariablePivot extends Pivot
public
function
dictionary_campaign
()
public
function
dictionary_campaign
()
{
{
return
$this
->
belongsTo
(
DictionaryCampaign
Pivot
::
class
,
'dictionary_campaign_id'
);
return
$this
->
belongsTo
(
DictionaryCampaign
::
class
,
'dictionary_campaign_id'
);
}
}
public
function
variable
()
public
function
variable
()
...
...
app/Models/Variable.php
View file @
c4fbdff
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\DictionaryCampaignVariable
Pivot
;
use
App\Models\Pivots\DictionaryCampaignVariable
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
/**
/**
...
@@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\Builder;
...
@@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\Builder;
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @property-read int|null $campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaignVariable
Pivot
[] $values
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaignVariable[] $values
* @property-read int|null $values_count
* @property-read int|null $values_count
* @method static Builder|Variable defaultOrderBy()
* @method static Builder|Variable defaultOrderBy()
* @method static Builder|Variable newModelQuery()
* @method static Builder|Variable newModelQuery()
...
@@ -42,7 +42,7 @@ class Variable extends Model
...
@@ -42,7 +42,7 @@ class Variable extends Model
public
function
values
()
public
function
values
()
{
{
return
$this
->
hasMany
(
DictionaryCampaignVariable
Pivot
::
class
,
'variable_id'
);
return
$this
->
hasMany
(
DictionaryCampaignVariable
::
class
,
'variable_id'
);
}
}
}
}
database/migrations/2021_05_17_101048_create_variables_table.php
View file @
c4fbdff
...
@@ -15,7 +15,7 @@ class CreateVariablesTable extends Migration
...
@@ -15,7 +15,7 @@ class CreateVariablesTable extends Migration
{
{
Schema
::
create
(
'variables'
,
function
(
Blueprint
$table
)
{
Schema
::
create
(
'variables'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
id
();
$table
->
string
(
'name'
,
255
);
$table
->
string
(
'name'
,
255
)
->
unique
()
;
$table
->
string
(
'default_value'
,
255
);
$table
->
string
(
'default_value'
,
255
);
$table
->
timestamps
();
$table
->
timestamps
();
});
});
...
...
database/migrations/2021_05_17_151448_create_dictionary_campaign_variables_table.php
View file @
c4fbdff
...
@@ -21,6 +21,8 @@ class CreateDictionaryCampaignVariablesTable extends Migration
...
@@ -21,6 +21,8 @@ class CreateDictionaryCampaignVariablesTable extends Migration
$table
->
timestamps
();
$table
->
timestamps
();
$table
->
unique
([
'dictionary_campaign_id'
,
'variable_id'
]);
$table
->
foreign
(
'dictionary_campaign_id'
)
->
references
(
'id'
)
->
on
(
'dictionary_campaigns'
)
$table
->
foreign
(
'dictionary_campaign_id'
)
->
references
(
'id'
)
->
on
(
'dictionary_campaigns'
)
->
cascadeOnDelete
();
->
cascadeOnDelete
();
$table
->
foreign
(
'variable_id'
)
->
references
(
'id'
)
->
on
(
'variables'
)
$table
->
foreign
(
'variable_id'
)
->
references
(
'id'
)
->
on
(
'variables'
)
...
...
resources/js/Pages/CampaignVariables/Edit.vue
View file @
c4fbdff
...
@@ -202,7 +202,7 @@
...
@@ -202,7 +202,7 @@
watch
:
{},
watch
:
{},
methods
:
{
methods
:
{
add
()
{
add
()
{
this
.
$inertia
.
post
(
this
.
route
(
'token.campaign.variable
s
'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
]),
{
this
.
$inertia
.
post
(
this
.
route
(
'token.campaign.variable
.add
'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
]),
{
variable
:
this
.
variable
,
variable
:
this
.
variable
,
default_value
:
this
.
default_value
,
default_value
:
this
.
default_value
,
name
:
this
.
name
,
name
:
this
.
name
,
...
@@ -238,26 +238,26 @@
...
@@ -238,26 +238,26 @@
}
}
};
};
},
},
save
(
campaign_var_id
,
names
)
{
save
(
variable_id
,
names
)
{
const
method
=
names
.
indexOf
(
'name'
)
!==
-
1
?
'patch'
:
'put'
;
let
data
=
{
let
data
=
{
id
:
campaign_var
_id
,
variable_id
:
variable
_id
,
};
};
names
.
map
((
name
)
=>
{
names
.
map
((
name
)
=>
{
data
[
name
]
=
this
.
inputs
[
campaign_var
_id
][
name
].
val
;
data
[
name
]
=
this
.
inputs
[
variable
_id
][
name
].
val
;
this
.
editCancel
(
campaign_var
_id
,
name
);
this
.
editCancel
(
variable
_id
,
name
);
});
});
this
.
$inertia
[
method
](
this
.
route
(
'token.campaign.variables'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
]),
data
);
if
(
names
.
indexOf
(
'name'
)
===
-
1
)
this
.
$inertia
.
post
(
this
.
route
(
'token.campaign.variable.edit'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
]),
data
);
else
this
.
$inertia
.
post
(
this
.
route
(
'variable.edit'
,
[
variable_id
]),
data
);
},
},
destroy
(
campaign_var
_id
)
{
destroy
(
variable
_id
)
{
if
(
confirm
(
'Are you sure you want to delete this campaign var?'
))
{
if
(
confirm
(
'Are you sure you want to delete this campaign var?'
))
{
this
.
$inertia
.
delete
(
this
.
route
(
'
token.campaign.variable.destroy'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
,
campaign_var
_id
]));
this
.
$inertia
.
delete
(
this
.
route
(
'
variable.destroy'
,
[
variable
_id
]));
}
}
},
},
},
},
...
...
routes/web.php
View file @
c4fbdff
...
@@ -152,51 +152,48 @@ Route::get('500', function () {
...
@@ -152,51 +152,48 @@ Route::get('500', function () {
echo
$fail
;
echo
$fail
;
});
});
Route
::
get
(
'/token/{api}'
,
[
TokensController
::
class
,
'token'
])
Route
::
group
([
'middleware'
=>
'auth'
],
function
()
{
->
name
(
'token'
)
->
middleware
(
'auth'
);
Route
::
get
(
'/token/{api}'
,
[
TokensController
::
class
,
'token'
])
->
name
(
'token'
);
Route
::
get
(
'/token/{api}/get'
,
[
TokensController
::
class
,
'get'
])
->
name
(
'token.get'
)
Route
::
get
(
'/token/{api}/get'
,
[
TokensController
::
class
,
'get'
])
->
middleware
(
'auth'
);
->
name
(
'token.get'
);
Route
::
get
(
'tokens'
,
[
TokensController
::
class
,
'index'
])
Route
::
get
(
'tokens'
,
[
TokensController
::
class
,
'index'
])
->
name
(
'tokens'
)
->
name
(
'tokens'
);
->
middleware
(
'auth'
);
Route
::
get
(
'token/edit/{token}'
,
[
TokensController
::
class
,
'edit'
])
Route
::
get
(
'token/edit/{token}'
,
[
TokensController
::
class
,
'edit'
])
->
name
(
'token.edit'
);
->
name
(
'token.edit'
)
Route
::
post
(
'token/edit/{token}'
,
[
TokensController
::
class
,
'update'
])
->
middleware
(
'auth'
);
->
name
(
'token.update'
);
Route
::
post
(
'token/edit/{token}'
,
[
TokensController
::
class
,
'update'
])
Route
::
delete
(
'token/delete/{token}'
,
[
TokensController
::
class
,
'destroy'
])
->
name
(
'token.update'
)
->
name
(
'token.destroy'
);
->
middleware
(
'auth'
);
Route
::
delete
(
'token/delete/{token}'
,
[
TokensController
::
class
,
'destroy'
])
Route
::
post
(
'token/campaigns/managed/{token}/{campaign_id}'
,
[
TokensController
::
class
,
'managedCampaign'
])
->
name
(
'token.destroy'
)
->
name
(
'token.campaign.managed'
);
->
middleware
(
'auth'
);
Route
::
post
(
'token/campaigns/enabled/{token}/{campaign_id}'
,
[
TokensController
::
class
,
'enabledCampaign'
])
->
name
(
'token.campaign.enabled'
);
Route
::
post
(
'token/campaigns/managed/{token}/{campaign_id}'
,
[
TokensController
::
class
,
'managedCampaign'
])
->
name
(
'token.campaign.managed'
)
Route
::
get
(
'token/campaigns/variables/{token}/{dictionary_id}/{campaign_id}'
,
[
CampaignVariablesController
::
class
,
'index'
])
->
middleware
(
'auth'
);
->
name
(
'token.campaign.variables'
);
Route
::
post
(
'token/campaigns/enabled/{token}/{campaign_id}'
,
[
TokensController
::
class
,
'enabledCampaign'
])
Route
::
post
(
'token/campaigns/variables/{token}/{dictionary_id}/{campaign_id}/add'
,
[
CampaignVariablesController
::
class
,
'addVariable'
])
->
name
(
'token.campaign.enabled'
)
->
name
(
'token.campaign.variable.add'
);
->
middleware
(
'auth'
);
Route
::
post
(
'token/campaigns/variables/{token}/{dictionary_id}/{campaign_id}/edit'
,
[
CampaignVariablesController
::
class
,
'editDictionaryCampaignVariable'
])
->
name
(
'token.campaign.variable.edit'
);
Route
::
any
(
'token/campaigns/vars/{token}/{dictionary_id}/{campaign_id}'
,
CampaignVariablesController
::
class
)
->
name
(
'token.campaign.variables'
)
Route
::
post
(
'variables/{variable}/edit'
,
[
CampaignVariablesController
::
class
,
'editVariable'
])
->
middleware
(
'auth'
);
->
name
(
'variable.edit'
);
Route
::
delete
(
'token/campaigns/vars/{token}/{dictionary_id}/{campaign_id}/{variable_id}'
,
[
CampaignVariablesController
::
class
,
'destroy'
])
Route
::
delete
(
'variables/{variable}'
,
[
CampaignVariablesController
::
class
,
'destroy'
])
->
name
(
'token.campaign.variable.destroy'
)
->
name
(
'variable.destroy'
);
->
middleware
(
'auth'
);
Route
::
post
(
'token/city/store/{token}/{city}'
,
[
TokensController
::
class
,
'storeCity'
])
->
name
(
'token.city.store'
);
Route
::
post
(
'token/city/updated/{token}/{city}'
,
[
TokensController
::
class
,
'updatedCity'
])
->
name
(
'token.city.updated'
);
Route
::
post
(
'token/city/campaign/updated/{token}/{city}/{campaign}'
,
[
TokensController
::
class
,
'updatedCityCampaign'
])
->
name
(
'token.city.campaign.updated'
);
Route
::
delete
(
'token/city/{token}/{city}'
,
[
TokensController
::
class
,
'destroyCity'
])
->
name
(
'token.city.destroy'
);
Route
::
post
(
'token/city/store/{token}/{city}'
,
[
TokensController
::
class
,
'storeCity'
])
});
->
name
(
'token.city.store'
)
->
middleware
(
'auth'
);
Route
::
post
(
'token/city/updated/{token}/{city}'
,
[
TokensController
::
class
,
'updatedCity'
])
->
name
(
'token.city.updated'
)
->
middleware
(
'auth'
);
Route
::
post
(
'token/city/campaign/updated/{token}/{city}/{campaign}'
,
[
TokensController
::
class
,
'updatedCityCampaign'
])
->
name
(
'token.city.campaign.updated'
)
->
middleware
(
'auth'
);
Route
::
delete
(
'token/city/{token}/{city}'
,
[
TokensController
::
class
,
'destroyCity'
])
->
name
(
'token.city.destroy'
)
->
middleware
(
'auth'
);
tests/Unit/CityTest.php
View file @
c4fbdff
...
@@ -5,7 +5,7 @@ namespace Tests\Unit;
...
@@ -5,7 +5,7 @@ namespace Tests\Unit;
use
App\Models\Account
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Models\User
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
...
@@ -81,7 +81,7 @@ class CityTest extends TestCase
...
@@ -81,7 +81,7 @@ class CityTest extends TestCase
$this
->
dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$this
->
dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$this
->
token_main
->
campaignsForManaged
->
keyBy
(
$this
->
token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
$this
->
token_main
->
campaignsForManaged
->
keyBy
(
$this
->
token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
...
...
tests/Unit/ReplaceByVariablesTest.php
View file @
c4fbdff
...
@@ -5,8 +5,8 @@ namespace Tests\Unit;
...
@@ -5,8 +5,8 @@ namespace Tests\Unit;
use
App\Models\Account
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaignVariable
Pivot
;
use
App\Models\Pivots\DictionaryCampaignVariable
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Models\User
;
use
App\Models\Variable
;
use
App\Models\Variable
;
...
@@ -53,7 +53,7 @@ class ReplaceByVariablesTest extends TestCase
...
@@ -53,7 +53,7 @@ class ReplaceByVariablesTest extends TestCase
$this
->
dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$this
->
dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$this
->
token_main
->
campaignsForManaged
->
keyBy
(
$this
->
token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
$this
->
token_main
->
campaignsForManaged
->
keyBy
(
$this
->
token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
...
@@ -67,7 +67,7 @@ class ReplaceByVariablesTest extends TestCase
...
@@ -67,7 +67,7 @@ class ReplaceByVariablesTest extends TestCase
'default_value'
=>
'vartwo value'
,
'default_value'
=>
'vartwo value'
,
]);
]);
$this
->
dictionaryCampaign
=
DictionaryCampaign
Pivot
::
first
();
$this
->
dictionaryCampaign
=
DictionaryCampaign
::
first
();
$this
->
dictionaryCampaign
->
dictionaryCampaignVariables
()
->
create
([
$this
->
dictionaryCampaign
->
dictionaryCampaignVariables
()
->
create
([
'variable_id'
=>
$this
->
variable
->
getKey
(),
'variable_id'
=>
$this
->
variable
->
getKey
(),
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment