Exemplo n.º 1
0
Arquivo: admin.php Projeto: ajb/rfpez
 /**
  * The main view for any of the data models
  *
  * @param string	$modelName
  *
  * @return Response
  */
 public function action_index($modelName)
 {
     //first we get the data model
     $model = ModelHelper::getModelInstance($modelName);
     $view = View::make("administrator::index", array("modelName" => $modelName));
     //set the layout content and title
     $this->layout->modelName = $modelName;
     $this->layout->content = $view;
 }
Exemplo n.º 2
0
    //accountingjs
    $assets->add('accountingjs', 'js/accounting.js');
    //historyjs
    $assets->add('historyjs', 'js/history/native.history.js');
    //and finally the admin js file
    $assets->add('admin', 'js/admin.js');
});
//validate_admin filter
Route::filter('validate_admin', function () {
    //get the admin check closure that should be supplied in the config
    $authCheck = Config::get('administrator::administrator.auth_check');
    if (!$authCheck()) {
        $loginUrl = URL::to(Config::get('administrator::administrator.login_path', 'user/login'));
        $redirectKey = Config::get('administrator::administrator.login_redirect_key', 'redirect');
        $redirectUri = URL::to_route('admin_dashboard');
        return Redirect::to($loginUrl)->with($redirectKey, $redirectUri);
    }
});
//validate_model filter
Route::filter('validate_model', function () {
    $modelName = URI::segment(2);
    $model = ModelHelper::getModelInstance($modelName);
    //if the model doesn't exist at all, redirect to 404
    if (!$model) {
        return Response::error('404');
    }
    //if the model does exist, check if this user has permission to access it
    if (!ModelHelper::checkPermission($modelName)) {
        Redirect::to_route('admin_dashboard');
    }
});
Exemplo n.º 3
0
 /**
  * Takes a model menu name and returns a ModelConfig instance if it can be found, or false otherwise
  *
  * @param string|int	$modelName 		//the model config/uri name
  *
  * @return false|ModelConfig object
  */
 public static function get($modelName)
 {
     //first we need to find the model's config (if it exists)
     if (!($config = static::find($modelName))) {
         return false;
     }
     //now that we have the config, we can begin to check if all of the required fields are provided
     //but first we have to check if the user has permission to access this model
     $permission = array_get($config, 'permission');
     if (is_callable($permission) && !$permission()) {
         return false;
     }
     //if the title or single names are provided, throw an exception
     if (!is_string(array_get($config, 'title')) || !is_string(array_get($config, 'single'))) {
         throw new Exception("Administrator: " . __('administrator::administrator.valid_title'));
     }
     //get an instance of the model
     $modelName = array_get($config, 'model');
     if (!is_string($modelName)) {
         throw new Exception("Administrator: " . __('administrator::administrator.valid_model'));
     }
     //grab an instance of the Eloquent model
     $config['model'] = ModelHelper::getModelInstance($modelName);
     //check if the required columns array was provided
     if (!is_array(array_get($config, 'columns'))) {
         throw new Exception("Administrator: " . __('administrator::administrator.valid_columns'));
     }
     //check if the edit fields array was provided
     if (!is_array(array_get($config, 'edit_fields'))) {
         throw new Exception("Administrator: " . __('administrator::administrator.valid_edit'));
     }
     //now we can instantiate the object
     return new static($config);
 }