/** * Saves this Profile Field Type */ public function save() { $columnName = $this->profileField->internal_name; if (!\humhub\modules\user\models\Profile::columnExists($columnName)) { $query = Yii::$app->db->getQueryBuilder()->addColumn(\humhub\modules\user\models\Profile::tableName(), $columnName . '_hide_year', 'INT(1)'); Yii::$app->db->createCommand($query)->execute(); } return parent::save(); }
/** * Saves this Profile Field Type */ public function save() { $columnName = $this->profileField->internal_name; if (!\humhub\modules\user\models\Profile::columnExists($columnName)) { $query = Yii::$app->db->getQueryBuilder()->addColumn(\humhub\modules\user\models\Profile::tableName(), $columnName, 'VARCHAR(255)'); Yii::$app->db->createCommand($query)->execute(); } else { Yii::error('Could not add profile column - already exists!'); } return parent::save(); }
public function actionRequest() { $request = \Yii::$app->request; if (\Yii::$app->user->isGuest) { return $this->render('index_guest', array()); } else { if (!empty(\Yii::$app->user->id)) { $user_id = \Yii::$app->user->id; $model = new MedicalHistory(); $profile = Profile::find()->where(["user_id" => \Yii::$app->user->id])->one(); $history_fields = MedicalHistoryField::find()->where(['id' => 1])->one(); } else { $user_id = null; } return $this->render('request', array('showProfilePostForm' => Setting::Get('showProfilePostForm', 'appointments'), 'profile' => $profile, 'history_fields' => $history_fields, 'model' => $model)); } }
public function actionIndex() { $request = Yii::$app->request; if (Yii::$app->user->isGuest) { return $this->render('index_guest', array()); } else { if (!empty(Yii::$app->user->id)) { $user_id = Yii::$app->user->id; $user_guid = Yii::$app->user->guid; $user_records = glob(Yii::getAlias('@webroot') . '/uploads/' . $user_guid . '/*.*'); $profile = Profile::find()->where(["user_id" => Yii::$app->user->id])->one(); } else { $user_id = null; } return $this->render('index', array('showProfilePostForm' => Setting::Get('showProfilePostForm', 'appointments'), 'profile' => $profile, 'records' => $user_records)); } }
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (\humhub\modules\space\models\Membership::GetUserSpaces($this->id) as $space) { if ($space->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } // Delete profile image $this->getProfileImage()->delete(); // Remove from search index Yii::$app->search->delete($this); // Cleanup related tables Invite::deleteAll(['user_originator_id' => $this->id]); Follow::deleteAll(['user_id' => $this->id]); Follow::deleteAll(['object_model' => $this->className(), 'object_id' => $this->id]); Password::deleteAll(['user_id' => $this->id]); Profile::deleteAll(['user_id' => $this->id]); GroupUser::deleteAll(['user_id' => $this->id]); Session::deleteAll(['user_id' => $this->id]); return parent::beforeDelete(); }
/** * Deletes a Profile Field Type */ public function delete() { $columnName = $this->profileField->internal_name; if (\humhub\modules\user\models\Profile::columnExists($columnName)) { $query = Yii::$app->db->getQueryBuilder()->dropColumn(\humhub\modules\user\models\Profile::tableName(), $this->profileField->internal_name); Yii::$app->db->createCommand($query)->execute(); } else { Yii::error('Could not delete profile column - not exists!'); } }
/** * Validator which checks the given internal name. * * Also ensures that internal_name could not be changed on existing records. */ public function checkInternalName() { // Little bit cleanup $this->internal_name = strtolower($this->internal_name); $this->internal_name = trim($this->internal_name); if (!$this->isNewRecord) { // Dont allow changes of internal_name - Maybe not the best way to check it. $currentProfileField = ProfileField::findOne(['id' => $this->id]); if ($this->internal_name != $currentProfileField->internal_name) { $this->addError('internal_name', Yii::t('UserModule.models_ProfileField', 'Internal name could not be changed!')); } } else { // Check if Internal Name is not in use yet if (Profile::columnExists($this->internal_name)) { $this->addError('internal_name', Yii::t('UserModule.models_ProfileField', 'Internal name already in use!')); } } }
/** * Callback to validate module database records. * * @param \yii\base\Event $event */ public static function onIntegrityCheck($event) { $integrityController = $event->sender; $integrityController->showTestHeadline("User Module - Users (" . User::find()->count() . " entries)"); foreach (User::find()->joinWith(['profile'])->all() as $user) { if ($user->profile == null) { $integrityController->showWarning("User with id " . $user->id . " has no profile record!"); } } foreach (GroupUser::find()->joinWith(['user'])->all() as $groupUser) { if ($groupUser->user == null) { if ($integrityController->showFix("Deleting group admin " . $groupUser->id . " without existing user!")) { $groupUser->delete(); } } } $integrityController->showTestHeadline("User Module - Password (" . Password::find()->count() . " entries)"); foreach (Password::find()->joinWith(['user'])->all() as $password) { if ($password->user == null) { if ($integrityController->showFix("Deleting password " . $password->id . " without existing user!")) { $password->delete(); } } } $integrityController->showTestHeadline("User Module - Profile (" . Profile::find()->count() . " entries)"); foreach (Profile::find()->joinWith(['user'])->all() as $profile) { if ($profile->user == null) { if ($integrityController->showFix("Deleting profile " . $profile->user_id . " without existing user!")) { $profile->delete(); } } } $integrityController->showTestHeadline("User Module - Mentioning (" . Mentioning::find()->count() . " entries)"); foreach (Mentioning::find()->joinWith(['user'])->all() as $mentioning) { if ($mentioning->user == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non existing user!")) { $mentioning->delete(); } } if ($mentioning->getPolymorphicRelation() == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non target!")) { $mentioning->delete(); } } } $integrityController->showTestHeadline("User Module - Follow (" . Follow::find()->count() . " entries)"); foreach (Follow::find()->joinWith(['user'])->all() as $follow) { if ($follow->user == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non existing user!")) { $follow->delete(); } } if ($follow->getTarget() == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non target!")) { $follow->delete(); } } } $integrityController->showTestHeadline("User Module - Modules (" . models\Module::find()->count() . " entries)"); foreach (models\Module::find()->joinWith(['user'])->all() as $module) { if ($module->user == null) { if ($integrityController->showFix("Deleting user-module " . $module->id . " of non existing user!")) { $module->delete(); } } } }