public function registerScripts() { $jsonOptions = Json::encode($this->leptureOptions); $varName = Inflector::classify('editor' . $this->id); $script = "var {$varName} = new Editor(" . $jsonOptions . "); {$varName}.render();"; $this->view->registerJs($script); }
/** * Registers simplemde markdown assets */ public function registerScripts() { $jsonOptions = Json::encode($this->mdeOptions); $varName = Inflector::classify('editor' . $this->id); $script = "var {$varName} = new SimpleMDE(" . $jsonOptions . ");"; $this->view->registerJs($script); }
public function beforeAction($action) { $caller = \yii::$app->getRequest()->getQueryParam('caller'); if (!isset($caller) || $caller == '') { throw new \yii\base\InvalidRouteException('Module requires specification of caller parameter'); } $this->_post = \yii\helpers\Inflector::classify($caller); $this->modelClass = $this->module->params['modelRegister'][$caller]; return parent::beforeAction($action); }
echo $generator->helperCrud->getClassid(CrudHelper::RK_MODEL_CM); ?> -form"> <?php echo "<?php "; ?> $form = ActiveForm::begin(); ?> <?php echo "<?= GxFlashHelper::alertValidation(\$model) ?>"; ?> <?php if ($generator->generateMutation) { echo "<?=\n \$form->field(\$model, " . ModelHelper::root($generator->helperModel->getClass(ModelHelper::RK_MODEL_CM)) . "::" . sprintf('%s%s', \dlds\giixer\Module::RELATION_NAME_PREFIX, strtoupper(Inflector::pluralize($generator->mutationSourceTableName))) . ")->widget(dlds\\rels\\widgets\\RelTabs::className(), [\n 'relView' => '/" . $generator->helperCrud->getClassid(CrudHelper::RK_MODEL_CM) . "/crud/relations/" . Inflector::camel2id(StringHelper::basename($generator->mutationJoinTableName)) . "',\n 'header' => '" . lcfirst(Inflector::classify($generator->mutationSourceTableName)) . ".title',\n 'form' => \$form,\n ])->label(false);\n ?>"; ?> <?php } ?> <?php foreach ($columnNames as $attribute) { if (isset($safeAttributes[$attribute]) && !$safeAttributes[$attribute]->isPrimaryKey && $attribute != $generator->sortableColumnAttribute) { echo "<?= " . $generator->generateActiveField($attribute) . " ?>\n\n"; } } ?> <div class="form-group"> <?php
* @throws NotFoundHttpException */ public function actionDetail(<?php echo $actionParams; ?> ) { $model = <?php echo StringHelper::basename($generator->modelClass); ?> ::find() <?php foreach ($pks as $pk) { ?> ->findBy<?php echo Inflector::classify($pk); ?> ($<?php echo $pk; ?> ) <?php } ?> ->one(); if ($model) { $data = $model->toArray(); <?php echo $generator->generateSuccessData(3, '$data') . "\n"; ?>
public function testClassify() { $this->assertEquals("CustomerTable", Inflector::classify('customer_tables')); }
/** * @inheritdoc */ public function generate() { $db = $this->getDbConnection(); $files = []; $tables = []; $this->getTableNames(); $counter = 0; foreach ($this->tableNames as $table) { $tables[$counter]['url'] = strtolower(Inflector::classify($table)) . "/table"; $tables[$counter]['comma'] = count($this->tableNames) == count($tables) ? '' : ','; $tables[$counter++]['name'] = $table; } foreach ($this->tableNames as $table) { $tableSchema = $db->getTableSchema($table); $primaryKey = $tableSchema->primaryKey[0]; $fieldsArray = []; $headersArray = []; foreach ($tableSchema->columns as $column) { if (!$column->autoIncrement) { array_push($fieldsArray, $column->name); array_push($headersArray, Inflector::humanize($column->name)); } } $fields = implode(',', $fieldsArray); $headers = implode(',', $headersArray); $modelControllerName = ucfirst(strtolower(Inflector::classify($table))); $files[] = new CodeFile($this->getModelFile($modelControllerName), $this->render('model.php', ['fields' => $fields, 'rules' => $this->generateRules($tableSchema), 'modelName' => $modelControllerName, 'primaryKey' => $primaryKey, 'tableName' => $table])); $files[] = new CodeFile($this->getControllerFile($modelControllerName), $this->render('controller.php', ['fields' => $fields, 'controllerName' => $modelControllerName, 'modelName' => $modelControllerName, 'primaryKey' => $primaryKey])); $files[] = new CodeFile($this->getViewFile($modelControllerName), $this->render('view.php', ['headers' => $headers, 'tableName' => $table, 'tables' => $tables, 'controllerName' => strtolower($modelControllerName)])); } $files[] = new CodeFile(Yii::getAlias($this->viewPath) . '/layouts/fullscreen.php', $this->render('layout.php')); $this->lastControllerName = $modelControllerName; return $files; }
foreach ($this-><?php echo Inflector::pluralize($primaryKey); ?> as $<?php echo $primaryKey; ?> ) { $<?php echo $modelVarName; ?> = <?php echo $modelClassName; ?> ::find() ->findBy<?php echo Inflector::classify($primaryKey); ?> ($<?php echo $primaryKey; ?> ) ->one(); if ($<?php echo $modelVarName; ?> ) { if (!$<?php echo $modelVarName; ?> ->delete()) { if ($<?php
public function actionSearchModels() { foreach (Yii::$app->getDb()->createCommand('SHOW FULL TABLES;')->queryAll(\PDO::FETCH_NUM) as $row) { list($tableName, $tableType) = $row; $ns = $tableType == 'VIEW' ? 'app\\models\\readonly\\search' : 'app\\models\\search'; $modelName = Inflector::classify($tableName); $modelClass = $ns . '\\' . $modelName . 'SearchBase'; $secondModelClass = $ns . '\\' . $modelName . 'Search'; $this->_commands[$secondModelClass] = ['gii/search2', 'modelClass' => $modelClass, 'secondModelClass' => $secondModelClass, 'interactive' => 0, 'overwrite' => 1]; } }
/** * @param array $generatedRelations * @return array */ protected function fixRelations(array $generatedRelations) { foreach ($generatedRelations as $tableName => $tableRelations) { $fixRelationNames = []; foreach ($tableRelations as $relationName => $relation) { if (preg_match('~^(\\D+)\\d+$~', $relationName, $match)) { $fixRelationNames[] = $match[1]; } } foreach ($fixRelationNames as $fixRelationName) { foreach ($tableRelations as $relationName => $relation) { if ($relationName == $fixRelationName) { if (isset($tableRelations[$relationName])) { $tableRelations[$relationName . '99'] = $tableRelations[$relationName]; unset($tableRelations[$relationName]); } if (isset($generatedRelations[$tableName][$relationName])) { $generatedRelations[$tableName][$relationName . '99'] = $generatedRelations[$tableName][$relationName]; unset($generatedRelations[$tableName][$relationName]); } if (isset($this->allRelations[$tableName][$relationName])) { $this->allRelations[$tableName][$relationName . '99'] = $this->allRelations[$tableName][$relationName]; unset($this->allRelations[$tableName][$relationName]); } if (isset($this->singularRelations[$tableName][$relationName])) { $this->singularRelations[$tableName][$relationName . '99'] = $this->singularRelations[$tableName][$relationName]; unset($this->singularRelations[$tableName][$relationName]); } if (isset($this->pluralRelations[$tableName][$relationName])) { $this->pluralRelations[$tableName][$relationName . '99'] = $this->pluralRelations[$tableName][$relationName]; unset($this->pluralRelations[$tableName][$relationName]); } } } } foreach ($fixRelationNames as $fixRelationName) { foreach ($tableRelations as $relationName => $relation) { if (preg_match('~^(\\D+)\\d+$~', $relationName, $match) && $match[1] == $fixRelationName) { $relation = $this->allRelations[$tableName][$relationName]; if ($relation['hasMany']) { $linkKeys = array_keys($relation['link']); if (count($linkKeys) == 1) { $linkKey = preg_replace('~_id$~', '', $linkKeys[0]); if ($tableName == $linkKey) { $relationName2 = $fixRelationName; } else { $relationName2 = Inflector::classify($linkKey); $relationName2 = str_replace(Inflector::singularize($fixRelationName), '', $relationName2); $relationName2 .= $fixRelationName; } echo $relationName, ' -> ', $relationName2, "\n"; if (isset($tableRelations[$relationName])) { $tableRelations[$relationName2] = $tableRelations[$relationName]; unset($tableRelations[$relationName]); } if (isset($generatedRelations[$tableName][$relationName])) { $generatedRelations[$tableName][$relationName2] = $generatedRelations[$tableName][$relationName]; unset($generatedRelations[$tableName][$relationName]); } if (isset($this->allRelations[$tableName][$relationName])) { $this->allRelations[$tableName][$relationName2] = $this->allRelations[$tableName][$relationName]; unset($this->allRelations[$tableName][$relationName]); } if (isset($this->singularRelations[$tableName][$relationName])) { $this->singularRelations[$tableName][$relationName2] = $this->singularRelations[$tableName][$relationName]; unset($this->singularRelations[$tableName][$relationName]); } if (isset($this->pluralRelations[$tableName][$relationName])) { $this->pluralRelations[$tableName][$relationName2] = $this->pluralRelations[$tableName][$relationName]; unset($this->pluralRelations[$tableName][$relationName]); } } } } } } } return $generatedRelations; }
protected function prepareFields(BaseActiveRecord $model) { $modelClass = get_class($model); $validKeys = $model->attributes(); $fields = ModelHelper::normalizeBrackets(ModelHelper::expandBrackets($this->fields ?: ModelHelper::formFields($model), $validKeys), $validKeys); foreach ($model->getBehaviors() as $behavior) { if ($behavior instanceof DatetimeBehavior) { foreach ($behavior->attributes as $datetimeAttribute) { if (array_key_exists($datetimeAttribute, $fields) && !array_key_exists('type', $fields[$datetimeAttribute])) { $fields[$datetimeAttribute]['type'] = 'datetime'; } } } elseif ($behavior instanceof SoftDeleteBehavior) { if (array_key_exists($behavior->deletedAttribute, $fields)) { $fields[$behavior->deletedAttribute]['visible'] = false; } } elseif ($behavior instanceof TimeDeleteBehavior) { if (array_key_exists($behavior->deletedAtAttribute, $fields)) { $fields[$behavior->deletedAtAttribute]['visible'] = false; } } elseif ($behavior instanceof TimestampBehavior) { if (array_key_exists($behavior->createdAtAttribute, $fields)) { $fields[$behavior->createdAtAttribute]['readOnly'] = true; } if (array_key_exists($behavior->updatedAtAttribute, $fields)) { $fields[$behavior->updatedAtAttribute]['readOnly'] = true; } if (array_key_exists($behavior->timestampAttribute, $fields)) { $fields[$behavior->timestampAttribute]['readOnly'] = true; } } } $tableSchema = $modelClass::getTableSchema(); foreach ($tableSchema->foreignKeys as $foreignKey) { if (count($foreignKey) == 2) { $relatedQueryMethod = 'get' . Inflector::classify($foreignKey[0]); if (method_exists($model, $relatedQueryMethod) && is_callable([$model, $relatedQueryMethod])) { $relatedAttribute = array_keys($foreignKey)[1]; $fields[$relatedAttribute]['type'] = 'dropDownList'; $fields[$relatedAttribute]['items'] = ModelHelper::listItems($model->{$relatedQueryMethod}()); } } } foreach ($fields as $attribute => $options) { if (!array_key_exists('type', $options)) { $listItemsMethod = Inflector::variablize($attribute) . 'ListItems'; if (method_exists($modelClass, $listItemsMethod) && is_callable([$modelClass, $listItemsMethod])) { $options['type'] = 'dropDownList'; $options['items'] = $modelClass::$listItemsMethod($model); } } $columnSchema = $tableSchema->getColumn($attribute); if ($columnSchema) { if ($columnSchema->isPrimaryKey && !method_exists($model, 'search')) { if (!$model->getIsNewRecord()) { $options['readOnly'] = true; } elseif ($columnSchema->autoIncrement) { $options['visible'] = false; } } if (!array_key_exists('type', $options)) { $options['type'] = $columnSchema->type; if (in_array($columnSchema->type, ['tinyint', 'smallint', 'integer', 'bigint'])) { if ($columnSchema->size == 1 && $columnSchema->unsigned) { $options['type'] = 'boolean'; } else { $options['size'] = $columnSchema->size; $options['unsigned'] = $columnSchema->unsigned; } } elseif (in_array($columnSchema->type, ['decimal', 'numeric', 'money'])) { $options['size'] = $columnSchema->size; $options['scale'] = $columnSchema->scale; $options['unsigned'] = $columnSchema->unsigned; } elseif ($columnSchema->type == 'string') { $options['size'] = $columnSchema->size; } } } if (array_key_exists('type', $options)) { if ($options['type'] && is_string($options['type'])) { if ($options['type'] == 'invisible') { $options['visible'] = false; } elseif (!array_key_exists('class', $options)) { $fieldClass = 'yii\\mozayka\\form\\' . Inflector::id2camel($options['type']) . 'Field'; if (class_exists($fieldClass)) { $options['class'] = $fieldClass; } } } unset($options['type']); } $fields[$attribute] = $options; } return array_filter($fields, function ($options) { return !array_key_exists('visible', $options) || $options['visible']; }); }
/** * @param string $name * @return string * @throws NotFoundGatewayException */ protected function getGatewayClassByName($name) { $className = __NAMESPACE__ . '\\gateways\\' . Inflector::classify($name); if (!class_exists($className)) { throw new NotFoundGatewayException('Gateway `' . $name . '` is not found.'); } return $className; }