public function render()
 {
     $activeWindowHash = Yii::$app->request->get('activeWindowHash');
     $activeWindowCallback = Yii::$app->request->get('activeWindowCallback');
     $activeWindows = $this->config->getPointer('aw');
     $obj = $activeWindows[$activeWindowHash]['object'];
     $function = 'callback' . Inflector::id2camel($activeWindowCallback);
     return ObjectHelper::callMethodSanitizeArguments($obj, $function, Yii::$app->request->post());
     /*
     $reflection = new \ReflectionMethod($obj, $function);
     
     $methodArgs = [];
     
     if ($reflection->getNumberOfRequiredParameters() > 0) {
         foreach ($reflection->getParameters() as $param) {
             if (!array_key_exists($param->name, $args)) {
                 throw new \Exception("the provided argument '".$param->name."' does not exists in the provided arguments list.");
             }
             $methodArgs[] = $args[$param->name];
         }
     }
     
     $response = call_user_func_array(array($obj, $function), $methodArgs);
     
     return $response;
     */
 }
Example #2
0
 public function testId2camel()
 {
     $this->assertEquals('PostTag', Inflector::id2camel('post-tag'));
     $this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_'));
     $this->assertEquals('PostTag', Inflector::id2camel('post-tag'));
     $this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_'));
 }
Example #3
0
 public function getView()
 {
     if ($this->_view === null) {
         $this->_view = lcfirst(Inflector::id2camel($this->id));
     }
     return $this->_view;
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->action === null) {
         $this->action = Inflector::id2camel($this->id);
     }
 }
Example #5
0
 public function actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     $method = 'callback' . Inflector::id2camel($callback);
     return ObjectHelper::callMethodSanitizeArguments($block, $method, Yii::$app->request->get());
 }
Example #6
0
 /**
  * Sends a request to the _search API and returns the result.
  * @param array $options
  * @throws ErrorResponseException
  * @return mixed
  */
 public function search($options = [])
 {
     $url = $this->index . Inflector::id2camel(ArrayHelper::remove($options, 'scenario', 'search'));
     $query = $this->queryParts;
     $options = array_merge($query, $options);
     return $this->db->post($url, $options);
 }
Example #7
0
 /**
  * @param \yii\base\Module $module
  * @param string           $id
  *
  * @return \yii\base\Controller $controller
  */
 public function getModuleController(Module $module, $id)
 {
     $className = sprintf('%s\\%sController', $module->controllerNamespace, Inflector::id2camel($id));
     if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\\base\\Controller')) {
         return new $className($id, $module);
     }
     return null;
 }
Example #8
0
 /**
  * Returns name of the operation based on controller's class and it's action name
  * @param Controller|string $controller
  * @param string $action
  * @return string
  */
 public static function operationName($controller, $action = '')
 {
     if (is_object($controller)) {
         $controller = $controller->className();
     }
     /** @var string $controller */
     return self::authItemName($controller . ':' . Inflector::id2camel($action));
 }
Example #9
0
 public function hasAction($id, $actions = null)
 {
     if (is_null($actions)) {
         $actions = $this->actions();
     }
     $method = 'action' . Inflector::id2camel($id);
     return isset($actions[$id]) || method_exists($this, $method);
 }
Example #10
0
 public function init()
 {
     $modelId = Yii::$app->getRequest()->getQueryParam('modelId');
     if ($modelId) {
         $this->modelName = Inflector::id2camel($modelId);
     }
     parent::init();
 }
Example #11
0
 public function getModelByTableName($name)
 {
     $returnName = str_replace($this->tablePrefix, '', $name);
     $returnName = Inflector::id2camel($returnName, '_');
     if ($this->singularEntities) {
         $returnName = Inflector::singularize($returnName);
     }
     return $returnName;
 }
Example #12
0
 public function testId2camel()
 {
     $this->assertEquals('PostTag', Inflector::id2camel('post-tag'));
     $this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_'));
     $this->assertEquals('PostTag', Inflector::id2camel('post-tag'));
     $this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_'));
     $this->assertEquals('FooYBar', Inflector::id2camel('foo-y-bar'));
     $this->assertEquals('FooYBar', Inflector::id2camel('foo_y_bar', '_'));
 }
