yii\base\Model ---------
773998
public function rules() {

		$rules = [
			// Required, Safe
			[ [ 'firstName', 'lastName', 'email' ], 'required' ],
			[ 'phone', 'required', 'on' => [ 'phone', 'phone-captcha' ] ],
			// Text Limit
			[ [ 'email', 'phone' ], 'string', 'min' => 1, 'max' => Yii::$app->core->xLargeText ],
			// Other
			[ 'email', 'email' ]
		];

		if( empty( $this->captchaAction ) ) {

			$this->captchaAction	= '/cart/cart/captcha';
		}

		$rules[] = [ 'captcha', 'captcha', 'captchaAction' => $this->captchaAction, 'on' => [ 'captcha', 'phone-captcha' ] ];

		if( Yii::$app->core->trimFieldValue ) {

			$trim[] = [ [ 'firstName', 'lastName', 'email', 'phone' ], 'filter', 'filter' => 'trim', 'skipOnArray' => true ];

			return ArrayHelper::merge( $trim, $rules );
		}

		return $rules;
	}
1331622
public function actionForum()
    {
        $user = User::findMe();
        $model = Meta::find()->where(['user_id' => $user->id])->limit(1)->one();
        if (empty($model)) {
            $model = new Meta();
        }

        if ($model->load(Yii::$app->request->post())) {
            $model->user_id = $user->id;
            $uploadAvatar = false;
            $path = Yii::getAlias('@webroot/avatars');
            $model->image = UploadedFile::getInstance($model, 'image');
            if ($model->validate()) {
                if ($model->gravatar && empty($user->email)) {
                    $model->addError('gravatar', Yii::t('podium/view', 'You need email address set to use Gravatar.'));
                } else {
                    if ($model->image) {
                        $folderExists = true;
                        if (!file_exists($path)) {
                            if (!FileHelper::createDirectory($path)) {
                                $folderExists = false;
                                Log::error('Error while creating avatars folder', null, __METHOD__);
                                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while creating the avatars folder. Contact administrator about this problem.'));
                            }
                        }
                        if ($folderExists) {
                            $oldAvatarPath = $path . DIRECTORY_SEPARATOR . $model->avatar;
                            if (!empty($model->avatar) && file_exists($oldAvatarPath)) {
                                if (!unlink($oldAvatarPath)) {
                                    Log::error('Error while deleting old avatar image', null, __METHOD__);
                                }
                            }
                            $model->avatar = Yii::$app->security->generateRandomString() . '.' . $model->image->getExtension();
                            $uploadAvatar = true;
                        }
                    }
                    if ($model->save(false)) {
                        if ($uploadAvatar) {
                            if (!$model->image->saveAs($path . DIRECTORY_SEPARATOR . $model->avatar)) {
                                Log::error('Error while saving avatar image', null, __METHOD__);
                                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while uploading the avatar image. Contact administrator about this problem.'));
                            }
                        }
                        Log::info('Profile updated', $model->id, __METHOD__);
                        $this->success(Yii::t('podium/flash', 'Your profile details have been updated.'));
                        return $this->refresh();
                    }
                }
            }
        }
        return $this->render('forum', ['model' => $model, 'user' => $user]);
    }
