/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/models/Email.php
103 строки
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\models; use Yii; use yii\helpers\ArrayHelper; use yii\helpers\VarDumper; /** * Таблица - почтовые адреса * * @property string $value Email * @property string $hash Unique hash * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2022 */ class Email extends \common\models\base\BaseModel { /** * {@inheritdoc} */ public static function tableName() { return 'email'; } /** * {@inheritdoc} */ public function rules() { return ArrayHelper::merge(parent::rules(), [ ['value', 'trim'], [['value', 'hash'], 'required'], ['value', 'email'], [['value', 'hash'], 'string', 'max' => 255], ['hash', 'unique'], ]); } /** * {@inheritdoc} */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'value' => Yii::t('app', 'Email'), 'hash' => Yii::t('app', 'Unique hash'), ]); } /** * Сгенерировать уникальный хэш почтового ящика * @param $value * @return string */ public static function generateHash($value) { return md5(mb_strtolower(trim($value))); } /** * {@inheritdoc} */ public function beforeValidate() { $this->hash = $this->generateHash($this->value); return parent::beforeValidate(); // TODO: Change the autogenerated stub } /** * {@inheritdoc} */ public static function findOrNew($condition = null) { $value = ArrayHelper::getValue((array)$condition, 'value'); $hash = self::generateHash($value); Yii::debug(VarDumper::dumpAsString([ 'value' => $value ])); $object = parent::findOrNew([ 'hash' => $hash ]); $object->value = $value; return $object; } /** * Получить ссылку на Gravatar * @return string */ public function getGravatar() { return 'https://gravatar.com/avatar/' . md5(strtolower(trim($this->value))); } }