Browse Source

Shop module rewrite

master
Egorka 6 years ago
parent
commit
0eb69526a3
  1. 1
      Yii.php
  2. 78
      core/components/LanguageTranslateTrait.php
  3. 12
      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.

78
core/components/LanguageTranslateTrait.php

@ -17,39 +17,45 @@ use Yii;
*/ */
trait LanguageTranslateTrait 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
* @param string $language *
* @param bool $abridge * @param string $language
* * @param bool $abridge
* @return $this *
*/ * @return $this
public function localized($language = null, $abridge = true) */
{ public function localized($language = null, $abridge = true)
$language = $language ?: Yii::$app->language; {
if (!isset($this->with['translations'])) { $language = $language ?: Yii::$app->language;
$this->with(['translation' => function ($query) use ($language, $abridge) { if (!isset($this->with['translations'])) {
/** @var ActiveQuery $query */ $this->with([
$query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]); 'translation' => function ($query) use ($language, $abridge) {
}]); /** @var ActiveQuery $query */
} $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]);
return $this; }
} ]);
/** }
* Scope for querying by all languages
* @return $this return $this;
*/ }
public function multilingual()
{ /**
if (isset($this->with['translation'])) { * Scope for querying by all languages
unset($this->with['translation']); * @return $this
} */
$this->with('translations'); public function multilingual()
return $this; {
} if (isset($this->with['translation'])) {
} unset($this->with['translation']);
}
$this->with('translations');
return $this;
}
}

12
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