558138
public function data()
    {
        $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::class);
        $userLangService = $this->getServiceLocator()->get(UserLanguageServiceInterface::class);
        $page = $this->getRequestParameter('page');
        $limit = $this->getRequestParameter('rows');
        $sortBy = $this->getRequestParameter('sortby');
        $sortOrder = $this->getRequestParameter('sortorder');
        $filterQuery = $this->getRequestParameter('filterquery');
        $filterColumns = $this->getRequestParameter('filtercolumns');
        $start = $limit * $page - $limit;

        $fieldsMap = [
            'login' => GenerisRdf::PROPERTY_USER_LOGIN,
            'firstname' => GenerisRdf::PROPERTY_USER_FIRSTNAME,
            'lastname' => GenerisRdf::PROPERTY_USER_LASTNAME,
            'email' => GenerisRdf::PROPERTY_USER_MAIL,
            'guiLg' => GenerisRdf::PROPERTY_USER_UILG,
            'roles' => GenerisRdf::PROPERTY_USER_ROLES
        ];
        if ($userLangService->isDataLanguageEnabled()) {
            $fieldsMap['dataLg'] = GenerisRdf::PROPERTY_USER_DEFLG;
        }

        // sorting
        $order = array_key_exists($sortBy, $fieldsMap) ? $fieldsMap[$sortBy] : $fieldsMap['login'];

        // filtering
        $filters = [
            GenerisRdf::PROPERTY_USER_LOGIN => '*',
        ];

        if ($filterQuery) {
            if (!$filterColumns) {
                // if filter columns not set, search by all columns
                $filterColumns = array_keys($fieldsMap);
            }
            $filters = array_flip(array_intersect_key($fieldsMap, array_flip($filterColumns)));
            array_walk($filters, function (&$row, $key) use($filterQuery) {
                $row = $filterQuery;
            });
        }

        $options = array(
            'recursive' => true,
            'like' => true,
            'chaining' => count($filters) > 1 ? 'or' : 'and',
            'order' => $order,
            'orderdir' => strtoupper($sortOrder),
        );

        // get total user count...
        $total = $userService->getCountUsers($options, $filters);

        // get the users using requested paging...
        $users = $userService->getAllUsers(array_merge($options, [
            'offset' => $start,
            'limit' => $limit
        ]), $filters);

        $rolesProperty = $this->getProperty(GenerisRdf::PROPERTY_USER_ROLES);

        $response = new stdClass();
        $readonly = [];
        $index = 0;

        /** @var core_kernel_classes_Resource $user */
        foreach ($users as $user) {

            $propValues = $user->getPropertiesValues(array_values($fieldsMap));

            $roles = $user->getPropertyValues($rolesProperty);
            $labels = [];

            foreach ($roles as $uri) {
                $labels[] = $this->getResource($uri)->getLabel();
            }

            $id = tao_helpers_Uri::encode($user->getUri());
            $login = (string)current($propValues[GenerisRdf::PROPERTY_USER_LOGIN]);
            $firstName = empty($propValues[GenerisRdf::PROPERTY_USER_FIRSTNAME]) ? '' : (string)current($propValues[GenerisRdf::PROPERTY_USER_FIRSTNAME]);
            $lastName = empty($propValues[GenerisRdf::PROPERTY_USER_LASTNAME]) ? '' : (string)current($propValues[GenerisRdf::PROPERTY_USER_LASTNAME]);
            $uiRes = empty($propValues[GenerisRdf::PROPERTY_USER_UILG]) ? null : current($propValues[GenerisRdf::PROPERTY_USER_UILG]);
            if ($userLangService->isDataLanguageEnabled()) {
                $dataRes = empty($propValues[GenerisRdf::PROPERTY_USER_DEFLG]) ? null : current($propValues[GenerisRdf::PROPERTY_USER_DEFLG]);
                $response->data[$index]['dataLg'] = is_null($dataRes) ? '' : $dataRes->getLabel();
            }

            $response->data[$index]['id'] = $id;
            $response->data[$index]['login'] = $login;
            $response->data[$index]['firstname'] = $firstName;
            $response->data[$index]['lastname'] = $lastName;
            $response->data[$index]['email'] = (string)current($propValues[GenerisRdf::PROPERTY_USER_MAIL]);
            $response->data[$index]['roles'] = implode(', ', $labels);
            $response->data[$index]['guiLg'] = is_null($uiRes) ? '' : $uiRes->getLabel();

            $statusInfo = $this->getUserLocksService()->getStatusDetails($login);
            $response->data[$index]['lockable'] = $statusInfo['lockable'];
            $response->data[$index]['locked'] = $statusInfo['locked'];
            $response->data[$index]['status'] = $statusInfo['status'];

            if ($user->getUri() == LOCAL_NAMESPACE . TaoOntology::DEFAULT_USER_URI_SUFFIX) {
                $readonly[$id] = true;
            }

            $index++;
        }

        $response->page = floor($start / $limit) + 1;
        $response->total = ceil($total / $limit);
        $response->records = count($users);
        $response->readonly = $readonly;

        $this->returnJson($response, 200);
    }
