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 a46b84a8
authored
May 19, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19461 Страница настройки целевых аккаунтов.
1 parent
97f72362
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
224 additions
and
120 deletions
.gitignore
app/Http/Controllers/CampaignVariablesController.php
app/Http/Controllers/TokensController.php
app/Models/Campaigns.php
app/Models/Dictionary.php
app/Models/Pivots/DictionaryCampaign.php → app/Models/Pivots/DictionaryCampaignPivot.php
app/Models/Pivots/CampaignVariable.php → app/Models/Pivots/DictionaryCampaignVariablePivot.php
app/Models/Tokens.php
app/Models/Variable.php
database/factories/CampaingFactory.php
database/factories/DictionaryFactory.php
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
database/migrations/2021_05_17_101448_create_campaign_variables_table.php → database/migrations/2021_05_17_151448_create_dictionary_campaign_variables_table.php
resources/js/Pages/CampaignVariables/Edit.vue
resources/js/Pages/Tokens/CitySettings.vue
routes/web.php
tests/Feature/CityTest.php
tests/Unit/CityTest.php
tests/Unit/ReplaceByVariablesTest.php
.gitignore
View file @
a46b84a
...
@@ -16,3 +16,4 @@ npm-debug.log
...
@@ -16,3 +16,4 @@ npm-debug.log
yarn-error.log
yarn-error.log
/.idea
/.idea
_ide_helper.php
_ide_helper.php
.phpstorm.meta.php
app/Http/Controllers/CampaignVariablesController.php
View file @
a46b84a
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
App\Models\Campaigns
;
use
App\Models\Campaigns
;
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
;
...
@@ -17,17 +19,27 @@ class CampaignVariablesController extends Controller
...
@@ -17,17 +19,27 @@ class CampaignVariablesController extends Controller
protected
$rule_default_value
=
'required'
;
protected
$rule_default_value
=
'required'
;
protected
$rule_value
=
''
;
protected
$rule_value
=
''
;
function
__invoke
(
Tokens
$token
,
$campaign_id
)
function
__invoke
(
Tokens
$token
,
$
dictionary_id
,
$
campaign_id
)
{
{
if
(
$token
->
isMain
())
{
if
(
$token
->
isMain
())
{
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
get
()
->
first
()
->
campaignsForManaged
()
->
with
(
'variables'
)
->
find
(
$campaign_id
);
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
()
->
campaignsForManaged
()
->
find
(
$campaign_id
);
if
(
!
$campaign
)
{
if
(
!
$campaign
)
{
return
Redirect
::
back
();
return
Redirect
::
back
();
};
}
$dictionary
=
$token
->
cities
()
->
find
(
$dictionary_id
);
if
(
!
$dictionary
)
{
return
Redirect
::
back
();
}
$dictionary_campaign
=
DictionaryCampaignPivot
::
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
first
();
switch
(
request
()
->
method
())
{
switch
(
request
()
->
method
())
{
case
'GET'
:
case
'GET'
:
...
@@ -35,14 +47,14 @@ class CampaignVariablesController extends Controller
...
@@ -35,14 +47,14 @@ class CampaignVariablesController extends Controller
$variables
=
Variable
::
defaultOrderBy
()
->
get
();
$variables
=
Variable
::
defaultOrderBy
()
->
get
();
return
Inertia
::
render
(
'CampaignVariables/Edit'
,
[
return
Inertia
::
render
(
'CampaignVariables/Edit'
,
[
'variables'
=>
$variables
->
transform
(
function
(
Variable
$variable
)
use
(
$campaign
)
{
'variables'
=>
$variables
->
transform
(
function
(
Variable
$variable
)
use
(
$
dictionary_
campaign
)
{
$data
=
$variable
->
toArray
();
$data
=
$variable
->
toArray
();
$data
[
'campaign'
]
=
$variable
->
campaigns
()
$data
[
'dictionaryCampaign'
]
=
$variable
->
values
()
->
where
(
'dictionary_campaign_id'
,
$dictionary_campaign
->
getKey
())
->
first
();
->
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
first
();
return
$data
;
return
$data
;
}),
}),
'token'
=>
$token
,
'token'
=>
$token
,
'campaign'
=>
$campaign
,
'campaign'
=>
$campaign
,
'dictionary'
=>
$dictionary
,
]);
]);
case
'POST'
:
case
'POST'
:
...
@@ -67,7 +79,7 @@ class CampaignVariablesController extends Controller
...
@@ -67,7 +79,7 @@ class CampaignVariablesController extends Controller
$value
=
request
(
'value'
);
$value
=
request
(
'value'
);
}
}
$this
->
putCampaignVariableValue
(
$campaign
,
$variable_id
,
$value
);
$this
->
putCampaignVariableValue
(
$
dictionary_
campaign
,
$variable_id
,
$value
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable added.'
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable added.'
);
break
;
break
;
...
@@ -78,7 +90,7 @@ class CampaignVariablesController extends Controller
...
@@ -78,7 +90,7 @@ class CampaignVariablesController extends Controller
'value'
=>
$this
->
rule_value
'value'
=>
$this
->
rule_value
]);
]);
$this
->
putCampaignVariableValue
(
$campaign
,
request
(
'id'
),
request
(
'value'
));
$this
->
putCampaignVariableValue
(
$
dictionary_
campaign
,
request
(
'id'
),
request
(
'value'
));
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable updated.'
);
return
Redirect
::
back
()
->
with
(
'success'
,
'Campaign variable updated.'
);
break
;
break
;
...
@@ -105,7 +117,7 @@ class CampaignVariablesController extends Controller
...
@@ -105,7 +117,7 @@ class CampaignVariablesController extends Controller
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
public
function
destroy
(
Tokens
$token
,
$campaign_id
,
$variable_id
)
public
function
destroy
(
Tokens
$token
,
$
dictionary_id
,
$
campaign_id
,
$variable_id
)
{
{
if
(
$token
->
isMain
())
{
if
(
$token
->
isMain
())
{
return
Redirect
::
back
();
return
Redirect
::
back
();
...
@@ -123,19 +135,19 @@ class CampaignVariablesController extends Controller
...
@@ -123,19 +135,19 @@ class CampaignVariablesController extends Controller
}
}
/**
/**
* @param
Campaigns $
campaign
* @param
DictionaryCampaignPivot $dictionary_
campaign
* @param integer $variable_id
* @param integer $variable_id
* @param string|null $value
* @param string|null $value
*/
*/
private
function
putCampaignVariableValue
(
Campaigns
$
campaign
,
$variable_id
,
$value
=
null
)
private
function
putCampaignVariableValue
(
$dictionary_
campaign
,
$variable_id
,
$value
=
null
)
{
{
if
(
is_null
(
$value
))
{
if
(
is_null
(
$value
))
{
$campaign
->
variables
()
->
detach
(
$variable_id
);
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
where
(
'variable_id'
,
$variable_id
)
->
delete
();
}
else
{
}
else
{
$
campaign
->
variables
()
->
syncWithoutDetaching
([
$
dictionary_campaign
->
dictionaryCampaignVariables
()
->
create
([
$variable_id
=>
[
'variable_id'
=>
$variable_id
,
'value'
=>
$value
,
'value'
=>
$value
,
],
]);
]);
}
}
}
}
...
...
app/Http/Controllers/TokensController.php
View file @
a46b84a
...
@@ -4,12 +4,10 @@ namespace App\Http\Controllers;
...
@@ -4,12 +4,10 @@ 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
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
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
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\Redirect
;
...
@@ -39,7 +37,7 @@ class TokensController extends Controller
...
@@ -39,7 +37,7 @@ class TokensController extends Controller
function
edit
(
Tokens
$token
)
function
edit
(
Tokens
$token
)
{
{
$mainToken
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
get
()
->
first
();
$mainToken
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
return
Inertia
::
render
(
'Tokens/Edit'
,
[
return
Inertia
::
render
(
'Tokens/Edit'
,
[
'token'
=>
[
'token'
=>
[
'id'
=>
$token
->
getKey
(),
'id'
=>
$token
->
getKey
(),
...
@@ -171,7 +169,7 @@ class TokensController extends Controller
...
@@ -171,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
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
}
}
...
...
app/Models/Campaigns.php
View file @
a46b84a
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\
CampaignVariable
;
use
App\Models\Pivots\
DictionaryCampaignVariablePivot
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
...
@@ -37,8 +37,8 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -37,8 +37,8 @@ use Illuminate\Database\Eloquent\Model;
* @property-read int|null $dictionaries_count
* @property-read int|null $dictionaries_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $groups
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $groups
* @property-read int|null $groups_count
* @property-read int|null $groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Variable[] $
v
ariables
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Variable[] $
dictionaryCampaignV
ariables
* @property-read int|null $
v
ariables_count
* @property-read int|null $
dictionaryCampaignV
ariables_count
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged()
...
@@ -115,12 +115,11 @@ class Campaigns extends Model
...
@@ -115,12 +115,11 @@ 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
::
copyPropertyInCampaign
(
$campaign
),
$dictionary
->
getKey
()
=>
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
),
]);
]);
});
});
}
else
{
}
else
{
$campaign
->
dictionaries
()
->
detach
();
$campaign
->
dictionaries
()
->
detach
();
//$campaign->variables()->detach();
}
}
}
}
});
});
...
@@ -129,7 +128,6 @@ class Campaigns extends Model
...
@@ -129,7 +128,6 @@ class Campaigns extends Model
static::deleting(function(Campaigns $campaign_delete)
static::deleting(function(Campaigns $campaign_delete)
{
{
$campaign_delete->dictionaries()->detach();
$campaign_delete->dictionaries()->detach();
$campaign_delete->variables()->detach();
$campaign_delete->groups()->delete();
$campaign_delete->groups()->delete();
});
});
*/
*/
...
@@ -140,19 +138,16 @@ class Campaigns extends Model
...
@@ -140,19 +138,16 @@ class Campaigns extends Model
return
$this
->
hasMany
(
AdGroup
::
class
,
'campaign_id'
);
return
$this
->
hasMany
(
AdGroup
::
class
,
'campaign_id'
);
}
}
public
function
v
ariables
()
public
function
dictionaryCampaignV
ariables
()
{
{
return
$this
->
belongsToMany
(
Variable
::
class
,
'campaign_variables'
,
'campaign_id'
,
'variable_id'
)
return
$this
->
hasManyThrough
(
DictionaryCampaignVariablePivot
::
class
,
DictionaryCampaignPivot
::
class
,
'campaign_id'
,
'dictionary_campaign_id'
);
->
using
(
CampaignVariable
::
class
)
->
withPivot
(
CampaignVariable
::
getWithPivot
())
->
withTimestamps
();
}
}
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
::
class
)
->
using
(
DictionaryCampaign
Pivot
::
class
)
->
withPivot
(
DictionaryCampaign
::
getWithPivot
())
->
withPivot
(
DictionaryCampaign
Pivot
::
getWithPivot
())
->
withTimestamps
();
->
withTimestamps
();
}
}
...
...
app/Models/Dictionary.php
View file @
a46b84a
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaignPivot
;
use
App\Models\Pivots\DictionaryCampaignVariablePivot
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
/**
/**
...
@@ -20,6 +21,8 @@ use Illuminate\Database\Eloquent\Builder;
...
@@ -20,6 +21,8 @@ use Illuminate\Database\Eloquent\Builder;
* @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 \App\Models\Tokens|null $token
* @property-read \App\Models\Tokens|null $token
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Variable[] $variables
* @property-read int|null $variables_count
* @method static Builder|Dictionary defaultOrderBy()
* @method static Builder|Dictionary defaultOrderBy()
* @method static Builder|Dictionary newModelQuery()
* @method static Builder|Dictionary newModelQuery()
* @method static Builder|Dictionary newQuery()
* @method static Builder|Dictionary newQuery()
...
@@ -60,8 +63,8 @@ class Dictionary extends Model
...
@@ -60,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
::
class
)
->
using
(
DictionaryCampaign
Pivot
::
class
)
->
withPivot
(
DictionaryCampaign
::
getWithPivot
())
->
withPivot
(
DictionaryCampaign
Pivot
::
getWithPivot
())
->
withTimestamps
();
->
withTimestamps
();
}
}
...
...
app/Models/Pivots/DictionaryCampaign.php
→
app/Models/Pivots/DictionaryCampaign
Pivot
.php
View file @
a46b84a
...
@@ -4,21 +4,46 @@ namespace App\Models\Pivots;
...
@@ -4,21 +4,46 @@ namespace App\Models\Pivots;
use
App\Models\Campaigns
;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\Variable
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
/**
/**
* App\Models\Pivots\DictionaryCampaign
* App\Models\Pivots\DictionaryCampaign
Pivot
*
*
* @property-read Campaigns $campaign
* @property-read Campaigns $campaign
* @property-read Dictionary $dictionary
* @property-read Dictionary $dictionary
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newModelQuery()
* @property-read DictionaryCampaignVariablePivot[] $dictionaryCampaignVariables
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newQuery()
* @property-read Variable[] $variables
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign query()
* @mixin \Eloquent
* @mixin \Eloquent
* @property int $id
* @property int $campaign_id
* @property int $dictionary_id
* @property string|null $name
* @property string|null $negative_keywords
* @property string|null $excluded_sites
* @property int $updated
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read int|null $dictionary_campaign_variables_count
* @property-read int|null $variables_count
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereDictionaryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereExcludedSites($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereNegativeKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereUpdated($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignPivot whereUpdatedAt($value)
*/
*/
class
DictionaryCampaign
extends
Pivot
class
DictionaryCampaign
Pivot
extends
Pivot
{
{
protected
$table
=
'dictionary_campaigns'
;
protected
$fillable
=
[
protected
$fillable
=
[
'campaign_id'
,
'campaign_id'
,
'dictionary_id'
,
'dictionary_id'
,
...
@@ -69,4 +94,17 @@ class DictionaryCampaign extends Pivot
...
@@ -69,4 +94,17 @@ class DictionaryCampaign extends Pivot
return
$this
->
belongsTo
(
Campaigns
::
class
,
'campaign_id'
);
return
$this
->
belongsTo
(
Campaigns
::
class
,
'campaign_id'
);
}
}
public
function
dictionaryCampaignVariables
()
{
return
$this
->
hasMany
(
DictionaryCampaignVariablePivot
::
class
,
'dictionary_campaign_id'
);
}
public
function
variables
()
{
return
$this
->
belongsToMany
(
Variable
::
class
,
'dictionary_campaign_variables'
,
'dictionary_campaign_id'
,
'variable_id'
)
->
using
(
DictionaryCampaignVariablePivot
::
class
)
->
withPivot
(
DictionaryCampaignVariablePivot
::
getWithPivot
())
->
withTimestamps
();
}
}
}
app/Models/Pivots/
CampaignVariable
.php
→
app/Models/Pivots/
DictionaryCampaignVariablePivot
.php
View file @
a46b84a
...
@@ -7,25 +7,40 @@ use App\Models\Variable;
...
@@ -7,25 +7,40 @@ use App\Models\Variable;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
/**
/**
* App\Models\Pivots\
CampaignVariable
* App\Models\Pivots\
DictionaryCampaignVariablePivot
*
*
* @property-read Campaigns $campaign
* @property-read Campaigns $
dictionary_
campaign
* @property-read Variable $variable
* @property-read Variable $variable
* @method static \Illuminate\Database\Eloquent\Builder|CampaignVariable newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CampaignVariable newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CampaignVariable query()
* @mixin \Eloquent
* @mixin \Eloquent
* @property int $id
* @property int $dictionary_campaign_id
* @property int $variable_id
* @property string $value
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot query()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereDictionaryCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereValue($value)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaignVariablePivot whereVariableId($value)
*/
*/
class
CampaignVariable
extends
Pivot
class
DictionaryCampaignVariablePivot
extends
Pivot
{
{
protected
$table
=
'dictionary_campaign_variables'
;
protected
$fillable
=
[
protected
$fillable
=
[
'campaign_id'
,
'
dictionary_
campaign_id'
,
'variable_id'
,
'variable_id'
,
'value'
,
'value'
,
];
];
protected
$casts
=
[
protected
$casts
=
[
'campaign_id'
=>
'int'
,
'
dictionary_
campaign_id'
=>
'int'
,
'variable_id'
=>
'int'
,
'variable_id'
=>
'int'
,
];
];
...
@@ -36,13 +51,14 @@ class CampaignVariable extends Pivot
...
@@ -36,13 +51,14 @@ class CampaignVariable extends Pivot
];
];
}
}
public
function
campaign
()
public
function
dictionary_
campaign
()
{
{
return
$this
->
belongsTo
(
Campaigns
::
class
,
'
campaign_id'
);
return
$this
->
belongsTo
(
DictionaryCampaignPivot
::
class
,
'dictionary_
campaign_id'
);
}
}
public
function
variable
()
public
function
variable
()
{
{
return
$this
->
belongsTo
(
Variable
::
class
,
'variable_id'
);
return
$this
->
belongsTo
(
Variable
::
class
,
'variable_id'
);
}
}
}
}
app/Models/Tokens.php
View file @
a46b84a
...
@@ -21,6 +21,10 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -21,6 +21,10 @@ use Illuminate\Database\Eloquent\Model;
* @property-read int|null $campaigns_count
* @property-read int|null $campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $cities
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $cities
* @property-read int|null $cities_count
* @property-read int|null $cities_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
* @property-read int|null $campaignsForManaged_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsNotForManaged
* @property-read int|null $campaignsNotForManaged_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Limits[] $limits
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Limits[] $limits
* @property-read int|null $limits_count
* @property-read int|null $limits_count
* @method static \Illuminate\Database\Eloquent\Builder|Tokens filter(array $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens filter(array $filters)
...
...
app/Models/Variable.php
View file @
a46b84a
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\
CampaignVariable
;
use
App\Models\Pivots\
DictionaryCampaignVariablePivot
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
/**
/**
...
@@ -15,6 +15,8 @@ use Illuminate\Database\Eloquent\Builder;
...
@@ -15,6 +15,8 @@ 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|DictionaryCampaignVariablePivot[] $values
* @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()
* @method static Builder|Variable newQuery()
* @method static Builder|Variable newQuery()
...
@@ -22,6 +24,7 @@ use Illuminate\Database\Eloquent\Builder;
...
@@ -22,6 +24,7 @@ use Illuminate\Database\Eloquent\Builder;
* @method static Builder|Variable whereCreatedAt($value)
* @method static Builder|Variable whereCreatedAt($value)
* @method static Builder|Variable whereId($value)
* @method static Builder|Variable whereId($value)
* @method static Builder|Variable whereName($value)
* @method static Builder|Variable whereName($value)
* @method static Builder|Variable whereDefaultValue($value)
* @method static Builder|Variable whereUpdatedAt($value)
* @method static Builder|Variable whereUpdatedAt($value)
* @mixin \Eloquent
* @mixin \Eloquent
*/
*/
...
@@ -37,12 +40,9 @@ class Variable extends Model
...
@@ -37,12 +40,9 @@ class Variable extends Model
return
$query
->
orderBy
(
'name'
);
return
$query
->
orderBy
(
'name'
);
}
}
public
function
campaign
s
()
public
function
value
s
()
{
{
return
$this
->
belongsToMany
(
Campaigns
::
class
,
'campaign_variables'
,
'variable_id'
,
'campaign_id'
)
return
$this
->
hasMany
(
DictionaryCampaignVariablePivot
::
class
,
'variable_id'
);
->
using
(
CampaignVariable
::
class
)
->
withPivot
(
CampaignVariable
::
getWithPivot
())
->
withTimestamps
();
}
}
}
}
database/factories/CampaingFactory.php
View file @
a46b84a
...
@@ -5,6 +5,6 @@ use Faker\Generator as Faker;
...
@@ -5,6 +5,6 @@ use Faker\Generator as Faker;
$factory
->
define
(
App\Models\Campaigns
::
class
,
function
(
Faker
$faker
)
{
$factory
->
define
(
App\Models\Campaigns
::
class
,
function
(
Faker
$faker
)
{
return
[
return
[
'name'
=>
$faker
->
name
,
'name'
=>
$faker
->
name
,
'external_id'
=>
$faker
->
randomNumber
()
'external_id'
=>
$faker
->
unique
()
->
randomNumber
()
];
];
});
});
database/factories/DictionaryFactory.php
View file @
a46b84a
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
View file @
a46b84a
...
@@ -25,9 +25,9 @@ class CreateDictionaryCampaignsTable extends Migration
...
@@ -25,9 +25,9 @@ class CreateDictionaryCampaignsTable extends Migration
$table
->
foreign
(
'campaign_id'
)
->
references
(
'id'
)
->
on
(
'campaigns'
)
$table
->
foreign
(
'campaign_id'
)
->
references
(
'id'
)
->
on
(
'campaigns'
)
->
onDelete
(
"cascade"
);
->
cascadeOnDelete
(
);
$table
->
foreign
(
'dictionary_id'
)
->
references
(
'id'
)
->
on
(
'dictionaries'
)
$table
->
foreign
(
'dictionary_id'
)
->
references
(
'id'
)
->
on
(
'dictionaries'
)
->
onDelete
(
"cascade"
);
->
cascadeOnDelete
(
);
});
});
}
}
...
...
database/migrations/2021_05_17_1
01448_create
_campaign_variables_table.php
→
database/migrations/2021_05_17_1
51448_create_dictionary
_campaign_variables_table.php
View file @
a46b84a
...
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
...
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
class
CreateCampaignVariablesTable
extends
Migration
class
Create
Dictionary
CampaignVariablesTable
extends
Migration
{
{
/**
/**
* Run the migrations.
* Run the migrations.
...
@@ -13,15 +13,15 @@ class CreateCampaignVariablesTable extends Migration
...
@@ -13,15 +13,15 @@ class CreateCampaignVariablesTable extends Migration
*/
*/
public
function
up
()
public
function
up
()
{
{
Schema
::
create
(
'campaign_variables'
,
function
(
Blueprint
$table
)
{
Schema
::
create
(
'
dictionary_
campaign_variables'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
id
();
$table
->
bigInteger
(
'campaign_id'
)
->
unsigned
();
$table
->
bigInteger
(
'
dictionary_
campaign_id'
)
->
unsigned
();
$table
->
bigInteger
(
'variable_id'
)
->
unsigned
();
$table
->
bigInteger
(
'variable_id'
)
->
unsigned
();
$table
->
string
(
'value'
,
255
);
$table
->
string
(
'value'
,
255
);
$table
->
timestamps
();
$table
->
timestamps
();
$table
->
foreign
(
'
campaign_id'
)
->
references
(
'id'
)
->
on
(
'
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'
)
->
cascadeOnDelete
();
->
cascadeOnDelete
();
...
@@ -35,6 +35,6 @@ class CreateCampaignVariablesTable extends Migration
...
@@ -35,6 +35,6 @@ class CreateCampaignVariablesTable extends Migration
*/
*/
public
function
down
()
public
function
down
()
{
{
Schema
::
dropIfExists
(
'campaign_variables'
);
Schema
::
dropIfExists
(
'
dictionary_
campaign_variables'
);
}
}
}
}
resources/js/Pages/CampaignVariables/Edit.vue
View file @
a46b84a
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
{{
token
.
login
}}
{{
token
.
login
}}
</inertia-link>
</inertia-link>
<span
class=
"text-indigo-400 font-medium"
>
/
</span>
<span
class=
"text-indigo-400 font-medium"
>
/
</span>
{{
dictionary
.
name
}}
<span
class=
"text-indigo-400 font-medium"
>
/
</span>
{{
campaign
.
name
}}
{{
campaign
.
name
}}
</h1>
</h1>
<div
class=
"mb-6 flex justify-between items-center"
>
<div
class=
"mb-6 flex justify-between items-center"
>
...
@@ -113,15 +115,15 @@
...
@@ -113,15 +115,15 @@
@
click=
"edit(variable.id, [
@
click=
"edit(variable.id, [
{
{
name: 'value',
name: 'value',
val: !variable.
c
ampaign
val: !variable.
dictionaryC
ampaign
? ''
? ''
: variable.
campaign.pivot
.value,
: variable.
dictionaryCampaign
.value,
},
},
])"
])"
>
>
{{
!
variable
.
c
ampaign
{{
!
variable
.
dictionaryC
ampaign
?
variable
.
default_value
?
variable
.
default_value
:
variable
.
campaign
.
pivot
.
value
}}
:
variable
.
dictionaryCampaign
.
value
}}
</div>
</div>
<div
v-else
class=
"inline-flex"
>
<div
v-else
class=
"inline-flex"
>
<text-input
v-model=
"inputs[variable.id].value.val"
<text-input
v-model=
"inputs[variable.id].value.val"
...
@@ -184,6 +186,7 @@
...
@@ -184,6 +186,7 @@
props
:
{
props
:
{
token
:
Object
,
token
:
Object
,
variables
:
Array
,
variables
:
Array
,
dictionary
:
Object
,
campaign
:
Object
,
campaign
:
Object
,
errors
:
Object
,
errors
:
Object
,
},
},
...
@@ -199,7 +202,7 @@
...
@@ -199,7 +202,7 @@
watch
:
{},
watch
:
{},
methods
:
{
methods
:
{
add
()
{
add
()
{
this
.
$inertia
.
post
(
this
.
route
(
'token.campaign.variables'
,
[
this
.
token
.
id
,
this
.
campaign
.
id
]),
{
this
.
$inertia
.
post
(
this
.
route
(
'token.campaign.variables'
,
[
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
,
...
@@ -250,11 +253,11 @@
...
@@ -250,11 +253,11 @@
this
.
editCancel
(
campaign_var_id
,
name
);
this
.
editCancel
(
campaign_var_id
,
name
);
});
});
this
.
$inertia
[
method
](
this
.
route
(
'token.campaign.variables'
,
[
this
.
token
.
id
,
this
.
campaign
.
id
]),
data
);
this
.
$inertia
[
method
](
this
.
route
(
'token.campaign.variables'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
]),
data
);
},
},
destroy
(
campaign_var_id
)
{
destroy
(
campaign_var_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
.
campaign
.
id
,
campaign_var_id
]));
this
.
$inertia
.
delete
(
this
.
route
(
'token.campaign.variable.destroy'
,
[
this
.
token
.
id
,
this
.
dictionary
.
id
,
this
.
campaign
.
id
,
campaign_var_id
]));
}
}
},
},
},
},
...
...
resources/js/Pages/Tokens/CitySettings.vue
View file @
a46b84a
...
@@ -58,12 +58,12 @@
...
@@ -58,12 +58,12 @@
<th
class=
"px-6 pt-6 pb-4"
>
Синхронизировать?
</th>
<th
class=
"px-6 pt-6 pb-4"
>
Синхронизировать?
</th>
<th></th>
<th></th>
</tr>
</tr>
<tr
v-if=
"city.campaigns.length"
:key=
"campaign.id"
v-for=
"campaign in city.campaigns"
>
<tr
v-if=
"city.campaigns.length"
:key=
"campaign.
pivot.
id"
v-for=
"campaign in city.campaigns"
>
<td
class=
"border-t"
></td>
<td
class=
"border-t"
></td>
<td
class=
"border-t"
>
<td
class=
"border-t"
>
<span
class=
"px-6 py-4 flex items-center focus:text-indigo-500"
>
<span
class=
"px-6 py-4 flex items-center focus:text-indigo-500"
>
<inertia-link
class=
"hover:text-indigo-500 focus:text-indigo-500"
<inertia-link
class=
"hover:text-indigo-500 focus:text-indigo-500"
:href=
"route('token.campaign.variables', [token.id, campaign.id])"
:href=
"route('token.campaign.variables', [token.id, c
ity.id, c
ampaign.id])"
>
>
{{
campaign
.
pivot
.
name
}}
{{
campaign
.
pivot
.
name
}}
</inertia-link>
</inertia-link>
...
...
routes/web.php
View file @
a46b84a
...
@@ -181,10 +181,10 @@ Route::post('token/campaigns/enabled/{token}/{campaign_id}', [TokensController::
...
@@ -181,10 +181,10 @@ Route::post('token/campaigns/enabled/{token}/{campaign_id}', [TokensController::
->
name
(
'token.campaign.enabled'
)
->
name
(
'token.campaign.enabled'
)
->
middleware
(
'auth'
);
->
middleware
(
'auth'
);
Route
::
any
(
'token/campaigns/vars/{token}/{campaign_id}'
,
CampaignVariablesController
::
class
)
Route
::
any
(
'token/campaigns/vars/{token}/{
dictionary_id}/{
campaign_id}'
,
CampaignVariablesController
::
class
)
->
name
(
'token.campaign.variables'
)
->
name
(
'token.campaign.variables'
)
->
middleware
(
'auth'
);
->
middleware
(
'auth'
);
Route
::
delete
(
'token/campaigns/vars/{token}/{campaign_id}/{variable_id}'
,
[
CampaignVariablesController
::
class
,
'destroy'
])
Route
::
delete
(
'token/campaigns/vars/{token}/{
dictionary_id}/{
campaign_id}/{variable_id}'
,
[
CampaignVariablesController
::
class
,
'destroy'
])
->
name
(
'token.campaign.variable.destroy'
)
->
name
(
'token.campaign.variable.destroy'
)
->
middleware
(
'auth'
);
->
middleware
(
'auth'
);
...
...
tests/Feature/CityTest.php
View file @
a46b84a
...
@@ -60,7 +60,8 @@ class CityTest extends TestCase
...
@@ -60,7 +60,8 @@ class CityTest extends TestCase
]);
]);
}
}
public
function
test_add_city_and_variables
(){
public
function
test_add_city_and_variables
()
{
$ids
=
Dictionary
::
all
()
->
pluck
(
'id'
);
$ids
=
Dictionary
::
all
()
->
pluck
(
'id'
);
$this
->
actingAs
(
$this
->
user
)
$this
->
actingAs
(
$this
->
user
)
...
@@ -71,9 +72,9 @@ class CityTest extends TestCase
...
@@ -71,9 +72,9 @@ class CityTest extends TestCase
->
assertStatus
(
302
);
->
assertStatus
(
302
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
assertEquals
(
$this
->
token
->
cities
->
count
(),
1
);
$this
->
assertEquals
(
1
,
$this
->
token
->
cities
->
count
()
);
foreach
(
$this
->
token
->
cities
as
$city
){
foreach
(
$this
->
token
->
cities
as
$city
)
{
$this
->
assertEquals
(
$city
->
campaigns
->
count
(),
2
);
$this
->
assertEquals
(
2
,
$city
->
campaigns
->
count
()
);
}
}
$this
->
actingAs
(
$this
->
user
)
$this
->
actingAs
(
$this
->
user
)
...
@@ -84,9 +85,9 @@ class CityTest extends TestCase
...
@@ -84,9 +85,9 @@ class CityTest extends TestCase
->
assertStatus
(
302
);
->
assertStatus
(
302
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
assertEquals
(
$this
->
token
->
cities
->
count
(),
2
);
$this
->
assertEquals
(
2
,
$this
->
token
->
cities
->
count
()
);
foreach
(
$this
->
token
->
cities
as
$city
){
foreach
(
$this
->
token
->
cities
as
$city
)
{
$this
->
assertEquals
(
$city
->
campaigns
->
count
(),
2
);
$this
->
assertEquals
(
2
,
$city
->
campaigns
->
count
()
);
}
}
$this
->
actingAs
(
$this
->
user
)
$this
->
actingAs
(
$this
->
user
)
...
@@ -97,9 +98,9 @@ class CityTest extends TestCase
...
@@ -97,9 +98,9 @@ class CityTest extends TestCase
->
assertStatus
(
302
);
->
assertStatus
(
302
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
token
->
load
(
'cities.campaigns'
);
$this
->
assertEquals
(
$this
->
token
->
cities
->
count
(),
3
);
$this
->
assertEquals
(
3
,
$this
->
token
->
cities
->
count
()
);
foreach
(
$this
->
token
->
cities
as
$city
){
foreach
(
$this
->
token
->
cities
as
$city
)
{
$this
->
assertEquals
(
$city
->
campaigns
->
count
(),
2
);
$this
->
assertEquals
(
2
,
$city
->
campaigns
->
count
()
);
}
}
...
@@ -107,8 +108,9 @@ class CityTest extends TestCase
...
@@ -107,8 +108,9 @@ class CityTest extends TestCase
$this
->
actingAs
(
$this
->
user
)
$this
->
actingAs
(
$this
->
user
)
->
post
(
route
(
'token.campaign.variables'
,
[
->
post
(
route
(
'token.campaign.variables'
,
[
'token'
=>
$this
->
token
->
id
,
'token'
=>
$this
->
token
->
id
,
'dictionary_id'
=>
$this
->
token
->
cities
[
0
]
->
getKey
(),
'campaign_id'
=>
$camp
->
id
'campaign_id'
=>
$camp
->
id
]),[
]),
[
'variable'
=>
'add'
,
'variable'
=>
'add'
,
'name'
=>
'test'
,
'name'
=>
'test'
,
'default_value'
=>
'default'
,
'default_value'
=>
'default'
,
...
@@ -116,14 +118,19 @@ class CityTest extends TestCase
...
@@ -116,14 +118,19 @@ class CityTest extends TestCase
])
])
->
assertStatus
(
302
);
->
assertStatus
(
302
);
foreach
(
$this
->
token
->
cities
as
$city
){
foreach
(
$city
->
campaigns
as
$campaign
){
foreach
(
$this
->
token
->
cities
as
$city
)
{
$this
->
assertEquals
(
$campaign
->
variables
->
count
(),
1
);
foreach
(
$city
->
campaigns
as
$campaign
)
{
foreach
(
$campaign
->
variables
as
$var
){
if
(
$campaign
->
id
==
$camp
->
id
)
{
if
(
$campaign
->
id
==
$camp
->
id
){
$this
->
assertEquals
(
1
,
$campaign
->
dictionaryCampaignVariables
->
count
());
$this
->
assertEquals
(
$var
->
value
,
'test_value'
);
}
else
{
$this
->
assertEquals
(
0
,
$campaign
->
dictionaryCampaignVariables
->
count
());
}
foreach
(
$campaign
->
dictionaryCampaignVariables
as
$var
)
{
if
(
$campaign
->
id
==
$camp
->
id
)
{
$this
->
assertEquals
(
'test_value'
,
$var
->
value
);
}
else
{
}
else
{
$this
->
assertEquals
(
$var
->
value
,
'default'
);
$this
->
assertEquals
(
'default'
,
$var
->
value
);
}
}
}
}
}
}
...
@@ -137,16 +144,25 @@ class CityTest extends TestCase
...
@@ -137,16 +144,25 @@ class CityTest extends TestCase
->
assertStatus
(
302
);
->
assertStatus
(
302
);
$this
->
token2
->
load
(
'cities.campaigns'
);
$this
->
token2
->
load
(
'cities.campaigns'
);
$this
->
assertEquals
(
$this
->
token2
->
cities
->
count
(),
1
);
$this
->
assertEquals
(
1
,
$this
->
token2
->
cities
->
count
()
);
foreach
(
$this
->
token2
->
cities
as
$city
){
foreach
(
$this
->
token2
->
cities
as
$city
)
{
$this
->
assertEquals
(
$city
->
campaigns
->
count
(),
2
);
$this
->
assertEquals
(
2
,
$city
->
campaigns
->
count
()
);
}
}
foreach
(
$this
->
token2
->
cities
as
$city
){
foreach
(
$this
->
token2
->
cities
as
$city
)
{
foreach
(
$city
->
campaigns
as
$campaign
){
foreach
(
$city
->
campaigns
as
$campaign
)
{
$this
->
assertEquals
(
$campaign
->
variables
->
count
(),
1
);
$campaign
->
load
(
'dictionaryCampaignVariables'
);
foreach
(
$campaign
->
variables
as
$var
){
if
(
$campaign
->
id
==
$camp
->
id
)
{
$this
->
assertEquals
(
$var
->
value
,
'default'
);
$this
->
assertEquals
(
1
,
$campaign
->
dictionaryCampaignVariables
->
count
());
}
else
{
$this
->
assertEquals
(
0
,
$campaign
->
dictionaryCampaignVariables
->
count
());
}
foreach
(
$campaign
->
dictionaryCampaignVariables
as
$var
)
{
if
(
$campaign
->
id
==
$camp
->
id
)
{
$this
->
assertEquals
(
1
,
$campaign
->
dictionaryCampaignVariables
->
count
());
}
else
{
$this
->
assertEquals
(
0
,
$campaign
->
dictionaryCampaignVariables
->
count
());
}
}
}
}
}
}
}
...
...
tests/Unit/CityTest.php
View file @
a46b84a
...
@@ -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
;
use
App\Models\Pivots\DictionaryCampaign
Pivot
;
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
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
Pivot
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
...
...
tests/Unit/ReplaceByVariablesTest.php
View file @
a46b84a
...
@@ -4,6 +4,9 @@ namespace Tests\Unit;
...
@@ -4,6 +4,9 @@ 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\Pivots\DictionaryCampaignPivot
;
use
App\Models\Pivots\DictionaryCampaignVariablePivot
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Models\User
;
use
App\Models\User
;
use
App\Models\Variable
;
use
App\Models\Variable
;
...
@@ -29,52 +32,68 @@ class ReplaceByVariablesTest extends TestCase
...
@@ -29,52 +32,68 @@ class ReplaceByVariablesTest extends TestCase
'owner'
=>
true
,
'owner'
=>
true
,
]);
]);
$this
->
token_main
=
factory
(
Tokens
::
class
)
->
create
([
'type'
=>
Tokens
::
MAIN
,
'created_by'
=>
$this
->
user
->
getKey
()
]);
$this
->
token
=
factory
(
Tokens
::
class
)
->
create
([
$this
->
token
=
factory
(
Tokens
::
class
)
->
create
([
'created_by'
=>
$this
->
user
->
getKey
()
'created_by'
=>
$this
->
user
->
getKey
()
]);
]);
$this
->
campaign
=
factory
(
Campaigns
::
class
)
->
create
([
$this
->
campaign
=
factory
(
Campaigns
::
class
)
->
create
([
'external_id'
=>
1
,
'manage'
=>
true
,
'manage'
=>
true
,
'token'
=>
$this
->
token
,
'token'
=>
$this
->
token_main
,
]);
$this
->
dictionary
=
factory
(
Dictionary
::
class
)
->
create
([
'token_id'
=>
$this
->
token
,
'type'
=>
Dictionary
::
CITY
,
]);
]);
$this
->
dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$this
->
token_main
->
campaignsForManaged
->
keyBy
(
$this
->
token_main
->
campaignsForManaged
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaignPivot
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
);
$this
->
variable
=
factory
(
Variable
::
class
)
->
create
([
$this
->
variable
=
factory
(
Variable
::
class
)
->
create
([
'name'
=>
'var'
,
'name'
=>
'var'
,
'default_value'
=>
'var value'
,
'default_value'
=>
'var value'
,
]);
]);
$this
->
campaign
->
variables
()
->
sync
([
$this
->
variable
->
getKey
()
=>
[
'value'
=>
'custom var value'
,
]
]);
$this
->
variable_2
=
factory
(
Variable
::
class
)
->
create
([
$this
->
variable_2
=
factory
(
Variable
::
class
)
->
create
([
'name'
=>
'vartwo'
,
'name'
=>
'vartwo'
,
'default_value'
=>
'vartwo value'
,
'default_value'
=>
'vartwo value'
,
]);
]);
$this
->
dictionaryCampaign
=
DictionaryCampaignPivot
::
first
();
$this
->
dictionaryCampaign
->
dictionaryCampaignVariables
()
->
create
([
'variable_id'
=>
$this
->
variable
->
getKey
(),
'value'
=>
'custom var value'
,
]);
}
}
public
function
testReplaceByVariables
()
public
function
testReplaceByVariables
()
{
{
$this
->
assertEquals
(
1
,
Tokens
::
count
());
$this
->
assertEquals
(
2
,
Tokens
::
count
());
$this
->
assertEquals
(
1
,
Campaigns
::
count
());
$this
->
assertEquals
(
1
,
Campaigns
::
count
());
$this
->
assertEquals
(
2
,
Variable
::
count
());
$this
->
assertEquals
(
2
,
Variable
::
count
());
$this
->
assertEquals
(
1
,
$this
->
campaign
->
v
ariables
->
count
());
$this
->
assertEquals
(
1
,
$this
->
campaign
->
dictionaryCampaignV
ariables
->
count
());
$variable_list
=
[];
$variable_list
=
[];
foreach
(
Variable
::
all
()
as
$variable
)
{
foreach
(
Variable
::
all
()
as
$variable
)
{
$
campaign
=
$variable
->
campaign
s
()
$
dictionaryCampaignVariable
=
$variable
->
value
s
()
->
where
(
'
campaign_id'
,
$this
->
c
ampaign
->
getKey
())
->
where
(
'
dictionary_campaign_id'
,
$this
->
dictionaryC
ampaign
->
getKey
())
->
first
();
->
first
();
$value
=
(
$value
=
(
$
campaign
$
dictionaryCampaignVariable
?
$
campaign
->
pivot
->
value
?
$
dictionaryCampaignVariable
->
value
:
$variable
->
default_value
:
$variable
->
default_value
);
);
...
@@ -84,6 +103,5 @@ class ReplaceByVariablesTest extends TestCase
...
@@ -84,6 +103,5 @@ class ReplaceByVariablesTest extends TestCase
$this
->
assertEquals
(
'String "custom var value"'
,
StrReplaceByVariables
::
getInstance
(
'String "%var%"'
,
$variable_list
)
->
get
());
$this
->
assertEquals
(
'String "custom var value"'
,
StrReplaceByVariables
::
getInstance
(
'String "%var%"'
,
$variable_list
)
->
get
());
$this
->
assertEquals
(
'String "vartwo value"'
,
StrReplaceByVariables
::
getInstance
(
'String "%vartwo%"'
,
$variable_list
)
->
get
());
$this
->
assertEquals
(
'String "vartwo value"'
,
StrReplaceByVariables
::
getInstance
(
'String "%vartwo%"'
,
$variable_list
)
->
get
());
}
}
}
}
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