Example #13
0
 /**
  * Calls the named method which is not a class method.
  * Call this method directly from database connections
  */
 public function __call($name, $params)
 {
     $method = explode('-', Inflector::camel2id($name));
     $model = array_shift($method);
     $method = lcfirst(Inflector::id2camel(implode('-', $method)));
     $class = isset($this->models[$model]) ? $this->models[$model] : null;
     if ($class && method_exists($class, $method)) {
         return call_user_func_array([$class, $method], $params);
     }
     $message = 'Calling unknown method: ' . ($class ? $class : get_class($this)) . "::{$name}()";
     throw new UnknownMethodException($message);
 }
Example #14
0
function getAllChild($role_id, $parent_id = NULL, $level = 0)
{
    foreach (\app\models\Menu::find()->where(["parent_id" => $parent_id])->all() as $menu) {
        ?>
                    <div class="form-group" style="padding-left: <?php 
        echo $level * 20;
        ?>
px">
                        <label>
                            <input type="checkbox" name="menu[]" value="<?php 
        echo $menu->id;
        ?>
" class="minimal" <?php 
        echo isChecked($role_id, $menu->id) ? "checked" : "";
        ?>
>
                        </label>
                        <label style="padding-left: 10px"> <?php 
        echo $menu->name;
        ?>
</label>
                    </div>
                <?php 
        //Show All Actions
        $camelName = Inflector::id2camel($menu->controller);
        $fullControllerName = "app\\controllers\\" . $camelName . "Controller";
        if (class_exists($fullControllerName)) {
            $reflection = new ReflectionClass($fullControllerName);
            $methods = $reflection->getMethods();
            echo "<div class=\"form-group\" style=\"padding-left: " . ($level * 20 + 10) . "px;\">";
            echo "<label><input type=\"checkbox\" class=\"minimal select-all\" ></label><label style=\"padding: 0px 20px 0px 5px\"> Select All</label>";
            foreach ($methods as $method) {
                if (substr($method->name, 0, 6) == "action" && $method->name != "actions") {
                    $camelAction = substr($method->name, 6);
                    $id = Inflector::camel2id($camelAction);
                    $name = Inflector::camel2words($camelAction);
                    $action = \app\models\Action::find()->where(["action_id" => $id, "controller_id" => $menu->controller])->one();
                    if ($action == NULL) {
                        //If the action not in database, save it !
                        $action = new \app\models\Action();
                        $action->action_id = $id;
                        $action->controller_id = $menu->controller;
                        $action->name = $name;
                        $action->save();
                    }
                    showCheckbox("action[]", $action->id, $name, hasAccessToAction($role_id, $action->id));
                }
            }
            echo "</div>";
        }
        getAllChild($role_id, $menu->id, $level + 1);
    }
}
 public function actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     if (!$model) {
         throw new Exception("Unable to find item id.");
     }
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     if (!$block) {
         throw new Exception("Unable to find block object.");
     }
     return ObjectHelper::callMethodSanitizeArguments($block, 'callback' . Inflector::id2camel($callback), Yii::$app->request->get());
 }
 /**
  * Checks whether the site can be accessed by the current user
  * @return boolean
  */
 protected function checkAccess()
 {
     $controller = $this->controllerNamespace . '\\' . Inflector::id2camel($this->defaultRoute) . 'Controller';
     if ($controller::className() !== Yii::$app->requestedAction->controller->className()) {
         $ip = Yii::$app->getRequest()->getUserIP();
         foreach ($this->allowedIPs as $filter) {
             if ($filter === '*' || $filter === $ip || ($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos)) {
                 return;
             }
         }
         Yii::$app->getResponse()->redirect($this->redirectURL);
     }
 }
 public function render()
 {
     $activeWindowHash = Yii::$app->request->get('activeWindowHash');
     $activeWindowCallback = Yii::$app->request->get('activeWindowCallback');
     $activeWindows = $this->config->getPointer('aw');
     if (!isset($activeWindows[$activeWindowHash])) {
         throw new Exception("Unable to find ActiveWindow " . $activeWindowHash);
     }
     $obj = Yii::createObject($activeWindows[$activeWindowHash]['objectConfig']);
     $obj->setItemId(Yii::$app->session->get($activeWindowHash));
     $obj->setConfigHash($this->config->getHash());
     $obj->setActiveWindowHash($activeWindowHash);
     $function = 'callback' . Inflector::id2camel($activeWindowCallback);
     return ObjectHelper::callMethodSanitizeArguments($obj, $function, Yii::$app->request->post());
 }
