Esempio n. 1
0
 public function actionCreate()
 {
     $model = new Site();
     $avatar = CmgFile::loadFile($model->avatar, 'Avatar');
     $banner = CmgFile::loadFile($model->banner, 'Banner');
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'Site') && $model->validate()) {
         if (SiteService::create($model, $avatar)) {
             return $this->redirect('all');
         }
     }
     return $this->render('create', ['model' => $model, 'avatar' => $avatar, 'banner' => $banner]);
 }
Esempio n. 2
0
 public static function create($user, $siteMember = null, $roleSlug = null)
 {
     // Find Current Site
     $site = Site::findByName(Yii::$app->cmgCore->getSiteName());
     if (!isset($siteMember)) {
         $siteMember = new SiteMember();
         if (isset($roleSlug)) {
             $role = RoleService::findBySlug($roleSlug);
             $siteMember->roleId = $role->id;
         } else {
             $role = RoleService::findBySlug(CoreGlobal::ROLE_USER);
             $siteMember->roleId = $role->id;
         }
     }
     $siteMember->siteId = $site->id;
     $siteMember->userId = $user->id;
     $siteMember->save();
     return $siteMember;
 }
Esempio n. 3
0
 public static function updateAttributes($modelAttributes)
 {
     $site = Site::findBySlug(Yii::$app->cmgCore->getSiteSlug());
     $metaToUpdate = $site->getModelMetaByTypeName($meta->type, $meta->name);
     $metaToUpdate->copyForUpdateFrom($meta, ['value']);
     $metaToUpdate->update();
     return $metaToUpdate;
 }
Esempio n. 4
0
 public function getSite()
 {
     return $this->hasOne(Site::className(), ['id' => 'siteId']);
 }