945308
public function insertModel(): bool
    {
        $this->getFromForm();
        if (!$this->insert()) {
            throw new Exception(\Yii::t('app', 'Ошибка при добавлении в БД'));
        }
        return true;
    }
588586
public function run()
    {
        /* @var $model yii\db\ActiveRecord */
        $model = new $this->modelClass;
        $model->setScenario( $this->scenario );
        if (yii::$app->getRequest()->getIsPost()) {
            if ($model->load(yii::$app->getRequest()->post()) && $model->save()) {
                yii::$app->getSession()->setFlash('success', yii::t('cms', 'Success'));
                return $this->controller->redirect(['index']);
            } else {
                $errors = $model->getErrors();
                $err = '';
                foreach ($errors as $v) {
                    $err .= $v[0] . '<br>';
                }
                Yii::$app->getSession()->setFlash('error', $err);
            }
        }
        $model->loadDefaultValues();
        $data = array_merge(['model' => $model], $this->data);
        return $this->controller->render('create', $data);
    }
867531
public function actionCreate()
    {
        $model = new Dump($this->getModule()->dbList);
        if (ArrayHelper::isIn($this->db, $this->getModule()->dbList)) {
            $dbInfo = $this->getModule()->getDbInfo($this->db);
            $dumpOptions = $model->makeDumpOptions();
            if ($this->gzip) {
                $dumpOptions['isArchive'] = true;
            }
            $manager = $this->getModule()->createManager($dbInfo);
            $dumpPath = $manager->makePath($this->getModule()->path, $dbInfo, $dumpOptions);
            $dumpCommand = $manager->makeDumpCommand($dumpPath, $dbInfo, $dumpOptions);
            Yii::trace(compact('dumpCommand', 'dumpPath', 'dumpOptions'), get_called_class());
            $process = new Process($dumpCommand);
            $process->run();
            if ($process->isSuccessful()) {
                if ($this->storage) {
                    if (Yii::$app->has('backupStorage')) {
                        $dumpText = fopen($dumpPath, 'r+');
                        Yii::$app->backupStorage->writeStream(StringHelper::basename($dumpPath), $dumpText);
                        fclose($dumpText);
                    } else {
                        Console::output('Storage component is not configured.');
                    }
                }
                Console::output('Dump successfully created.');
            } else {
                Console::output('Dump failed create.');
            }
        } else {
            Console::output('Database configuration not found.');
        }
    }
371822
private static function initModelProperties()
    {
        $currentModel = static::class;

        if (isset(self::$modelProperties[$currentModel])) {
            return;
        }

        $properties = [
            'connection'  => ConnectionFactory::build(static::$connection),
            'dateFields'  => static::$dates ?: [],
            'fields'      => static::$fields ?: [],
            'primaryKeys' => (array) static::$primaryKey,
            'table'       => static::$table,
            'timestamps'  => (bool) static::$timestamps,
        ];

        if ($properties['timestamps']) {
            $properties['fields'][] = 'created_at';
            $properties['fields'][] = 'updated_at';
            $properties['dateFields'][] = 'created_at';
            $properties['dateFields'][] = 'updated_at';
        }

        self::$modelProperties[$currentModel] = $properties;
    }
101690
public function actionAdd() {

		$model				= new Post();
		$model->siteId		= Yii::$app->core->siteId;
		$model->comments	= false;

		$content			= new ModelContent();

		if( $model->load( Yii::$app->request->post(), $model->getClassName() ) && $model->validate() && $content->load(Yii::$app->request->post(),'ModelContent' ) && $content->getClassName() ) {

			$model->status	= Post::STATUS_BASIC;

			$this->modelService->register( $model, [ 'publish' => $model->isActive(), 'content' => $content ] );

			return $this->checkRefresh( $model );
		}

		$visibilityMap	= Post::$visibilityMap;

		return $this->render( 'reg/basic', [
			'model' => $model, 'content' => $content,
			'visibilityMap' => $visibilityMap
		]);
	}