Example #18
0
 /**
  * Generates a class name from the specified table name.
  * @param string $tableName the table name (which may contain schema prefix)
  * @return string the generated class name
  */
 protected function generateClassName($tableName)
 {
     if (isset($this->_classNames[$tableName])) {
         return $this->_classNames[$tableName];
     }
     if (($pos = strrpos($tableName, '.')) !== false) {
         $tableName = substr($tableName, $pos + 1);
     }
     $db = $this->getDbConnection();
     $patterns = [];
     $patterns[] = "/^{$db->tablePrefix}(.*?)\$/";
     $patterns[] = "/^(.*?){$db->tablePrefix}\$/";
     if (strpos($this->tableName, '*') !== false) {
         $pattern = $this->tableName;
         if (($pos = strrpos($pattern, '.')) !== false) {
             $pattern = substr($pattern, $pos + 1);
         }
         $patterns[] = '/^' . str_replace('*', '(\\w+)', $pattern) . '$/';
     }
     $className = $tableName;
     foreach ($patterns as $pattern) {
         if (preg_match($pattern, $tableName, $matches)) {
             $className = $matches[1];
             break;
         }
     }
     /* 
      * Remove Prefix Tabel 
      * tbl_ ref_ tb_		 
      */
     $suffix_2 = substr($className, 0, 3);
     $suffix_3 = substr($className, 0, 4);
     if ($suffix_3 === 'tbl_' or $suffix_3 === 'ref_') {
         $className = substr($className, 4, 255);
     } else {
         if ($suffix_2 === 'tb_') {
             $className = substr($className, 3, 255);
         }
     }
     return $this->_classNames[$tableName] = Inflector::id2camel($className, '_');
 }
 protected function getControllers($namespace, $prefix, &$result)
 {
     $path = Yii::getAlias('@' . str_replace('\\', '/', $namespace));
     if (!is_dir($path)) {
         return;
     }
     foreach (scandir($path) as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         if (is_dir($path . '/' . $file)) {
             $this->getControllers($namespace . $file . '\\', $prefix . $file . '/', $result);
         } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
             $id = Inflector::camel2id(substr(basename($file), 0, -14));
             $className = $namespace . Inflector::id2camel($id) . 'Controller';
             if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\\base\\Controller')) {
                 $result[$prefix . $id] = $this->getInfo($className);
             }
         }
     }
 }
Example #20
0
    public function columnFormat($column, $model)
    {
        // do not handle columns with a primary key, TOOD: review(!) should not be omitted in every case
        if ($column->isPrimaryKey) {
            return null;
        }
        $relation = $this->generator->getRelationByColumn($model, $column);
        if ($relation) {
            if ($relation->multiple) {
                return null;
            }
            $title = $this->generator->getModelNameAttribute($relation->modelClass);
            $route = $this->generator->createRelationRoute($relation, 'view');
            $method = __METHOD__;
            $relationGetter = 'get' . Inflector::id2camel(str_replace('_id', '', $column->name), '_') . '()';
            // TODO: improve detection
            $pk = key($relation->link);
            $relationModel = new $relation->modelClass();
            $pks = $relationModel->primaryKey();
            $paramArrayItems = "";
            foreach ($pks as $attr) {
                $paramArrayItems .= "'{$attr}' => \$rel->{$attr},";
            }
            $code = <<<EOS
[ // generated by {$method}
    "class" => yii\\grid\\DataColumn::className(),
    "attribute" => "{$column->name}",
    "value" => function(\$model){
        if (\$rel = \$model->{$relationGetter}->one()) {
            return yii\\helpers\\Html::a(\$rel->{$title},["{$route}", {$paramArrayItems}],["data-pjax"=>0]);
        } else {
            return '';
        }
    },
    "format" => "raw",
]
EOS;
            return $code;
        }
    }
Example #21
0
 /**
  * Get controller routes
  * @param $module
  * @param $namespace
  * @param $prefix
  * @param $result
  * @throws \yii\base\InvalidConfigException
  */
 private static function getControllerRoutes($module, $namespace, $prefix, &$result)
 {
     $path = Yii::getAlias('@' . str_replace('\\', '/', $namespace));
     if (!is_dir($path)) {
         return;
     }
     foreach (scandir($path) as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         if (is_dir($path . '/' . $file)) {
             self::getControllerRoutes($module, $namespace . $file . '\\', $prefix . $file . '/', $result);
         } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
             $id = Inflector::camel2id(substr(basename($file), 0, -14));
             $className = $namespace . Inflector::id2camel($id) . 'Controller';
             if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\\base\\Controller')) {
                 $controller = Yii::createObject($className, [$prefix . $id, $module]);
                 self::getActionRoutes($controller, $result);
                 $result[] = '/' . $controller->uniqueId . '/*';
             }
         }
     }
 }
