Просмотр файла vkclone-0.0.1/protected/modules/admin/controllers/DefaultController.php

Размер файла: 2.62Kb
<?php
/**
 * The main admin panel controller
 */
class DefaultController extends BackEndController {
	public $defaultAction = 'dashboard';

	/**
	 * Admin main page
	 */
	public function actionDashboard() {
		$modules = array_diff(array_keys(Yii::app()->getModules()), array('gii', 'admin'));
		sort($modules);
		foreach ($modules as $i => $module) {
			$module = Yii::app()->getModule($module);
			if ($module instanceof WebModule) {
				$modules[$i] = array(
					'id' => $module->id,
					'label' => $module->getMeta('name'),
					'url' => $module->getMeta('admin.controller') === null ? null : array('/'.$module->id.'/'.$module->getMeta('admin.controller')),
					'author' => $module->getMeta('author'),
					'description' => $module->getMeta('description'),
					'icon' => $module->getMeta('icon'),
				);
			}
		}
		$dataProvider = new CArrayDataProvider($modules, array('pagination' => false));

		$this->render('index', array(
			// modules
			'modules_provider' => $dataProvider,

			// disk
			'free_space' => disk_free_space(Yii::getPathOfAlias('application')),
			'total_space' => disk_total_space(Yii::getPathOfAlias('application')),
		));
	}

	/**
	 * Login page
	 */
	public function actionLogin() {
		$model = new LoginForm;

		// collect user input data
		if(isset($_POST[CHtml::modelName($model)])) {
			$model->attributes = $_POST[CHtml::modelName($model)];
			if ($model->validate() && $model->login())
				$this->redirect(array('dashboard'));
		}
		$this->render('login', array('model' => $model));
	}

	/**
	 * Shows gearman job server status
	 */
	public function actionGearman() {
		if (($gearman_status = Yii::app()->gearman->getStatus('127.0.0.1')) === false)
			throw new CHttpException(500, 'Gearman server is unavailable!');

		$this->render('gearman', array(
			'commands' => new CArrayDataProvider(array_combine(range(0, count($gearman_status['commands']) - 1), $gearman_status['commands']), array(
				'keyField' => 'command',
				'pagination' => false,
			)),
			'workers' => new CArrayDataProvider(array_combine(range(0, count($gearman_status['workers']) - 1), $gearman_status['workers']), array(
				'keyField' => 'fd',
				'pagination' => false,
			)),
		));
	}

	/**
	 * Checks requirements
	 */
	public function actionCheck() {
		$this->render('check', array(
			'requirements' => array(
				'php' => '5.3',
				'extensions' => array(
					'gd',
					'pdo_mysql',
					'gearman',
					'mbstring',
					'memcached',
				),
				'writableDirs' => array(
					Yii::getPathOfAlias('application.runtime'),
					Yii::getPathOfAlias('logs'),
					Yii::getPathOfAlias('webroot.assets'),
					Yii::getPathOfAlias('webroot.static'),
				),
			),
		));
	}
}