259008
public function actionCreate()
    {
        /* @var $model ActiveRecord */
        $model = $this->createModel();
        $this->beginTransaction();
        try {
            $this->fire('beforeCreate', [$model]);
            $model->load(Yii::$app->request->post(), '');
            $this->fire('create', [$model]);
            if ($model->save()) {
                $this->fire('created', [$model]);
                $this->commit();
                $model->refresh();
            } else {
                $this->fire('rollbackCreate', [$model]);
                $this->rollBack();
            }
        } catch (\Exception $e) {
            $this->fire('errorCreate', [$model, $e]);
            $this->rollBack();
            throw $e;
        }

        return $model;
    }
1224614
public function rules() {
        return [
            'processRequired' => [['code', 'name', 'flag', 'is_active'], 'required', 'on' => ['create', 'update']],
            'searchSafe' => [['code', 'name', 'is_active'], 'safe', 'on' => ['search']],
            'codeUnique' => ['code', 'unique',
                'targetClass' => Language::className(),
                'message' => Yii::t('multilang', 'Code must be unique'),
                'when' => function($model, $attribute) {
                    return $model->{$attribute} != $model->getOldAttribute($attribute);
                }, 'on' => ['create', 'update']],
        ];
    }
624469
public function run()
    {
        /** @var Model $model */
        $model = $this->model;
        $options = $this->options;
        unset($options['id']);

        // Add model meta
        $modelClassName = $model::className();
        $modelMeta = $model::meta();
        if (\Yii::$app->has('frontendState')) {
            \Yii::$app->frontendState->set('config.types.metas.' . $modelClassName, $modelMeta);
        } else {
            $jsArgs = [Json::encode($modelClassName), Json::encode($modelMeta)];
            \Yii::$app->view->registerJs('__appTypes.addModelMeta(' . implode(', ', $jsArgs) . ')', View::POS_END, 'app-form-' . $model::className());
        }

        // Add enums
        foreach ($model::meta() as $item) {
            if (!empty($item['enumClassName'])) {
                /** @var Enum $enumClass */
                $enumClass = $item['enumClassName'];
                $enumClassName = $enumClass::className();
                $props = [
                    'labels' => $enumClass::getLabels(),
                ];

                if (\Yii::$app->has('frontendState')) {
                    \Yii::$app->frontendState->set('config.types.enums.' . $enumClassName, $props);
                } else {
                    $jsArgs = [Json::encode($enumClassName), Json::encode($props)];
                    \Yii::$app->view->registerJs('__appTypes.addEnum(' . implode(', ', $jsArgs) . ')', View::POS_END, 'app-enum-' . $enumClass::className());
                }
            }
        }

        // Render field
        $props = array_merge([
            'formId' => $this->field ? $this->field->form->id : 'f' . ++self::$idCounter,
            'model' => $model::className(),
            'prefix' => $model->formName(),
            'attribute' => Html::getAttributeName($this->attribute),
        ], $options);
        if (\Yii::$app->has('frontendState')) {
            \Yii::$app->frontendState->add('config.types.toRenderField', [$this->id, $props]);
        } else {
            $jsArgs = [Json::encode($this->id), Json::encode($props)];
            \Yii::$app->view->registerJs('__appTypes.renderField(' . implode(', ', $jsArgs) . ')', View::POS_END, $this->id);
        }
        return Html::tag('span', '', ['id' => $this->id]);
    }
873955
public function actionView()
    {
        $model = $this->model;
        $id = $model->name;
        $model = $this->findModel($id);
        $authManager = Yii::$app->getAuthManager();
        $avaliable = $assigned = [
            'Permission' => [],
            'Routes' => [],
        ];
        $children = array_keys($authManager->getChildren($id));
        $children[] = $id;
        foreach ($authManager->getPermissions() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }
            if (isset($name[0])) {
                $avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $role->description;
            }
        }
        foreach ($authManager->getChildren($id) as $name => $child) {
            $assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $child->description;;
        }
        $avaliable = array_filter($avaliable);
        $assigned = array_filter($assigned);
        return $this->render('view', ['model' => $model, 'avaliable' => $avaliable, 'assigned' => $assigned]);
    }
141997
public function init()
  {
    parent::init();
    if($this->basePath===null)
      $this->basePath=Yii::$app->getAlias('@app');
    $this->prepare();
  }