Example #22
0
 public function init()
 {
     if ($this->useNativeBootstrap == true) {
         \Yii::info('Registering a bootstrap assets', __METHOD__);
         $this->view->registerAssetBundle(BootstrapAsset::className(), View::POS_HEAD);
         $this->view->registerAssetBundle(BootstrapPluginAsset::className(), View::POS_HEAD);
     }
     $this->view->registerAssetBundle(AssetBundle::className(), View::POS_BEGIN);
     $this->options['id'] = $this->id;
     if (!empty($this->value) && !isset($this->sliderOptions['value'])) {
         $this->sliderOptions['value'] = $this->value;
     }
     if (strtolower($this->mode) === 'js') {
         $this->view->registerJs(sprintf('var slider%1$s = window.slider%1$s = new Slider(\'#%2$s\',%3$s);', Inflector::id2camel($this->id), $this->id, Json::encode($this->sliderOptions)), View::POS_END);
     } elseif (strtolower($this->mode) === 'data') {
         $data = ['provide' => 'slider'];
         foreach ($this->sliderOptions as $k => $v) {
             $data[sprintf('slider-%s', $k)] = $v;
         }
         $this->options['data'] = $data;
     } else {
         throw new InvalidParamException('A \'mode\' must be set to \'data\' or \'js\'!');
     }
 }
Example #23
0
 /**
  * Get list controller under module
  * @param \yii\base\Module $module
  * @param string $namespace
  * @param string $prefix
  * @param mixed $result
  * @return mixed
  */
 private function getControllerFiles($module, $namespace, $prefix, &$result)
 {
     $path = @Yii::getAlias('@' . str_replace('\\', '/', $namespace));
     $token = "Get controllers from '{$path}'";
     Yii::beginProfile($token, __METHOD__);
     try {
         if (!is_dir($path)) {
             return;
         }
         foreach (scandir($path) as $file) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             if (is_dir($path . '/' . $file)) {
                 $this->getControllerFiles($module, $namespace . $file . '\\', $prefix . $file . '/', $result);
             } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
                 $id = Inflector::camel2id(substr(basename($file), 0, -14));
                 $className = $namespace . Inflector::id2camel($id) . 'Controller';
                 if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\\base\\Controller')) {
                     $this->getControllerActions($className, $prefix . $id, $module, $result);
                 }
             }
         }
     } catch (\Exception $exc) {
         Yii::error($exc->getMessage(), __METHOD__);
     }
     Yii::endProfile($token, __METHOD__);
 }
