-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
firstrow
committed
Jun 11, 2010
0 parents
commit 4704f56
Showing
1,414 changed files
with
121,275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
<?php | ||
|
||
/** | ||
* YiiadminModule | ||
* | ||
* @uses CWebModule | ||
* @package YiiAdmin | ||
* @version $id$ | ||
* @copyright 2010 | ||
* @author Firstrow <[email protected]> | ||
* @license BSD | ||
*/ | ||
class YiiadminModule extends CWebModule | ||
{ | ||
private $_assetsUrl; | ||
protected $model; | ||
public $attributesWidgets=null; | ||
public $_modelsList=array(); | ||
public static $fileExt='.php'; | ||
private $controller; | ||
public $password; | ||
public $registerModels=array(); | ||
public $excludeModels=array(); | ||
|
||
public function init() | ||
{ | ||
error_reporting(E_ALL ^ E_NOTICE); | ||
Yii::app()->clientScript->registerCoreScript('jquery'); | ||
|
||
Yii::app()->setComponents(array( | ||
'errorHandler'=>array( | ||
'errorAction'=>'yiiadmin/default/error', | ||
), | ||
'user'=>array( | ||
'class'=>'CWebUser', | ||
'stateKeyPrefix'=>'yiiadmin', | ||
'loginUrl'=>Yii::app()->createUrl('yiiadmin/default/login'), | ||
), | ||
)); | ||
|
||
$this->setImport(array( | ||
'yiiadmin.models.*', | ||
'yiiadmin.components.*', | ||
)); | ||
} | ||
|
||
/** | ||
* Получение списка моделей | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function getModelsList() | ||
{ | ||
//$models=YAdminConfig::$registerModels; | ||
$models=$this->registerModels; | ||
|
||
if (!empty($models)) | ||
{ | ||
foreach($models as $model) | ||
{ | ||
// Импорт всех моделей(модели) | ||
Yii::import($model); | ||
|
||
if (substr($model, -1)=='*') | ||
{ | ||
// Если импортируем директорию с моделями, | ||
// Получим список моделей | ||
$files=CFileHelper::findFiles(Yii::getPathOfAlias($model)); | ||
if ($files) | ||
{ | ||
foreach($files as $file) | ||
{ | ||
$class_name=str_replace(self::$fileExt,'',substr(strrchr($file, "/"), 1)); | ||
$this->addModel($class_name); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
$class_name=substr(strrchr($model, "."), 1); | ||
$this->addModel($class_name); | ||
} | ||
} | ||
} | ||
|
||
return array_unique($this->_modelsList); | ||
} | ||
|
||
/** | ||
* Добавление модели в список. | ||
* | ||
* @param mixed $name | ||
* @access protected | ||
* @return void | ||
*/ | ||
protected function addModel($name) | ||
{ | ||
//if (!in_array($name,YAdminConfig::$excludeModels)) | ||
if (!in_array($name,$this->excludeModels)) | ||
$this->_modelsList[]=$name; | ||
} | ||
|
||
/** | ||
* Загрузка модели | ||
* | ||
* @param string $name | ||
* @access public | ||
* @return object | ||
*/ | ||
public function loadModel($name) | ||
{ | ||
$model=(string)$_GET['model_name']; | ||
$this->model=new $model; | ||
return $this->model; | ||
} | ||
|
||
public function createWidget($form,$model,$attribute) | ||
{ | ||
$dbType=$model->tableSchema->columns[$attribute]->dbType; | ||
|
||
$widget=$this->getAttributeWidget($attribute); | ||
|
||
switch ($widget) | ||
{ | ||
case 'textArea'; | ||
return $form->textArea($model,$attribute,array('class'=>'vTextField')); | ||
break; | ||
|
||
case 'textField'; | ||
return $form->textField($model,$attribute,array('class'=>'vTextField')); | ||
break; | ||
|
||
case 'dropDownList': | ||
return $form->dropDownList($model,$attribute,$this->getAttributeChoices($attribute),array('empty'=>'- select -')); | ||
break; | ||
|
||
case 'calendar': | ||
$widgetData=array_slice($this->getAttributeData($attribute),2); | ||
|
||
$data=array( | ||
'name'=>get_class($model).'['.$attribute.']', | ||
'value'=>$model->$attribute, | ||
'language'=>'ru', | ||
'options'=>array( | ||
'showAnim'=>'fold', | ||
'dateFormat'=>'yy-mm-dd', | ||
), | ||
); | ||
|
||
if ($widgetData) | ||
$data=array_merge($data,$widgetData); | ||
|
||
$this->controller->widget('zii.widgets.jui.CJuiDatePicker', $data); | ||
break; | ||
|
||
case 'boolean': | ||
return $form->checkBox($model,$attribute); | ||
break; | ||
|
||
default: | ||
return $form->textField($model,$attribute,array('class'=>'vTextField')); | ||
break; | ||
} | ||
} | ||
|
||
protected function getAttributeWidget($name) | ||
{ | ||
if ($this->attributesWidgets!==null) | ||
{ | ||
if (isset($this->attributesWidgets->$name)) | ||
return $this->attributesWidgets->$name; | ||
else | ||
{ | ||
$dbType=$this->model->tableSchema->columns[$name]->dbType; | ||
if ($dbType=='text') | ||
return 'textArea'; | ||
else | ||
return 'textField'; | ||
} | ||
} | ||
|
||
if (method_exists($this->model,'attributeWidgets')) | ||
$attributeWidgets=$this->model->attributeWidgets(); | ||
else | ||
return null; | ||
|
||
$temp=array(); | ||
|
||
if (!empty($attributeWidgets)) | ||
{ | ||
foreach($attributeWidgets as $key=>$val) | ||
{ | ||
if (isset($val[0]) && isset($val[1])) | ||
{ | ||
$temp[$val[0]]=$val[1]; | ||
$temp[$val[0].'Data']=$val; | ||
} | ||
} | ||
} | ||
|
||
$this->attributesWidgets=(object)$temp; | ||
|
||
return $this->getAttributeWidget($name); | ||
} | ||
|
||
protected function getAttributeData($attribute) | ||
{ | ||
$attribute.='Data'; | ||
if (isset($this->attributesWidgets->$attribute)) | ||
return $this->attributesWidgets->$attribute; | ||
else | ||
return null; | ||
} | ||
|
||
/** | ||
* Получение массива значений атрибута. | ||
* Имя переменной массива с значениями должно быть: attributeNameChoices. | ||
* Например categoryChoices. | ||
* | ||
* @param mixed $attribute | ||
* @access private | ||
* @return array | ||
*/ | ||
private function getAttributeChoices($attribute) | ||
{ | ||
$data=array(); | ||
$choicesName=(string)$attribute.'Choices'; | ||
if (isset($this->model->$choicesName) && is_array($this->model->$choicesName)) | ||
$data=$this->model->$choicesName; | ||
|
||
return $data; | ||
} | ||
|
||
public function getModelNamePlural($model) | ||
{ | ||
if (is_string($model)) | ||
return $model; | ||
|
||
if (!get_class($model)) | ||
$model=new $model; | ||
|
||
if (isset($model->adminName)) | ||
return $model->adminName; | ||
else | ||
return get_class($model); | ||
} | ||
|
||
public function getObjectPluralName($model, $pos=0) | ||
{ | ||
if (is_string($model)) | ||
return $model; | ||
|
||
if (!get_class($model)) | ||
$model=new $model; | ||
|
||
if (!isset($model->pluralNames)) | ||
return get_class($model); | ||
else | ||
return $model->pluralNames[$pos]; | ||
} | ||
|
||
/** | ||
* @return string the base URL that contains all published asset files. | ||
*/ | ||
public function getAssetsUrl() | ||
{ | ||
if($this->_assetsUrl===null) | ||
$this->_assetsUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.yiiadmin.assets')); | ||
return $this->_assetsUrl; | ||
} | ||
|
||
/** | ||
* @param string the base URL that contains all published asset files. | ||
*/ | ||
public function setAssetsUrl($value) | ||
{ | ||
$this->_assetsUrl=$value; | ||
} | ||
|
||
public static function createActionUrl($action,$pk) | ||
{ | ||
$a=new CController; | ||
return $a->createUrl('manageModel',$data->primaryKey); | ||
} | ||
|
||
public static function t($message) | ||
{ | ||
return Yii::t('YiiadminModule.yiiadmin',$message); | ||
} | ||
|
||
public function beforeControllerAction($controller, $action) | ||
{ | ||
if(parent::beforeControllerAction($controller, $action)) | ||
{ | ||
$this->controller=$controller; | ||
$route=$controller->id.'/'.$action->id; | ||
|
||
$publicPages=array( | ||
'default/login', | ||
'default/error', | ||
); | ||
if($this->password!==false && Yii::app()->user->isGuest && !in_array($route,$publicPages)) | ||
Yii::app()->user->loginRequired(); | ||
else | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
|
||
|
||
/* Reset Styles (reset.css of Blueprint www.blueprintcss.org) | ||
------------------------------------------------------------------------------------------------------ */ | ||
|
||
@import url('reset.css'); | ||
|
||
|
||
|
||
/* Grappelli Styles: | ||
The core settings of Grappelli are defined here. | ||
Do not change them (better use your own skins/css in the next section). | ||
------------------------------------------------------------------------------------------------------ */ | ||
|
||
@import url('typography.css'); | ||
@import url('structures.css'); | ||
@import url('components.css'); | ||
@import url('tools.css'); | ||
@import url('forms.css'); | ||
@import url('buttons.css'); | ||
@import url('tables.css'); | ||
|
||
|
||
|
||
/* Grappelli Skins & Custom Styles: | ||
Use the delivered Grappelli skins or import your own skins/css here | ||
------------------------------------------------------------------------------------------------------ */ | ||
|
||
/* Grappelli Basic Skin: The Plain Version */ | ||
/*@import url('grappelli-skin-basic.css');*/ | ||
|
||
/* Grappelli Default Skin: Adds Border-Radius & Background-Gradients to the Grappelli Basic Skin */ | ||
@import url('grappelli-skin-default.css'); |
Oops, something went wrong.