/** * 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(); }
/** * 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!')); } } }