/** * Return table name by special model name * For Example: Yad::modelName2TableName('app\models\news') return `news`, if * Use table prefix, will return `table_prifix_news` name * @param string $modelName * @return string */ public static function modelName2TableName($modelName) { $tableName = null; if (!empty($modelName)) { $tableName = (Yii::$app->getDb()->tablePrefix ?: '') . Inflector::camel2id(StringHelper::basename(BaseActiveRecord::id2ClassName($modelName)), '_'); } return $tableName; }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($insert) { $this->auth_key = (new Security())->generateRandomString(); if ($this->status === null) { $this->status = self::STATUS_PENDING; } $this->register_ip = Yii::$app->getRequest()->getUserIP(); $this->login_count = 0; $this->created_by = $this->updated_by = Yii::$app->user->id ?: 0; $this->deleted_by = $this->deleted_at = null; } elseif ($this->_oldStatus == self::STATUS_DELETED && $this->status != self::STATUS_DELETED) { $this->deleted_by = $this->deleted_at = null; } return true; } else { return false; } }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if (!$insert && $this->defaulted) { Yii::$app->db->createCommand()->update(self::tableName(), ['defaulted' => Constant::BOOLEAN_FALSE], '[[group_name]] = :groupName AND [[id]] <> :id', [':groupName' => $this->group_name, ':id' => $this->id])->execute(); } }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { $this->final_date = DatetimeHelper::mktime($this->final_date); return true; } else { return false; } }
/** * @inheritdoc */ public function attributeLabels() { return array_merge(parent::attributeLabels(), ['label' => Yii::t('lookup', 'Label'), 'description' => Yii::t('lookup', 'Description'), 'value' => Yii::t('lookup', 'Value'), 'return_type' => Yii::t('lookup', 'Return Type')]); }