Commit 76c0b38d by Vladislav

#19463 Реализация методов обработки полей РК с заменой переменных.

1 parent 1712c1bf
......@@ -15,3 +15,4 @@ Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
_ide_helper.php
......@@ -32,15 +32,15 @@ class CampaignVariablesController extends Controller
switch (request()->method()) {
case 'GET':
$variables = Variable::defaultOrderBy()->get()->transform(function (Variable $variable) use ($campaign) {
$variable->campaign = $variable->campaigns()
->where('campaign_id', $campaign->getKey())->first();
return $variable;
});
$variables = Variable::defaultOrderBy()->get();
return Inertia::render('CampaignVariables/Edit', [
'variables' => $variables,
'variables' => $variables->transform(function (Variable $variable) use ($campaign) {
$data = $variable->toArray();
$data['campaign'] = $variable->campaigns()
->where('campaign_id', $campaign->getKey())->first();
return $data;
}),
'token' => $token,
'campaign' => $campaign,
]);
......
......@@ -2,6 +2,28 @@
namespace App\Models;
/**
* App\Models\Account
*
* @property int $id
* @property string $name
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Contact[] $contacts
* @property-read int|null $contacts_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Organization[] $organizations
* @property-read int|null $organizations_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $users
* @property-read int|null $users_count
* @method static \Illuminate\Database\Eloquent\Builder|Account newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Account newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Account query()
* @method static \Illuminate\Database\Eloquent\Builder|Account whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Account extends Model
{
public function users()
......
......@@ -4,6 +4,46 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\AdGroup
*
* @property int $id
* @property int $campaign_id
* @property int $external_id
* @property int $campaign_external_id
* @property string|null $name
* @property string|null $tracking_params
* @property string|null $status
* @property string|null $serving_status
* @property string|null $type
* @property string|null $sub_type
* @property array|null $restricted_region_ids
* @property array|null $region_ids
* @property array|null $negative_keywords
* @property array|null $negative_keyword_shared_set_ids
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup query()
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereCampaignExternalId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereCampaignId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereExternalId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereNegativeKeywordSharedSetIds($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereNegativeKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereRegionIds($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereRestrictedRegionIds($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereServingStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereSubType($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereTrackingParams($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|AdGroup whereUpdatedAt($value)
* @mixin \Eloquent
*/
class AdGroup extends Model
{
const STATUS_ACCEPTED = 'ACCEPTED';
......
......@@ -7,6 +7,72 @@ use App\Models\Pivots\DictionaryCampaign;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Campaigns
*
* @property int $id
* @property int $token
* @property int $external_id
* @property string|null $name
* @property string|null $time_targeting
* @property string|null $negative_keywords
* @property string|null $blocked_ips
* @property string|null $excluded_sites
* @property string|null $daily_budget
* @property string|null $text_campaign_strategy_search
* @property string|null $text_campaign_strategy_network
* @property string|null $settings
* @property string|null $counter_ids
* @property int|null $relevant_keywords_setting_budget_percent
* @property int|null $relevant_keywords_setting_optimize_goal_id
* @property string|null $attribution_model
* @property string|null $priority_goals
* @property string|null $updated
* @property bool $manage
* @property bool $enabled
* @property \Illuminate\Support\Carbon|null $groups_loaded_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $dictionaries
* @property-read int|null $dictionaries_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $groups
* @property-read int|null $groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Variable[] $variables
* @property-read int|null $variables_count
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns notForEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns notForManaged()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns query()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereAttributionModel($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereBlockedIps($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereCounterIds($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereDailyBudget($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereEnabled($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereExcludedSites($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereExternalId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereGroupsLoadedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereManage($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereNegativeKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns wherePriorityGoals($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereRelevantKeywordsSettingBudgetPercent($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereRelevantKeywordsSettingOptimizeGoalId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereSettings($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTextCampaignStrategyNetwork($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTextCampaignStrategySearch($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTimeTargeting($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdated($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Campaigns extends Model
{
use HasFactory;
......
......@@ -4,6 +4,51 @@ namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* App\Models\Contact
*
* @property int $id
* @property int $account_id
* @property int|null $organization_id
* @property string $first_name
* @property string $last_name
* @property string|null $email
* @property string|null $phone
* @property string|null $address
* @property string|null $city
* @property string|null $region
* @property string|null $country
* @property string|null $postal_code
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read mixed $name
* @property-read \App\Models\Organization|null $organization
* @method static \Illuminate\Database\Eloquent\Builder|Contact filter(array $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Contact newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Contact newQuery()
* @method static \Illuminate\Database\Query\Builder|Contact onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Contact orderByName()
* @method static \Illuminate\Database\Eloquent\Builder|Contact query()
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereAccountId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereFirstName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereLastName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereOrganizationId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact wherePhone($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact wherePostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereRegion($value)
* @method static \Illuminate\Database\Eloquent\Builder|Contact whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|Contact withTrashed()
* @method static \Illuminate\Database\Query\Builder|Contact withoutTrashed()
* @mixin \Eloquent
*/
class Contact extends Model
{
use SoftDeletes;
......
......@@ -5,6 +5,36 @@ namespace App\Models;
use App\Models\Pivots\DictionaryCampaign;
use Illuminate\Database\Eloquent\Builder;
/**
* App\Models\Dictionary
*
* @property int $id
* @property int $region_id
* @property int|null $parent_id
* @property string $name
* @property string $type
* @property int|null $token_id
* @property bool $update
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @property-read \App\Models\Tokens|null $token
* @method static Builder|Dictionary defaultOrderBy()
* @method static Builder|Dictionary newModelQuery()
* @method static Builder|Dictionary newQuery()
* @method static Builder|Dictionary query()
* @method static Builder|Dictionary whereCreatedAt($value)
* @method static Builder|Dictionary whereId($value)
* @method static Builder|Dictionary whereName($value)
* @method static Builder|Dictionary whereParentId($value)
* @method static Builder|Dictionary whereRegionId($value)
* @method static Builder|Dictionary whereTokenId($value)
* @method static Builder|Dictionary whereType($value)
* @method static Builder|Dictionary whereUpdate($value)
* @method static Builder|Dictionary whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Dictionary extends Model
{
CONST CITY = 'City';
......
......@@ -5,6 +5,35 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Limits
*
* @property int $id
* @property int $token
* @property string $service
* @property string $method
* @property int $spent
* @property int $current
* @property int $day
* @property int $reserved
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Limits complited()
* @method static \Illuminate\Database\Eloquent\Builder|Limits newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Limits newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Limits query()
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereCurrent($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereDay($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereMethod($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereReserved($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereService($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereSpent($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Limits whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Limits extends Model
{
use HasFactory;
......
......@@ -4,6 +4,46 @@ namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* App\Models\Organization
*
* @property int $id
* @property int $account_id
* @property string $name
* @property string|null $email
* @property string|null $phone
* @property string|null $address
* @property string|null $city
* @property string|null $region
* @property string|null $country
* @property string|null $postal_code
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Contact[] $contacts
* @property-read int|null $contacts_count
* @method static \Illuminate\Database\Eloquent\Builder|Organization filter(array $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Organization newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Organization newQuery()
* @method static \Illuminate\Database\Query\Builder|Organization onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Organization query()
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereAccountId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization wherePhone($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization wherePostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereRegion($value)
* @method static \Illuminate\Database\Eloquent\Builder|Organization whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|Organization withTrashed()
* @method static \Illuminate\Database\Query\Builder|Organization withoutTrashed()
* @mixin \Eloquent
*/
class Organization extends Model
{
use SoftDeletes;
......
......@@ -6,6 +6,16 @@ use App\Models\Campaigns;
use App\Models\Variable;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* App\Models\Pivots\CampaignVariable
*
* @property-read Campaigns $campaign
* @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
*/
class CampaignVariable extends Pivot
{
protected $fillable = [
......
......@@ -6,6 +6,16 @@ use App\Models\Campaigns;
use App\Models\Dictionary;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* App\Models\Pivots\DictionaryCampaign
*
* @property-read Campaigns $campaign
* @property-read Dictionary $dictionary
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign query()
* @mixin \Eloquent
*/
class DictionaryCampaign extends Pivot
{
......@@ -37,12 +47,16 @@ class DictionaryCampaign extends Pivot
static public function copyPropertyInCampaign(Campaigns $campaign)
{
return collect(self::getWithPivot())
->filter(fn($property_name) => $property_name !== 'updated')
->filter(function ($property_name){
return $property_name !== 'updated';
})
->transform(function ($property_name) use ($campaign) {
return [
$property_name => $campaign->{$property_name}
];
})->flatMap(fn($val) => $val)->all();
})->flatMap(function ($val){
return $val;
})->all();
}
public function dictionary()
......
......@@ -4,6 +4,41 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Tokens
*
* @property int $id
* @property string $token
* @property string $login
* @property string $api
* @property string|null $type
* @property int $created_by
* @property string|null $timestamp
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $limit
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $cities
* @property-read int|null $cities_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Limits[] $limits
* @property-read int|null $limits_count
* @method static \Illuminate\Database\Eloquent\Builder|Tokens filter(array $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Tokens newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Tokens query()
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereApi($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereCreatedBy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLimit($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLogin($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereTimestamp($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Tokens extends Model
{
CONST MAIN = 'main';
......
......@@ -12,6 +12,46 @@ use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\URL;
use League\Glide\Server;
/**
* App\Models\User
*
* @property int $id
* @property int $account_id
* @property string $first_name
* @property string $last_name
* @property string $email
* @property string|null $password
* @property bool $owner
* @property string|null $photo_path
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \App\Models\Account $account
* @property-read mixed $name
* @method static \Illuminate\Database\Eloquent\Builder|User filter(array $filters)
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
* @method static \Illuminate\Database\Query\Builder|User onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|User orderByName()
* @method static \Illuminate\Database\Eloquent\Builder|User query()
* @method static \Illuminate\Database\Eloquent\Builder|User whereAccountId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereFirstName($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereLastName($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereOwner($value)
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|User wherePhotoPath($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereRole($role)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|User withTrashed()
* @method static \Illuminate\Database\Query\Builder|User withoutTrashed()
* @mixin \Eloquent
*/
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use SoftDeletes, Authenticatable, Authorizable;
......
......@@ -5,6 +5,26 @@ namespace App\Models;
use App\Models\Pivots\CampaignVariable;
use Illuminate\Database\Eloquent\Builder;
/**
* App\Models\Variable
*
* @property int $id
* @property string $name
* @property string $default_value
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @method static Builder|Variable defaultOrderBy()
* @method static Builder|Variable newModelQuery()
* @method static Builder|Variable newQuery()
* @method static Builder|Variable query()
* @method static Builder|Variable whereCreatedAt($value)
* @method static Builder|Variable whereId($value)
* @method static Builder|Variable whereName($value)
* @method static Builder|Variable whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Variable extends Model
{
protected $fillable = [
......
......@@ -32,6 +32,8 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
//
if (app()->environment() !== 'production') {
app()->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
}
}
<?php
namespace App\Service;
class StrReplaceByVariables
{
private $delimer = '%';
private $str;
private $variables;
/**
* @param string $str
* @param array $variables
*/
public function __construct($str, $variables)
{
foreach ($variables as $key => $variable) {
$variables["{$this->delimer}{$key}{$this->delimer}"] = $variable;
unset($variables[$key]);
}
$this->str = $str;
$this->variables = $variables;
}
static public function getInstance($str, $variables)
{
return new static($str, $variables);
}
/**
* @return string
*/
public function get()
{
return strtr($this->str, $this->variables);
}
}
......@@ -11,6 +11,7 @@
"php": "^7.3|^8.0",
"ext-exif": "*",
"ext-gd": "*",
"ext-json": "*",
"facade/ignition": "^2.3.6",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
......@@ -27,7 +28,10 @@
"phpunit/phpunit": "^9.3",
"reinink/remember-query-strings": "^0.1.0",
"tightenco/ziggy": "^0.8.0",
"ext-json": "*"
"itsgoingd/clockwork": "^5.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.10"
},
"config": {
"optimize-autoloader": true,
......@@ -36,7 +40,9 @@
},
"extra": {
"laravel": {
"dont-discover": []
"dont-discover": [
"barryvdh/laravel-ide-helper"
]
}
},
"autoload": {
......
This diff could not be displayed because it is too large.
......@@ -175,6 +175,8 @@ return [
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Clockwork\Support\Laravel\ClockworkServiceProvider::class,
],
/*
......@@ -227,6 +229,9 @@ return [
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Clockwork' => Clockwork\Support\Laravel\Facade::class,
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Enable Clockwork
|--------------------------------------------------------------------------
|
| You can explicitly enable or disable Clockwork here. When enabled, special
| headers for communication with the Clockwork Chrome extension will be
| included in your application responses and requests data will be available
| at /__clockwork url.
| When set to null, Clockwork behavior is controlled by app.debug setting.
| Default: null
|
*/
'enable' => env('CLOCKWORK_ENABLE', null),
/*
|--------------------------------------------------------------------------
| Features
|--------------------------------------------------------------------------
|
| You can enable or disable various Clockwork features here. Some features
| accept additional configuration (eg. slow query threshold for database).
|
*/
'features' => [
// Cache usage stats and cache queries including results
'cache' => [
'enabled' => env('CLOCKWORK_CACHE_ENABLED', true),
// Collect cache queries including results (high performance impact with a high number of queries)
'collect_queries' => env('CLOCKWORK_CACHE_QUERIES', false)
],
// Database usage stats and queries
'database' => [
'enabled' => env('CLOCKWORK_DATABASE_ENABLED', true),
// Collect database queries (high performance impact with a very high number of queries)
'collect_queries' => env('CLOCKWORK_DATABASE_COLLECT_QUERIES', true),
// Query execution time threshold in miliseconds after which the query will be marked as slow
'slow_threshold' => env('CLOCKWORK_DATABASE_SLOW_THRESHOLD'),
// Collect only slow database queries
'slow_only' => env('CLOCKWORK_DATABASE_SLOW_ONLY', false),
// Detect and report duplicate (N+1) queries
'detect_duplicate_queries' => env('CLOCKWORK_DATABASE_DETECT_DUPLICATE_QUERIES', false)
],
// Sent emails
'emails' => [
'enabled' => env('CLOCKWORK_EMAILS_ENABLED', true),
],
// Dispatched events
'events' => [
'enabled' => env('CLOCKWORK_EVENTS_ENABLED', true),
// Ignored events (framework events are ignored by default)
'ignored_events' => [
// App\Events\UserRegistered::class,
// 'user.registered'
],
],
// Laravel log (you can still log directly to Clockwork with laravel log disabled)
'log' => [
'enabled' => env('CLOCKWORK_LOG_ENABLED', true)
],
// Dispatched queue jobs
'queue' => [
'enabled' => env('CLOCKWORK_QUEUE_ENABLED', true)
],
// Redis commands
'redis' => [
'enabled' => env('CLOCKWORK_REDIS_ENABLED', true)
],
// Routes list
'routes' => [
'enabled' => env('CLOCKWORK_ROUTES_ENABLED', false)
],
// Rendered views
'views' => [
'enabled' => env('CLOCKWORK_VIEWS_ENABLED', true),
// Collect views including view data (high performance impact with a high number of views)
'collect_data' => env('CLOCKWORK_VIEWS_COLLECT_DATA', false),
// Use Twig profiler instead of Laravel events for apps using laravel-twigbridge (more precise, but does
// not support collecting view data)
'use_twig_profiler' => env('CLOCKWORK_VIEWS_USE_TWIG_PROFILER', false)
]
],
/*
|--------------------------------------------------------------------------
| Enable web UI
|--------------------------------------------------------------------------
|
| Enable or disable the Clockwork web UI available at http://your.app/__clockwork.
| You can also set whether to use the dark theme by default.
| Default: true
|
*/
'web' => env('CLOCKWORK_WEB', true),
/*
|--------------------------------------------------------------------------
| Artisan commands collection
|--------------------------------------------------------------------------
|
| You can enable or disable and configure collection of executed Artisan
| commands here.
|
*/
'artisan' => [
// Enable or disable collection of executed Artisan commands
'collect' => env('CLOCKWORK_ARTISAN_COLLECT', true),
// List of commands that should not be collected (built-in commands are not collected by default)
'except' => [
// 'inspire'
],
// List of commands that should be collected, any other command will not be collected if not empty
'only' => [
// 'inspire'
],
// Enable or disable collection of command output
'collect_output' => env('CLOCKWORK_ARTISAN_COLLECT_OUTPUT', false),
// Enable or disable collection of built-in Laravel commands
'except_laravel_commands' => env('CLOCKWORK_ARTISAN_EXCEPT_LARAVEL_COMMANDS', true)
],
/*
|--------------------------------------------------------------------------
| Queue jobs collection
|--------------------------------------------------------------------------
|
| You can enable or disable and configure collection of executed queue jobs
| here.
|
*/
'queue' => [
// Enable or disable collection of executed queue jobs
'collect' => env('CLOCKWORK_QUEUE_COLLECT', true),
// List of queue jobs that should not be collected
'except' => [
// App\Jobs\ExpensiveJob::class
],
// List of queue jobs that should be collected, any other queue job will not be collected if not empty
'only' => [
App\Jobs\Clients\SendEmailOrder::class,
App\Jobs\Clients\GenerateExportSale::class,
App\Jobs\Clients\SendEmailActivate::class,
App\Jobs\Systems\SendEmailRegistrationActivate::class,
App\Jobs\Systems\SendEmailReminder::class,
App\Jobs\Systems\SubsystemCreateSsl::class,
App\Jobs\Systems\SubsystemDelete::class,
App\Jobs\Systems\SubsystemDeleteSsl::class,
App\Jobs\Systems\SubsystemDeploy::class,
App\Jobs\Systems\SubsystemUpdate::class,
App\Jobs\Systems\SubsystemUpdateSsl::class,
App\Jobs\Systems\Evotor\SendEmailRegistration::class,
]
],
/*
|--------------------------------------------------------------------------
| Tests collection
|--------------------------------------------------------------------------
|
| You can enable or disable and configure collection of ran tests here.
|
*/
'tests' => [
// Enable or disable collection of ran tests
'collect' => env('CLOCKWORK_TESTS_COLLECT', false),
// List of tests that should not be collected
'except' => [
// Tests\Unit\ExampleTest::class
]
],
/*
|--------------------------------------------------------------------------
| Enable data collection, when Clockwork is disabled
|--------------------------------------------------------------------------
|
| This setting controls, whether data about application requests will be
| recorded even when Clockwork is disabled (useful for later analysis).
| Default: false
|
*/
'collect_data_always' => env('CLOCKWORK_COLLECT_DATA_ALWAYS', false),
/*
|--------------------------------------------------------------------------
| Metadata storage
|--------------------------------------------------------------------------
|
| You can configure how are the metadata collected by Clockwork stored.
| Valid options are: files or sql.
| Files storage stores the metadata in one-per-request files in a specified
| directory.
| Sql storage stores the metadata as rows in a sql database. You can specify
| the database by name if defined in database.php or by path to Sqlite
| database. Database table will be automatically created.
| Sql storage requires PDO.
|
*/
'storage' => env('CLOCKWORK_STORAGE', 'files'),
'storage_files_path' => env('CLOCKWORK_STORAGE_FILES_PATH', storage_path('clockwork')),
// Compress the metadata files using gzip, trading a little bit of performance for lower disk usage
'storage_files_compress' => env('CLOCKWORK_STORAGE_FILES_COMPRESS', false),
'storage_sql_database' => env('CLOCKWORK_STORAGE_SQL_DATABASE', storage_path('clockwork.sqlite')),
'storage_sql_table' => env('CLOCKWORK_STORAGE_SQL_TABLE', 'clockwork'),
/*
|--------------------------------------------------------------------------
| Metadata expiration
|--------------------------------------------------------------------------
|
| Maximum lifetime of the metadata in minutes, metadata for older requests
| will automatically be deleted when storing new requests.
| When set to false, metadata will never be deleted.
| Default: 1 week
|
*/
'storage_expiration' => env('CLOCKWORK_STORAGE_EXPIRATION', 60 * 24 * 7),
/*
|--------------------------------------------------------------------------
| Authentication
|--------------------------------------------------------------------------
|
| Clockwork can be configured to require authentication before allowing
/ access to the collected data. This is recommended when the application
/ is publicly accessible, as the metadata might contain sensitive information.
/ Setting to "true" enables authentication with a single password set below,
/ "false" disables authentication.
/ You can also pass a class name of a custom authentication implementation.
/ Default: false
|
*/
'authentication' => env('CLOCKWORK_AUTHENTICATION', false),
'authentication_password' => env('CLOCKWORK_AUTHENTICATION_PASSWORD', 'VerySecretPassword'),
/*
|--------------------------------------------------------------------------
| Disable data collection for certain URIs or methods
|--------------------------------------------------------------------------
|
| You can disable data collection for specific URIs by adding matching
| regular expressions here. You can also disable collecting all requests
| with a specific method.
|
*/
'filter_uris' => [
'/horizon/.*', // Laravel Horizon requests
'/telescope/.*', // Laravel Telescope requests
],
'filter_methods' => [
'options' // mostly used in the csrf pre-flight requests and is rarely of interest
],
/*
|--------------------------------------------------------------------------
| Enable collecting of stack traces
|--------------------------------------------------------------------------
|
| This setting controls, whether log messages and certain data sources, like
/ the database or cache data sources, should collect stack traces.
/ You might want to disable this if you are collecting 100s of queries or
/ log messages, as the stack traces can considerably increase the metadata size.
/ You can force collecting of stack trace for a single log call by passing
/ [ 'trace' => true ] as $context.
| Default: true
|
*/
'stack_traces' => [
// Enable or disable collecting of stack traces, when disabled only caller file and line number is collected
'enabled' => env('CLOCKWORK_STACK_TRACES_ENABLED', true),
// List of vendor names to skip when determining caller, common vendor are automatically added
'skip_vendors' => [
// 'phpunit'
],
// List of namespaces to skip when determining caller
'skip_namespaces' => [
// 'Laravel'
],
// List of class names to skip when determining caller
'skip_classes' => [
// App\CustomLog::class
],
// Limit of frames to be collected
'limit' => env('CLOCKWORK_STACK_TRACES_LIMIT', 10)
],
/*
|--------------------------------------------------------------------------
| Serialization
|--------------------------------------------------------------------------
|
| Configure how Clockwork serializes the collected data.
| Depth limits how many levels of multi-level arrays and objects have
| extended serialization (rest uses simple serialization).
| Blackbox allows you to specify classes which contents should be never
| serialized (eg. a service container class).
| Lowering depth limit and adding classes to blackbox lowers the memory
| usage and processing time.
|
*/
'serialization_depth' => env('CLOCKWORK_SERIALIZATION_DEPTH', 10),
'serialization_blackbox' => [
\Illuminate\Container\Container::class,
\Illuminate\Foundation\Application::class,
\Laravel\Lumen\Application::class
],
/*
|--------------------------------------------------------------------------
| Register helpers
|--------------------------------------------------------------------------
|
| This setting controls whether the "clock" helper function will be registered. You can use the "clock" function to
| quickly log something to Clockwork or access the Clockwork instance.
|
*/
'register_helpers' => env('CLOCKWORK_REGISTER_HELPERS', true),
/*
|--------------------------------------------------------------------------
| Send Headers for AJAX request
|--------------------------------------------------------------------------
|
| When trying to collect data the AJAX method can sometimes fail if it is
| missing required headers. For example, an API might require a version
| number using Accept headers to route the HTTP request to the correct
| codebase.
|
*/
'headers' => [
// 'Accept' => 'application/vnd.com.whatever.v1+json',
],
/*
|--------------------------------------------------------------------------
| Server-Timing
|--------------------------------------------------------------------------
|
| Clockwork supports the W3C Server Timing specification, which allows for
/ collecting a simple performance metrics in a cross-browser way. Eg. in
/ Chrome, your app, database and timeline event timings will be shown
/ in the Dev Tools network tab.
/ This setting specifies the max number of timeline events that will be sent.
| When set to false, Server-Timing headers will not be set.
| Default: 10
|
*/
'server_timing' => env('CLOCKWORK_SERVER_TIMING', 10)
];
<?php
return array(
/*
|--------------------------------------------------------------------------
| Filename & Format
|--------------------------------------------------------------------------
|
| The default filename (without extension) and the format (php or json)
|
*/
'filename' => '_ide_helper',
'format' => 'php',
/*
|--------------------------------------------------------------------------
| Where to write the PhpStorm specific meta file
|--------------------------------------------------------------------------
|
| PhpStorm also supports the directory `.phpstorm.meta.php/` with arbitrary
| files in it, should you need additional files for your project; e.g.
| `.phpstorm.meta.php/laravel_ide_Helper.php'.
|
*/
'meta_filename' => '.phpstorm.meta.php',
/*
|--------------------------------------------------------------------------
| Fluent helpers
|--------------------------------------------------------------------------
|
| Set to true to generate commonly used Fluent methods
|
*/
'include_fluent' => false,
/*
|--------------------------------------------------------------------------
| Factory Builders
|--------------------------------------------------------------------------
|
| Set to true to generate factory generators for better factory()
| method auto-completion.
|
*/
'include_factory_builders' => false,
/*
|--------------------------------------------------------------------------
| Write Model Magic methods
|--------------------------------------------------------------------------
|
| Set to false to disable write magic methods of model
|
*/
'write_model_magic_where' => true,
/*
|--------------------------------------------------------------------------
| Write Model relation count properties
|--------------------------------------------------------------------------
|
| Set to false to disable writing of relation count properties to model DocBlocks.
|
*/
'write_model_relation_count_properties' => true,
/*
|--------------------------------------------------------------------------
| Write Eloquent Model Mixins
|--------------------------------------------------------------------------
|
| This will add the necessary DocBlock mixins to the model class
| contained in the Laravel Framework. This helps the IDE with
| auto-completion.
|
| Please be aware that this setting changes a file within the /vendor directory.
|
*/
'write_eloquent_model_mixins' => false,
/*
|--------------------------------------------------------------------------
| Helper files to include
|--------------------------------------------------------------------------
|
| Include helper files. By default not included, but can be toggled with the
| -- helpers (-H) option. Extra helper files can be included.
|
*/
'include_helpers' => false,
'helper_files' => array(
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
),
/*
|--------------------------------------------------------------------------
| Model locations to include
|--------------------------------------------------------------------------
|
| Define in which directories the ide-helper:models command should look
| for models.
|
| glob patterns are supported to easier reach models in sub-directories,
| e.g. `app/Services/* /Models` (without the space)
|
*/
'model_locations' => array(
'app/Models',
),
/*
|--------------------------------------------------------------------------
| Models to ignore
|--------------------------------------------------------------------------
|
| Define which models should be ignored.
|
*/
'ignored_models' => array(
),
/*
|--------------------------------------------------------------------------
| Extra classes
|--------------------------------------------------------------------------
|
| These implementations are not really extended, but called with magic functions
|
*/
'extra' => array(
'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
'Session' => array('Illuminate\Session\Store'),
),
'magic' => array(),
/*
|--------------------------------------------------------------------------
| Interface implementations
|--------------------------------------------------------------------------
|
| These interfaces will be replaced with the implementing class. Some interfaces
| are detected by the helpers, others can be listed below.
|
*/
'interfaces' => array(
),
/*
|--------------------------------------------------------------------------
| Support for custom DB types
|--------------------------------------------------------------------------
|
| This setting allow you to map any custom database type (that you may have
| created using CREATE TYPE statement or imported using database plugin
| / extension to a Doctrine type.
|
| Each key in this array is a name of the Doctrine2 DBAL Platform. Currently valid names are:
| 'postgresql', 'db2', 'drizzle', 'mysql', 'oracle', 'sqlanywhere', 'sqlite', 'mssql'
|
| This name is returned by getName() method of the specific Doctrine/DBAL/Platforms/AbstractPlatform descendant
|
| The value of the array is an array of type mappings. Key is the name of the custom type,
| (for example, "jsonb" from Postgres 9.4) and the value is the name of the corresponding Doctrine2 type (in
| our case it is 'json_array'. Doctrine types are listed here:
| http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html
|
| So to support jsonb in your models when working with Postgres, just add the following entry to the array below:
|
| "postgresql" => array(
| "jsonb" => "json_array",
| ),
|
*/
'custom_db_types' => array(
),
/*
|--------------------------------------------------------------------------
| Support for camel cased models
|--------------------------------------------------------------------------
|
| There are some Laravel packages (such as Eloquence) that allow for accessing
| Eloquent model properties via camel case, instead of snake case.
|
| Enabling this option will support these packages by saving all model
| properties as camel case, instead of snake case.
|
| For example, normally you would see this:
|
| * @property \Illuminate\Support\Carbon $created_at
| * @property \Illuminate\Support\Carbon $updated_at
|
| With this enabled, the properties will be this:
|
| * @property \Illuminate\Support\Carbon $createdAt
| * @property \Illuminate\Support\Carbon $updatedAt
|
| Note, it is currently an all-or-nothing option.
|
*/
'model_camel_case_properties' => false,
/*
|--------------------------------------------------------------------------
| Property Casts
|--------------------------------------------------------------------------
|
| Cast the given "real type" to the given "type".
|
*/
'type_overrides' => array(
'integer' => 'int',
'boolean' => 'bool',
),
/*
|--------------------------------------------------------------------------
| Include DocBlocks from classes
|--------------------------------------------------------------------------
|
| Include DocBlocks from classes to allow additional code inspection for
| magic methods and properties.
|
*/
'include_class_docblocks' => false,
);
<?php
use App\Models\Campaigns;
use Faker\Generator as Faker;
$factory->define(App\Models\Campaigns::class, function (Faker $faker) {
......
<?php
use App\Models\Campaigns;
use Faker\Generator as Faker;
$factory->define(App\Models\Dictionary::class, function (Faker $faker) {
......
<?php
use Faker\Generator as Faker;
$factory->define(App\Models\Variable::class, function (Faker $faker) {
return [];
});
......@@ -16,6 +16,7 @@ class CreateVariablesTable extends Migration
Schema::create('variables', function (Blueprint $table) {
$table->id();
$table->string('name', 255);
$table->string('default_value', 255);
$table->timestamps();
});
}
......
# Developer
Generate local ide helper meta PHPDoc
```shell script
php artisan ide-helper:generate
php artisan ide-helper:meta
```
# Ping CRM
A demo application to illustrate how Inertia.js works.
......
*.json
*.json.gz
index
<?php
namespace Tests\Unit;
use App\Models\Account;
use App\Models\Campaigns;
use App\Models\Tokens;
use App\Models\User;
use App\Models\Variable;
use App\Service\StrReplaceByVariables;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ReplaceByVariablesTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$account = Account::create(['name' => 'Acme Corporation']);
$this->user = factory(User::class)->create([
'account_id' => $account->id,
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'owner' => true,
]);
$this->token = factory(Tokens::class)->create([
'created_by' => $this->user->getKey()
]);
$this->campaign = factory(Campaigns::class)->create([
'external_id' => 1,
'manage' => true,
'token' => $this->token,
]);
$this->variable = factory(Variable::class)->create([
'name' => 'var',
'default_value' => 'var value',
]);
$this->campaign->variables()->sync([
$this->variable->getKey() => [
'value' => 'custom var value',
]
]);
$this->variable_2 = factory(Variable::class)->create([
'name' => 'vartwo',
'default_value' => 'vartwo value',
]);
}
public function testReplaceByVariables()
{
$this->assertEquals(1, Tokens::count());
$this->assertEquals(1, Campaigns::count());
$this->assertEquals(2, Variable::count());
$this->assertEquals(1, $this->campaign->variables->count());
$variable_list = [];
foreach (Variable::all() as $variable) {
$campaign = $variable->campaigns()
->where('campaign_id', $this->campaign->getKey())
->first();
$value = (
$campaign
? $campaign->pivot->value
: $variable->default_value
);
$variable_list[$variable->name] = $value;
}
$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());
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!