/**
  * [init description].
  *
  * @return [type] [description]
  */
 public function init()
 {
     parent::init();
     $this->ctype = 'user';
     $this->uuid = !empty(\Yii::$app->getRequest()->getQueryParam('uuid')) ? \Yii::$app->getRequest()->getQueryParam('uuid') : null;
     // create default user element, if none is present
     $workspacePath = realpath(\Yii::getAlias('@webroot') . '/../workspace');
     if ($workspacePath === false) {
         throw new \yii\web\ServerErrorHttpException('The *workspace* folder could not be found - please create it in your project root');
     }
     $elementsPath = realpath($workspacePath . '/elements');
     if ($elementsPath === false) {
         throw new \yii\web\ServerErrorHttpException('The *elements* folder could not be found - please create it in your workspace folder');
     }
     $modelJson = realpath($elementsPath . '/' . $this->ctype . '.json');
     if ($modelJson === false) {
         file_put_contents($elementsPath . '/' . $this->ctype . '.json', '{"key":"user","label":"User","tabs":[{"label":"Login","key":"login","visible":false,"groups":[{"label":"Login","key":"login","fields":["email","password","login"]}]},{"label":"User","key":"user","groups":[{"label":"User","key":"user","fields":["email","password","state"]}]}],"fields":[{"label":"Email address","key":"email","type":"textInput","visibleInGrid":true,"rules":[["required"],["email"],["string",{"max":128}]]},{"label":"Password","key":"password","type":"passwordInput","visibleInGrid":false,"rules":[["required"],["string",{"max":128}]],"transform":"hash"},{"label":"Login","key":"login","type":"submitButton","visibleInGrid":false}, {"label":"Auth-Key","key":"authKey","type":"text","visibleInGrid":false}]}');
     }
     \Yii::$app->cache->flush();
     $usersProvider = new CrelishJsonDataProvider('user');
     $users = $usersProvider->rawAll();
     if (sizeof($users) == 0) {
         // Generate default admin.
         $adminUser = new CrelishDynamicJsonModel(['email', 'password', 'login', 'state'], ['ctype' => 'user']);
         $adminUser->email = '*****@*****.**';
         $adminUser->login = '******';
         $adminUser->password = '******';
         $adminUser->state = 1;
         $adminUser->authKey = \Yii::$app->security->generateRandomString();
         $adminUser->save();
     }
 }
 /**
  * [init description]
  * @return [type] [description]
  */
 public function init()
 {
     parent::init();
     $this->ctype = !empty(\Yii::$app->getRequest()->getQueryParam('ctype')) ? \Yii::$app->getRequest()->getQueryParam('ctype') : 'page';
     $this->uuid = !empty(\Yii::$app->getRequest()->getQueryParam('uuid')) ? \Yii::$app->getRequest()->getQueryParam('uuid') : null;
 }
 public function init()
 {
     parent::init();
 }
 /**
  * [parseFolderContent description]
  * @param  [type] $folder [description]
  * @return [type]         [description]
  */
 public function parseFolderContent($folder)
 {
     $filesArr = [];
     $allModels = [];
     $fullFolder = \Yii::getAlias($this->pathAlias) . DIRECTORY_SEPARATOR . $folder;
     if (!file_exists($fullFolder)) {
         mkdir($fullFolder);
     }
     $files = FileHelper::findFiles($fullFolder, ['recursive' => false]);
     if (isset($files[0])) {
         foreach ($files as $file) {
             $filesArr[] = $file;
         }
     }
     foreach ($filesArr as $file) {
         $finalArr = [];
         $content = file_get_contents($file);
         $modelArr = json_decode($content, true);
         if (is_null($modelArr)) {
             $segments = explode(DIRECTORY_SEPARATOR, $file);
             CrelishBaseController::addError("Invalid JSON in " . array_pop($segments));
             continue;
         }
         $modelArr['id'] = $file;
         $modelArr['ctype'] = $this->ctype;
         // todo: Handle special fields... uncertain about this.
         foreach ($modelArr as $attr => $value) {
             if (strpos($attr, '__cr_include') !== false) {
                 // Include data.
                 $include = new CrelishJsonDataProvider($value['ctype'], [], $value['uuid']);
                 $finalArr[str_replace('__cr_include', '', $attr)] = $include->one();
             } else {
                 $finalArr[$attr] = $value;
             }
         }
         $allModels[] = $finalArr;
     }
     return $allModels;
 }