Просмотр файла vkclone-0.0.1/protected/components/WebUser.php

Размер файла: 1.73Kb
<?php
class WebUser extends CWebUser {
	const ALERTS_KEY = 'Users.components.WebUser.alerts';
	private $record;

	/**
	 * Returns associated record in {{users}}
	 */
	public function getRecord() {
		if ($this->record !== null)
			return $this->record;

		if (isset($this->service))
			$this->record = User::model()->findByAttributes(array('service' => $this->service, 'service_id' => $this->id));
		else
			$this->record = User::model()->findByPk($this->id);

		return $this->record;
	}

	/**
	 * Stores a typified alert.
	 * @param string $message Alert message
	 * @param string $type Type. Valid values: success, danger, warning, info.
	 * @param string $title Alert title
	 */
	public function setAlert($message, $type, $title = null) {
		$alerts = $this->getState(self::ALERTS_KEY, array());
		$alerts[] = array('message' => $message, 'type' => $type, 'title' => $title);
		return $this->setState(self::ALERTS_KEY, $alerts);
	}

	/**
	 * Returns all stored alerts and after deletes them immediately.
	 * @return array
	 */
	public function getAlerts() {
		$alerts = $this->getState(self::ALERTS_KEY, array());
		$this->setState(self::ALERTS_KEY, null);
		return $alerts;
	}

	public function getPreferredTheme() {
		$theme = Yii::app()->request->isMobile() ? 'mobile' : 'web';
		if (isset(Yii::app()->request->cookies['theme']))
			$theme = (string)Yii::app()->request->cookies['theme'];
		return $theme;
	}

	public function flipPreferredTheme() {
		$theme = Yii::app()->request->isMobile() ? 'mobile' : 'web';
		if (isset(Yii::app()->request->cookies['theme']))
			$theme = (string)Yii::app()->request->cookies['theme'];
		// flip theme
		$theme = ($theme == 'web') ? 'mobile' : 'web';
		Yii::app()->request->cookies['theme'] = new CHttpCookie('theme', $theme);
	}
}