public static function preConfigure() { $app = Mindy::app(); $tpl = $app->template; $tpl->addHelper('t', function ($text, $category, $params = []) { if ($category !== 'app' && !strpos($category, '.')) { $category .= '.main'; } $findCategory = explode('.', $category); $moduleNameRaw = ucfirst($findCategory[0]); if (Mindy::app()->hasModule($moduleNameRaw)) { $module = Mindy::app()->getModule($moduleNameRaw); $moduleName = get_class($module) . '.' . $findCategory[1]; return Mindy::t($moduleName, $text, $params); } else { return $text; } }); $tpl->addHelper('convert_base64', ['\\Modules\\Mail\\Helper\\MailHelper', 'convertToBase64']); $tpl->addHelper('ucfirst', ['\\Mindy\\Helper\\Text', 'mbUcfirst']); $tpl->addHelper('debug_panel', ['\\Modules\\Core\\Components\\DebugPanel', 'render']); $tpl->addHelper('param', ['\\Modules\\Core\\Components\\ParamsHelper', 'get']); $tpl->addHelper('humanizeDateTime', ['\\Modules\\Core\\Components\\Humanize', 'humanizeDateTime']); $tpl->addHelper('locale', function () use($app) { return $app->locale; }); $tpl->addHelper('humanizeSize', ['\\Modules\\Core\\Components\\Humanize', 'humanizeSize']); $tpl->addHelper('humanizePrice', ['\\Modules\\Core\\Components\\Humanize', 'numToStr']); $tpl->addHelper('limit', ['\\Mindy\\Helper\\Text', 'limit']); $tpl->addHelper('strtotime', 'strtotime'); $tpl->addHelper('time', 'time'); $tpl->addHelper('is_file', 'is_file'); $tpl->addHelper('d', 'd'); $tpl->addHelper('locale_date', function ($timestamp, $format = 'd MMMM yyyy') { return Translate::getInstance()->getDateFormatter()->format($format, $timestamp); }); $tpl->addHelper('method_exists', function ($obj, $name) { return method_exists($obj, $name); }); $tpl->addHelper('user_actions', function ($by = 10) { return UserLog::objects()->limit($by)->order(['-created_at'])->all(); }); $signal = $app->signal; $signal->handler('\\Mindy\\Orm\\Model', 'afterSave', [self::className(), 'afterSaveModel']); $signal->handler('\\Mindy\\Orm\\Model', 'afterDelete', [self::className(), 'afterDeleteModel']); }
public function getFields() { $fields = ['username' => ['class' => CharField::className(), 'label' => UserModule::t('Username'), 'required' => true, 'validators' => [function ($value) { if (User::objects()->filter(['username' => $value])->count() > 0) { return UserModule::t("Username must be a unique"); } return true; }]], 'email' => ['class' => EmailField::className(), 'label' => UserModule::t('Email'), 'required' => true, 'validators' => [function ($value) { if (User::objects()->filter(['email' => $value])->count() > 0) { return UserModule::t("Email must be a unique"); } return true; }]], 'password' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password')], 'password_repeat' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password repeat')]]; $module = Mindy::app()->getModule('User'); if ($module->enableRecaptcha) { if (empty($module->recaptchaPublicKey) && empty($module->recaptchaSecretKey)) { Mindy::app()->logger->warning("publicKey and secretKey isn't set in UserModule"); } else { $fields['captcha'] = ['class' => RecaptchaField::className(), 'label' => Translate::getInstance()->t('validation', 'Captcha'), 'publicKey' => $module->recaptchaPublicKey, 'secretKey' => $module->recaptchaSecretKey]; } } return $fields; }
/** * @param $size * @param bool $minimal * @return mixed */ public static function humanizeSize($size, $minimal = true) { if ($size < 1024) { $converted = $size; $message = $minimal ? '{n} B' : '{n} byte|{n} bytes'; } elseif ($size < pow(1024, 2)) { $converted = round($size / 1024); $message = $minimal ? '{n} KB' : '{n} kilobyte|{n} kilobytes'; } elseif ($size < pow(1024, 3)) { $converted = round($size / pow(1024, 2)); $message = $minimal ? '{n} MB' : '{n} megabyte|{n} megabytes'; } elseif ($size < pow(1024, 4)) { $converted = round($size / pow(1024, 3)); $message = $minimal ? '{n} GB' : '{n} gigabyte|{n} gigabytes'; } else { $converted = round($size / pow(1024, 4)); $message = $minimal ? '{n} TB' : '{n} terabyte|{n} terabytes'; } return Translate::getInstance()->t('base', $message, $converted); }
public function __getInternalOrm($name) { if ($name == 'pk') { $name = $this->primaryKey(); $name = array_shift($name); } $meta = static::getMeta(); if ($meta->hasFileField($name)) { $fileField = $this->getField($name); $fileField->setModel($this); $fileField->setDbValue($this->getAttribute($name)); return $fileField; } if ($meta->hasOneToOneField($name)) { /* @var $field \Mindy\Orm\Fields\OneToOneField */ $field = $meta->getField($name); $field->setModel($this); return $field->getValue(); } if ($meta->hasForeignField($name) && $this->hasAttribute($name) === false) { $value = $this->getAttribute($name . '_id'); if (is_null($value)) { return $value; } else { /* @var $field \Mindy\Orm\Fields\ForeignField */ $field = $meta->getForeignField($name)->setModel($this)->setValue($value); return $field->getValue(); } } if ($meta->hasManyToManyField($name) || $meta->hasHasManyField($name)) { /* @var $field \Mindy\Orm\Fields\ManyToManyField|\Mindy\Orm\Fields\HasManyField */ $field = $meta->getField($name); $field->setModel($this); return $field->getManager(); } if ($meta->hasField($name) && is_a($this->getField($name), JsonField::className())) { $field = $this->getField($name); $field->setModel($this); $field->setDbValue($this->getAttribute($name)); return $field->getValue(); } if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) { return $this->_attributes[$name]; } elseif ($this->hasAttribute($name)) { return $this->hasField($name) ? $this->getField($name)->default : null; } if (!in_array($name, $this->attributes()) && $this->hasField($name)) { throw new \Mindy\Query\Exception(Translate::getInstance()->t("orm", "'{name}' column is missing in database. Please check database structure", ['{name}' => $name])); } return $this->__getInternal($name); }
/** * Resolves the error message to be displayed. * This method will check {@link message} and {@link CAccessRule::message} to see * what error message should be displayed. * @param Rule $rule the access rule * @return string the error message * @since 1.1.1 */ protected function resolveErrorMessage($rule) { if ($rule->message !== null) { return $rule->message; } elseif ($this->message !== null) { return $this->message; } else { return Translate::getInstance()->t('base', 'You are not authorized to perform this action.'); } }
public function isValid() { parent::isValid(); if (isset($this->value['error']) && $this->value['error'] == UPLOAD_ERR_NO_FILE && $this->null == false) { $this->addErrors(Translate::getInstance()->t('validation', 'Cannot be empty')); } return $this->hasErrors() === false; }