Browse Source

Shop module rewrite

master
Egorka 6 years ago
parent
commit
0eb69526a3
  1. 1
      Yii.php
  2. 10
      core/components/LanguageTranslateTrait.php
  3. 10
      core/events/EventTrait.php
  4. 21
      core/helpers/PhoneHelper.php

1
Yii.php

@ -27,6 +27,7 @@ abstract class BaseApplication extends yii\base\Application
* Include only Web application related components here * Include only Web application related components here
* *
* @property \core\components\modules\ModuleManager $moduleManager Module manager * @property \core\components\modules\ModuleManager $moduleManager Module manager
* @property \yii\db\Query $queue
* *
* @property \core\entities\user\User $user The user component. This property is read-only. Extended component. * @property \core\entities\user\User $user The user component. This property is read-only. Extended component.
* @ property \app\components\MyResponse $response The response component. This property is read-only. Extended component. * @ property \app\components\MyResponse $response The response component. This property is read-only. Extended component.

10
core/components/LanguageTranslateTrait.php

@ -21,6 +21,7 @@ trait LanguageTranslateTrait
* @var string the name of the lang field of the translation table. Default to 'language'. * @var string the name of the lang field of the translation table. Default to 'language'.
*/ */
public $languageField = 'language'; public $languageField = 'language';
/** /**
* Scope for querying by languages * Scope for querying by languages
* *
@ -33,13 +34,17 @@ trait LanguageTranslateTrait
{ {
$language = $language ?: Yii::$app->language; $language = $language ?: Yii::$app->language;
if (!isset($this->with['translations'])) { if (!isset($this->with['translations'])) {
$this->with(['translation' => function ($query) use ($language, $abridge) { $this->with([
'translation' => function ($query) use ($language, $abridge) {
/** @var ActiveQuery $query */ /** @var ActiveQuery $query */
$query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]); $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]);
}]);
} }
]);
}
return $this; return $this;
} }
/** /**
* Scope for querying by all languages * Scope for querying by all languages
* @return $this * @return $this
@ -50,6 +55,7 @@ trait LanguageTranslateTrait
unset($this->with['translation']); unset($this->with['translation']);
} }
$this->with('translations'); $this->with('translations');
return $this; return $this;
} }
} }

10
core/events/EventTrait.php

@ -4,17 +4,17 @@ namespace core\events;
trait EventTrait trait EventTrait
{ {
private $events = []; private $_events = [];
protected function recordEvent($event): void public function recordEvent($event): void
{ {
$this->events[] = $event; $this->_events[] = $event;
} }
public function releaseEvents(): array public function releaseEvents(): array
{ {
$events = $this->events; $events = $this->_events;
$this->events = []; $this->_events = [];
return $events; return $events;
} }
} }

21
core/helpers/PhoneHelper.php

@ -0,0 +1,21 @@
<?php
/**
* Created by Error202
* Date: 23.09.2018
*/
namespace core\helpers;
class PhoneHelper
{
public static function normalizePhone(string $phone): string
{
return preg_replace('/[^0-9]/', '', $phone);
}
public static function isCorrect(string $phone): bool
{
$string = PhoneHelper::normalizePhone($phone);
return strlen($string) == 11;
}
}
Loading…
Cancel
Save