/** * Get current user advert templet. * * @param int $userId * * @return \common\models\Advert instance */ public static function getTemplet($userId = null) { if (!$userId) { $userId = Yii::$app->user->id; } // create templet advert if there is no anyone if (!($templet = self::findOne(['user_id' => $userId, 'is_templet' => 1]))) { $templet = new self(); $templet->setScenario(self::SCENARIO_CREATE_TEMPLET); $templet->user_id = $userId; $templet->is_templet = 1; $templet->save(); $templet->setScenario(self::SCENARIO_DEFAULT); } return $templet; }