1047392
private static function model()
    {
        $files = ['ORM_', 'CRUD', 'ORM', 'Collection', 'ModelArray'];
        $folder = static::$root.'MVC/Model'.'/';

        self::call($files, $folder);

        $files = ['ForeingKeyMethodException', 'ColumnNotEmptyException', 'ManyPrimaryKeysException', 'TableNotFoundException', 'ModelNotFoundException', 'PrimaryKeyNotFoundException'];
        $folder = static::$root.'MVC/Model/Exceptions'.'/';

        self::call($files, $folder);
    }
1302158
public function init() {

		parent::init();

		$this->basePath	 		= 'post/default';
		$this->crudPermission	= CoreGlobal::PERM_USER;

		$this->layout			= CoreGlobalWeb::LAYOUT_PUBLIC;

		$this->modelService			= Yii::$app->factory->get( 'postService' );

		$this->templateService		= Yii::$app->factory->get( 'templateService' );

		$this->categoryService		= Yii::$app->factory->get( 'categoryService' );
		$this->tagService			= Yii::$app->factory->get( 'tagService' );

		$this->modelContentService	= Yii::$app->factory->get( 'modelContentService' );
		$this->modelCategoryService	= Yii::$app->factory->get( 'modelCategoryService' );

		$this->pageMetaService		= Yii::$app->factory->get( 'pageMetaService' );
	}
1183704
public function run()
    {
        /* @var $model \yii\db\ActiveRecord */
        $model = new $this->modelClass;
        $model->setScenario( $this->scenario );
        $request=yii::$app->getRequest();
        if ($request->getIsPost()) {
            if ($model->load($request->post()) && $model->save()) {
                yii::$app->getSession()->setFlash('success', yii::t('app', 'Created Success'));
                if($request->isAjax){
                    return ['status'=>true,'msg'=>yii::t('app','Created Success')];
                }else{
                    return $this->controller->redirect([$this->indexView]);
                }
            } else {
                $errors = $model->getErrors();
                $err = '';
                foreach ($errors as $v) {
                    $err .= Yii::t('app',$v[0]) . '<br>';
                }
                Yii::$app->getSession()->setFlash('error', $err);
                if($request->isAjax){
                    return ['status'=>false,'msg'=>$err];
                }
            }
        }
        $model->loadDefaultValues();
        $data = [
            'model' => $model,
        ];
        if( is_array($this->data) ){
            $data = array_merge($data, $this->data);
        }elseif ($this->data instanceof \Closure){
            $data = call_user_func_array($this->data, [$model, $this]);
        }
        $this->viewFile === null && $this->viewFile = $this->id;
        return $this->controller->render($this->viewFile, $data);
    }
1183898
public function init() {

		parent::init();

		// Config
		$this->type			= CmsGlobal::TYPE_MENU;
		$this->templateType = CmsGlobal::TYPE_MENU;
		$this->apixBase		= 'cms/menu';

		// Services
		$this->modelService = Yii::$app->factory->get( 'menuService' );

		// Sidebar
		$this->sidebar = [ 'parent' => 'sidebar-ui', 'child' => 'umenu' ];

		// Return Url
		$this->returnUrl = Url::previous( 'menus' );
		$this->returnUrl = isset( $this->returnUrl ) ? $this->returnUrl : Url::toRoute( [ '/cms/menu/all' ], true );

		// Breadcrumbs
		$this->breadcrumbs = [
			'base' => [
				[ 'label' => 'Home', 'url' => Url::toRoute( '/dashboard' ) ]
			],
			'all' => [ [ 'label' => 'Menus' ] ],
			'create' => [ [ 'label' => 'Menus', 'url' => $this->returnUrl ], [ 'label' => 'Add' ] ],
			'update' => [ [ 'label' => 'Menus', 'url' => $this->returnUrl ], [ 'label' => 'Update' ] ],
			'delete' => [ [ 'label' => 'Menus', 'url' => $this->returnUrl ], [ 'label' => 'Delete' ] ],
			'settings' => [ [ 'label' => 'Menus', 'url' => $this->returnUrl ], [ 'label' => 'Settings' ] ],
			'data' => [ [ 'label' => 'Menus', 'url' => $this->returnUrl ], [ 'label' => 'Data' ] ]
		];
	}