Example #24
0
class WorkController extends Backend
{
    /** @var string Model class for CRUD */
    public $modelClass = '<?php 
echo $generator->modelClass;
?>
';
<?php 
foreach ($generator->getExtraActions() as $action) {
    ?>

    /**
    * @return string
    */
    public function action<?php 
    echo Inflector::id2camel($action);
    ?>
()
    {
        return $this->render('<?php 
    echo $action;
    ?>
', []);
    }
<?php 
}
if (!$generator->controllerActionIndexEnabled) {
    ?>

    /**
    * Index
Example #25
0
        <?php 
if (isset($this->blocks['content-header'])) {
    ?>
            <h1><?php 
    echo $this->blocks['content-header'];
    ?>
</h1>
        <?php 
} else {
    ?>
            <h1>
                <?php 
    if ($this->title !== null) {
        echo \yii\helpers\Html::encode($this->title);
    } else {
        echo \yii\helpers\Inflector::camel2words(\yii\helpers\Inflector::id2camel($this->context->module->id));
        echo $this->context->module->id !== \Yii::$app->id ? '<small>Module</small>' : '';
    }
    ?>
            </h1>
        <?php 
}
?>

        <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
    </section>

    <section class="content">
        <?php 
Example #26
0
 /**
  * Generates a class name from the specified table name.
  * @param string $tableName the table name (which may contain schema prefix)
  * @param boolean $useSchemaName should schema name be included in the class name, if present
  * @return string the generated class name
  */
 protected function generateClassName($tableName, $useSchemaName = null)
 {
     if (isset($this->classNames[$tableName])) {
         return $this->classNames[$tableName];
     }
     $schemaName = '';
     $fullTableName = $tableName;
     if (($pos = strrpos($tableName, '.')) !== false) {
         if ($useSchemaName === null && $this->useSchemaName || $useSchemaName) {
             $schemaName = substr($tableName, 0, $pos) . '_';
         }
         $tableName = substr($tableName, $pos + 1);
     }
     $db = $this->getDbConnection();
     $patterns = [];
     $patterns[] = "/^{$db->tablePrefix}(.*?)\$/";
     $patterns[] = "/^(.*?){$db->tablePrefix}\$/";
     if (strpos($this->tableName, '*') !== false) {
         $pattern = $this->tableName;
         if (($pos = strrpos($pattern, '.')) !== false) {
             $pattern = substr($pattern, $pos + 1);
         }
         $patterns[] = '/^' . str_replace('*', '(\\w+)', $pattern) . '$/';
     }
     $className = $tableName;
     foreach ($patterns as $pattern) {
         if (preg_match($pattern, $tableName, $matches)) {
             $className = $matches[1];
             break;
         }
     }
     return $this->classNames[$fullTableName] = Inflector::id2camel($schemaName . $className, '_');
 }
Example #27
0
 /**
  * Get ID interface
  * @return string
  */
 public function getId()
 {
     if ($this->id === null) {
         $this->setId(Inflector::underscore((new \ReflectionClass(__CLASS__))->getShortName()) . '-' . Inflector::underscore(Inflector::id2camel(Yii::$app->controller->action->getUniqueId(), '/')) . ($this->isUniqueId() ? '-' . uniqid() : ''));
     }
     return $this->id;
 }
Example #28
0
 public function resolveClassName($className)
 {
     $className = Inflector::id2camel($className, '_');
     if (isset($this->aliases[$className])) {
         return $this->aliases[$className];
     }
     foreach ($this->namespaces as $namespace) {
         $resolvedClassName = $namespace . '\\' . $className;
         if (class_exists($resolvedClassName)) {
             return $this->aliases[$className] = $resolvedClassName;
         }
     }
     return $className;
 }
Example #29
0
 /**
  * Generates a class name from the specified table name.
  *
  * @param string $tableName the table name (which may contain schema prefix)
  *
  * @return string the generated class name
  */
 protected function generateClassName($tableName)
 {
     #Yii::trace("Generating class name for '{$tableName}'...", __METHOD__);
     if (isset($this->classNames2[$tableName])) {
         #Yii::trace("Using '{$this->classNames2[$tableName]}' for '{$tableName}' from classNames2.", __METHOD__);
         return $this->classNames2[$tableName];
     }
     if (isset($this->tableNameMap[$tableName])) {
         Yii::trace("Converted '{$tableName}' from tableNameMap.", __METHOD__);
         return $this->classNames2[$tableName] = $this->tableNameMap[$tableName];
     }
     if (($pos = strrpos($tableName, '.')) !== false) {
         $tableName = substr($tableName, $pos + 1);
     }
     $db = $this->getDbConnection();
     $patterns = [];
     $patterns[] = "/^{$this->tablePrefix}(.*?)\$/";
     $patterns[] = "/^(.*?){$this->tablePrefix}\$/";
     $patterns[] = "/^{$db->tablePrefix}(.*?)\$/";
     $patterns[] = "/^(.*?){$db->tablePrefix}\$/";
     if (strpos($this->tableName, '*') !== false) {
         $pattern = $this->tableName;
         if (($pos = strrpos($pattern, '.')) !== false) {
             $pattern = substr($pattern, $pos + 1);
         }
         $patterns[] = '/^' . str_replace('*', '(\\w+)', $pattern) . '$/';
     }
     $className = $tableName;
     foreach ($patterns as $pattern) {
         if (preg_match($pattern, $tableName, $matches)) {
             $className = $matches[1];
             Yii::trace("Mapping '{$tableName}' to '{$className}' from pattern '{$pattern}'.", __METHOD__);
             break;
         }
     }
     $returnName = Inflector::id2camel($className, '_');
     Yii::trace("Converted '{$tableName}' to '{$returnName}'.", __METHOD__);
     return $this->classNames2[$tableName] = $returnName;
 }
Example #30
0
<?php

/**
 * This is the template for generating an action view file.
 */
use yii\helpers\Inflector;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\form\Generator */
echo "<?php\n";
?>

public function action<?php 
echo Inflector::id2camel(trim(basename($generator->viewName), '_'));
?>
()
{
    $model = new <?php 
echo $generator->modelClass;
echo empty($generator->scenarioName) ? "()" : "(['scenario' => '{$generator->scenarioName}'])";
?>
;

    if ($model->load(Yii::$app->request->post())) {
        if ($model->validate()) {
            // form inputs are valid, do something here
            return;
        }
    }

    return $this->render('<?php 
echo basename($generator->viewName);