repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
luyadev/luya-module-admin | src/image/Item.php | Item.getSource | public function getSource($scheme = false)
{
if (!$this->getFileExists()) {
if (Yii::$app->storage->autoFixMissingImageSources === false) {
return false;
}
// The image source does not exist, probably it has been deleted due to filter changes.
// storage component is going go try to re-create this image now.
$apply = Yii::$app->storage->createImage($this->getFileId(), $this->getFilterId());
}
$fileName = $this->getFilterId() . '_' . $this->getFile()->getSystemFileName();
return $scheme ? Yii::$app->storage->fileAbsoluteHttpPath($fileName) : Yii::$app->storage->fileHttpPath($fileName);
} | php | public function getSource($scheme = false)
{
if (!$this->getFileExists()) {
if (Yii::$app->storage->autoFixMissingImageSources === false) {
return false;
}
// The image source does not exist, probably it has been deleted due to filter changes.
// storage component is going go try to re-create this image now.
$apply = Yii::$app->storage->createImage($this->getFileId(), $this->getFilterId());
}
$fileName = $this->getFilterId() . '_' . $this->getFile()->getSystemFileName();
return $scheme ? Yii::$app->storage->fileAbsoluteHttpPath($fileName) : Yii::$app->storage->fileHttpPath($fileName);
} | [
"public",
"function",
"getSource",
"(",
"$",
"scheme",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getFileExists",
"(",
")",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"storage",
"->",
"autoFixMissingImageSources",
"===",
"fals... | Get the source path to the image location on the webserver.
@param string $scheme Whether the source path should be absolute or not.
@return string|boolean | [
"Get",
"the",
"source",
"path",
"to",
"the",
"image",
"location",
"on",
"the",
"webserver",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/image/Item.php#L103-L118 | train |
luyadev/luya-module-admin | src/image/Item.php | Item.getServerSource | public function getServerSource()
{
return $this->getFile() ? Yii::$app->storage->fileServerPath($this->systemFileName) : false;
} | php | public function getServerSource()
{
return $this->getFile() ? Yii::$app->storage->fileServerPath($this->systemFileName) : false;
} | [
"public",
"function",
"getServerSource",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
")",
"?",
"Yii",
"::",
"$",
"app",
"->",
"storage",
"->",
"fileServerPath",
"(",
"$",
"this",
"->",
"systemFileName",
")",
":",
"false",
";",
"}"
] | The source to the image internal used on the Server.
@return string|boolean | [
"The",
"source",
"to",
"the",
"image",
"internal",
"used",
"on",
"the",
"Server",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/image/Item.php#L135-L138 | train |
luyadev/luya-module-admin | src/image/Item.php | Item.getFile | public function getFile()
{
if ($this->_file === null) {
$this->_file = Yii::$app->storage->getFile($this->getFileId());
}
return $this->_file;
} | php | public function getFile()
{
if ($this->_file === null) {
$this->_file = Yii::$app->storage->getFile($this->getFileId());
}
return $this->_file;
} | [
"public",
"function",
"getFile",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_file",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_file",
"=",
"Yii",
"::",
"$",
"app",
"->",
"storage",
"->",
"getFile",
"(",
"$",
"this",
"->",
"getFileId",
"(",
... | Get image depending file object where the image was create from, its like the original Source
@return \luya\admin\file\Item | [
"Get",
"image",
"depending",
"file",
"object",
"where",
"the",
"image",
"was",
"create",
"from",
"its",
"like",
"the",
"original",
"Source"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/image/Item.php#L185-L192 | train |
luyadev/luya-module-admin | src/image/Item.php | Item.applyFilter | public function applyFilter($filterName)
{
return ($filterItem = Yii::$app->storage->getFiltersArrayItem($filterName)) ? Yii::$app->storage->addImage($this->getFileId(), $filterItem['id'], !YII_ENV_PROD) : false;
} | php | public function applyFilter($filterName)
{
return ($filterItem = Yii::$app->storage->getFiltersArrayItem($filterName)) ? Yii::$app->storage->addImage($this->getFileId(), $filterItem['id'], !YII_ENV_PROD) : false;
} | [
"public",
"function",
"applyFilter",
"(",
"$",
"filterName",
")",
"{",
"return",
"(",
"$",
"filterItem",
"=",
"Yii",
"::",
"$",
"app",
"->",
"storage",
"->",
"getFiltersArrayItem",
"(",
"$",
"filterName",
")",
")",
"?",
"Yii",
"::",
"$",
"app",
"->",
"... | Apply a new filter for the original ussed file and return the new created image object.
@param string $filterName The name of a filter like `tiny-thumbnail` or a custom filter you have defined in your filters list.
@return boolean|\luya\admin\image\Item Returns boolean or image item object if its found. | [
"Apply",
"a",
"new",
"filter",
"for",
"the",
"original",
"ussed",
"file",
"and",
"return",
"the",
"new",
"created",
"image",
"object",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/image/Item.php#L200-L203 | train |
luyadev/luya-module-admin | src/ngrest/base/NgRestEventBehavior.php | NgRestEventBehavior.bindPluginEvents | public function bindPluginEvents(Event $event)
{
foreach ($this->plugins as $field => $plugin) {
$plugin = self::findPluginInstance($field, $plugin, $event->sender->tableName());
foreach ($plugin->events() as $on => $handler) {
$event->sender->on($on, is_string($handler) ? [$plugin, $handler] : $handler);
}
}
} | php | public function bindPluginEvents(Event $event)
{
foreach ($this->plugins as $field => $plugin) {
$plugin = self::findPluginInstance($field, $plugin, $event->sender->tableName());
foreach ($plugin->events() as $on => $handler) {
$event->sender->on($on, is_string($handler) ? [$plugin, $handler] : $handler);
}
}
} | [
"public",
"function",
"bindPluginEvents",
"(",
"Event",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"plugins",
"as",
"$",
"field",
"=>",
"$",
"plugin",
")",
"{",
"$",
"plugin",
"=",
"self",
"::",
"findPluginInstance",
"(",
"$",
"field",
... | Bing all plugin Events to the corresponding Owner Object.
@param \yii\base\Event $event | [
"Bing",
"all",
"plugin",
"Events",
"to",
"the",
"corresponding",
"Owner",
"Object",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/NgRestEventBehavior.php#L39-L47 | train |
luyadev/luya-module-admin | src/ngrest/base/NgRestEventBehavior.php | NgRestEventBehavior.findPluginInstance | private static function findPluginInstance($field, array $plugin, $tableName)
{
if (!isset(self::$_pluginInstances[$tableName][$field])) {
self::$_pluginInstances[$tableName][$field] = NgRest::createPluginObject($plugin['type']['class'], $plugin['name'], $plugin['alias'], $plugin['i18n'], $plugin['type']['args']);
}
return self::$_pluginInstances[$tableName][$field];
} | php | private static function findPluginInstance($field, array $plugin, $tableName)
{
if (!isset(self::$_pluginInstances[$tableName][$field])) {
self::$_pluginInstances[$tableName][$field] = NgRest::createPluginObject($plugin['type']['class'], $plugin['name'], $plugin['alias'], $plugin['i18n'], $plugin['type']['args']);
}
return self::$_pluginInstances[$tableName][$field];
} | [
"private",
"static",
"function",
"findPluginInstance",
"(",
"$",
"field",
",",
"array",
"$",
"plugin",
",",
"$",
"tableName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_pluginInstances",
"[",
"$",
"tableName",
"]",
"[",
"$",
"field",
... | Singleton Container for Plugin Objects.
@param string $field
@param array $plugin
@param string $tableName
@return \luya\admin\ngrest\base\Plugin | [
"Singleton",
"Container",
"for",
"Plugin",
"Objects",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/NgRestEventBehavior.php#L57-L64 | train |
luyadev/luya-module-admin | src/traits/TaggableTrait.php | TaggableTrait.getTags | public function getTags()
{
return $this->hasMany(Tag::class, ['id' => 'tag_id'])->viaTable('{{%admin_tag_relation}}', ['pk_id' => 'id'], function ($query) {
$query->andWhere(['table_name' => static::cleanBaseTableName(static::tableName())]);
});
} | php | public function getTags()
{
return $this->hasMany(Tag::class, ['id' => 'tag_id'])->viaTable('{{%admin_tag_relation}}', ['pk_id' => 'id'], function ($query) {
$query->andWhere(['table_name' => static::cleanBaseTableName(static::tableName())]);
});
} | [
"public",
"function",
"getTags",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"hasMany",
"(",
"Tag",
"::",
"class",
",",
"[",
"'id'",
"=>",
"'tag_id'",
"]",
")",
"->",
"viaTable",
"(",
"'{{%admin_tag_relation}}'",
",",
"[",
"'pk_id'",
"=>",
"'id'",
"]",
... | Returns all related tag for the current active record item.
@return \luya\admin\models\Tag An active record array from tag models | [
"Returns",
"all",
"related",
"tag",
"for",
"the",
"current",
"active",
"record",
"item",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/traits/TaggableTrait.php#L44-L49 | train |
luyadev/luya-module-admin | src/ngrest/base/NgRestActiveQuery.php | NgRestActiveQuery.i18nWhere | public function i18nWhere($field, $value)
{
$lang = Yii::$app->composition->langShortCode;
return $this->andWhere(["JSON_EXTRACT({$field}, \"$.{$lang}\")" => $value]);
} | php | public function i18nWhere($field, $value)
{
$lang = Yii::$app->composition->langShortCode;
return $this->andWhere(["JSON_EXTRACT({$field}, \"$.{$lang}\")" => $value]);
} | [
"public",
"function",
"i18nWhere",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"$",
"lang",
"=",
"Yii",
"::",
"$",
"app",
"->",
"composition",
"->",
"langShortCode",
";",
"return",
"$",
"this",
"->",
"andWhere",
"(",
"[",
"\"JSON_EXTRACT({$field}, \\\"... | Very basic where condition for i18n fields which use mysql's JSON_EXTRACT function.
This method allows very basic where condition for NgRest model fiels which are cased as {{luya\admin\ngrest\base\NgRestModel::$i18n}}.
Assuming your ngrest model has an i18n field:
```php
class MyModel extends NgRestModel
{
public $i18n = ['slug', 'name'];
}
```
The value for slug will be stored as json in the database, an example record for slug could look like `{"en":"english-slug","de":"german-slug"}`.
In order to perform where conditions with the json fields you can use {{i18nWhere}}. The above example where condition could be:
```php
$model = MyModel::find()->i18nWhere('slug', 'german-slug')->one();
```
> Keep in mind this only works with mysql version 5.7 and above.
@param string $field The field (attribute) name which is cased with {{luya\admin\ngrest\base\NgRestModel::$i18n}}
@param string $value The value to compare within the json string.
@return NgRestActiveQuery | [
"Very",
"basic",
"where",
"condition",
"for",
"i18n",
"fields",
"which",
"use",
"mysql",
"s",
"JSON_EXTRACT",
"function",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/NgRestActiveQuery.php#L46-L50 | train |
luyadev/luya-module-admin | src/ngrest/base/NgRestActiveQuery.php | NgRestActiveQuery.inPool | public function inPool($pool = null)
{
if (empty($pool)) {
return $this;
}
$model = Yii::createObject($this->modelClass);
if (!array_key_exists($pool, $model->ngRestPools())) {
throw new InvalidConfigException("The requested pool identifier '{$pool}' does not exist in the ngRestPools() definition.");
}
return $this->andWhere($model->ngRestPools()[$pool]);
} | php | public function inPool($pool = null)
{
if (empty($pool)) {
return $this;
}
$model = Yii::createObject($this->modelClass);
if (!array_key_exists($pool, $model->ngRestPools())) {
throw new InvalidConfigException("The requested pool identifier '{$pool}' does not exist in the ngRestPools() definition.");
}
return $this->andWhere($model->ngRestPools()[$pool]);
} | [
"public",
"function",
"inPool",
"(",
"$",
"pool",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"pool",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"model",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"this",
"->",
"modelClass",
"... | Add the pool where condition if a pool is given.
@param string $pool
@return NgRestActiveQuery
@since 2.0.0 | [
"Add",
"the",
"pool",
"where",
"condition",
"if",
"a",
"pool",
"is",
"given",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/NgRestActiveQuery.php#L74-L86 | train |
luyadev/luya-module-admin | src/ngrest/ConfigBuilder.php | ConfigBuilder.addPlugin | public function addPlugin($name, array $args)
{
$plugin = ['class' => $name, 'args' => $args];
$this->config[$this->pointer][$this->field]['type'] = $plugin;
return $this;
} | php | public function addPlugin($name, array $args)
{
$plugin = ['class' => $name, 'args' => $args];
$this->config[$this->pointer][$this->field]['type'] = $plugin;
return $this;
} | [
"public",
"function",
"addPlugin",
"(",
"$",
"name",
",",
"array",
"$",
"args",
")",
"{",
"$",
"plugin",
"=",
"[",
"'class'",
"=>",
"$",
"name",
",",
"'args'",
"=>",
"$",
"args",
"]",
";",
"$",
"this",
"->",
"config",
"[",
"$",
"this",
"->",
"poi... | Add a Plugin to the current field pointer plugins array.
@param string $name The name of the ngrest\plugin
@param array $args
@return \luya\admin\ngrest\ConfigBuilder
@since 1.0.0 | [
"Add",
"a",
"Plugin",
"to",
"the",
"current",
"field",
"pointer",
"plugins",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/ConfigBuilder.php#L124-L130 | train |
luyadev/luya-module-admin | src/ngrest/ConfigBuilder.php | ConfigBuilder.field | public function field($name, $alias = null, $i18n = false)
{
$this->config[$this->pointer][$name] = [
'name' => $name,
'i18n' => $i18n,
'alias' => (is_null($alias)) ? $name : $alias,
'type' => null,
'extraField' => false,
];
$this->field = $name;
return $this;
} | php | public function field($name, $alias = null, $i18n = false)
{
$this->config[$this->pointer][$name] = [
'name' => $name,
'i18n' => $i18n,
'alias' => (is_null($alias)) ? $name : $alias,
'type' => null,
'extraField' => false,
];
$this->field = $name;
return $this;
} | [
"public",
"function",
"field",
"(",
"$",
"name",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"i18n",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"$",
"this",
"->",
"pointer",
"]",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$"... | Define a field.
@param string $name
@param string $alias
@param boolean $i18n
@return \luya\admin\ngrest\ConfigBuilder | [
"Define",
"a",
"field",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/ConfigBuilder.php#L140-L153 | train |
luyadev/luya-module-admin | src/ngrest/ConfigBuilder.php | ConfigBuilder.load | public function load($objectType)
{
if ($this->pointer !== 'aw') {
throw new Exception('Register method can only be used in a pointer context.');
}
$object = Yii::createObject($objectType);
if (is_string($objectType)) {
$config['class'] = $objectType;
} else {
$config = $objectType;
}
$config['ngRestModelClass'] = $this->ngRestModelClass;
$this->config[$this->pointer][$object->getHashName()] = [
'objectConfig' => $config,
'label' => $object->getLabel(),
'icon' => $object->getIcon(),
];
return $this;
} | php | public function load($objectType)
{
if ($this->pointer !== 'aw') {
throw new Exception('Register method can only be used in a pointer context.');
}
$object = Yii::createObject($objectType);
if (is_string($objectType)) {
$config['class'] = $objectType;
} else {
$config = $objectType;
}
$config['ngRestModelClass'] = $this->ngRestModelClass;
$this->config[$this->pointer][$object->getHashName()] = [
'objectConfig' => $config,
'label' => $object->getLabel(),
'icon' => $object->getIcon(),
];
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"objectType",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pointer",
"!==",
"'aw'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Register method can only be used in a pointer context.'",
")",
";",
"}",
"$",
"object",
"=",
... | Creates a new active window object using the given configuration.
Below are some usage examples:
```php
// create an object using a class name
load('app\modules\foobar\test\MyActiveWindow');
// create an object using a configuration array
load([
'class' => 'app\modules\foobar\test\MyActiveWindow',
'property1' => 'value for property 1'
]);
```
@param string|array $objectType the object type. This can be specified in one of the following forms:
+ a string: representing the class name of the object to be created
+ a configuration array: the array must contain a `class` element which is treated as the object class,
and the rest of the name-value pairs will be used to initialize the corresponding object properties
@return $this
@throws Exception
@since 1.0.0 | [
"Creates",
"a",
"new",
"active",
"window",
"object",
"using",
"the",
"given",
"configuration",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/ConfigBuilder.php#L198-L221 | train |
luyadev/luya-module-admin | src/ngrest/ConfigBuilder.php | ConfigBuilder.copyFrom | public function copyFrom($key, $removeFields = [])
{
$temp = $this->config[$key];
foreach ($removeFields as $name) {
if (array_key_exists($name, $temp)) {
unset($temp[$name]);
}
}
$this->config[$this->pointer] = ArrayHelper::merge($this->config[$this->pointer], $temp);
} | php | public function copyFrom($key, $removeFields = [])
{
$temp = $this->config[$key];
foreach ($removeFields as $name) {
if (array_key_exists($name, $temp)) {
unset($temp[$name]);
}
}
$this->config[$this->pointer] = ArrayHelper::merge($this->config[$this->pointer], $temp);
} | [
"public",
"function",
"copyFrom",
"(",
"$",
"key",
",",
"$",
"removeFields",
"=",
"[",
"]",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
";",
"foreach",
"(",
"$",
"removeFields",
"as",
"$",
"name",
")",
"{",
"if"... | Copy from a pointer into another with optional removal of fields, the copie will applied
to the current active pointer.
@param string $key The pointer to copy from
@param array $removeFields | [
"Copy",
"from",
"a",
"pointer",
"into",
"another",
"with",
"optional",
"removal",
"of",
"fields",
"the",
"copie",
"will",
"applied",
"to",
"the",
"current",
"active",
"pointer",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/ConfigBuilder.php#L230-L240 | train |
luyadev/luya-module-admin | src/ngrest/plugins/CheckboxRelation.php | CheckboxRelation.getModel | public function getModel()
{
if (!is_object($this->_model)) {
$this->_model = Yii::createObject(['class' => $this->_model]);
}
return $this->_model;
} | php | public function getModel()
{
if (!is_object($this->_model)) {
$this->_model = Yii::createObject(['class' => $this->_model]);
}
return $this->_model;
} | [
"public",
"function",
"getModel",
"(",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"_model",
")",
")",
"{",
"$",
"this",
"->",
"_model",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"$",
"this",
"->",
"_model",
"]... | Getter method for model.
@return \yii\base\Model | [
"Getter",
"method",
"for",
"model",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/plugins/CheckboxRelation.php#L164-L171 | train |
luyadev/luya-module-admin | src/ngrest/plugins/CheckboxRelation.php | CheckboxRelation.getOptionsData | private function getOptionsData($event)
{
$items = [];
foreach ($this->model->find()->asArray($this->asArray)->all() as $item) {
if (is_callable($this->labelField, false)) {
$label = call_user_func($this->labelField, $item);
} else {
if ($this->labelField === null) {
$this->labelField = array_keys($item);
}
$array = ArrayHelper::filter($item, $this->labelField);
foreach ($array as $key => $value) {
if ($event->sender->isI18n($key)) {
$array[$key] = I18n::decodeFindActive($value);
}
}
$label = $this->labelTemplate ? vsprintf($this->labelTemplate, $array) : implode(', ', $array);
}
$items[] = ['value' => (int) $item[$this->modelPrimaryKey], 'label' => $label];
}
return ['items' => $items];
} | php | private function getOptionsData($event)
{
$items = [];
foreach ($this->model->find()->asArray($this->asArray)->all() as $item) {
if (is_callable($this->labelField, false)) {
$label = call_user_func($this->labelField, $item);
} else {
if ($this->labelField === null) {
$this->labelField = array_keys($item);
}
$array = ArrayHelper::filter($item, $this->labelField);
foreach ($array as $key => $value) {
if ($event->sender->isI18n($key)) {
$array[$key] = I18n::decodeFindActive($value);
}
}
$label = $this->labelTemplate ? vsprintf($this->labelTemplate, $array) : implode(', ', $array);
}
$items[] = ['value' => (int) $item[$this->modelPrimaryKey], 'label' => $label];
}
return ['items' => $items];
} | [
"private",
"function",
"getOptionsData",
"(",
"$",
"event",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
")",
"->",
"asArray",
"(",
"$",
"this",
"->",
"asArray",
")",
"->",
"all",
"(",
... | Get the options data to display.
@return array | [
"Get",
"the",
"options",
"data",
"to",
"display",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/plugins/CheckboxRelation.php#L205-L231 | train |
luyadev/luya-module-admin | src/ngrest/plugins/CheckboxRelation.php | CheckboxRelation.setRelation | protected function setRelation(array $value, $viaTableName, $localTableId, $foreignTableId, $activeRecordId)
{
Yii::$app->db->createCommand()->delete($viaTableName, [$localTableId => $activeRecordId])->execute();
$batch = [];
foreach ($value as $k => $v) {
// $this->id: the value of the current database model, example when relation ins on user model id would be user id
// $v['id'] extra field values foreached from the join table, so id will represent the joined table pk.
// issue #696 array logic
if (is_array($v)) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6
if (isset($v['value'])) {
$batch[] = [$activeRecordId, $v['value']];
}
} else { // its not an array so it could have been assigned from the frontend
$batch[] = [$activeRecordId, $v];
}
}
if (!empty($batch)) {
Yii::$app->db->createCommand()->batchInsert($viaTableName, [$localTableId, $foreignTableId], $batch)->execute();
}
return true;
} | php | protected function setRelation(array $value, $viaTableName, $localTableId, $foreignTableId, $activeRecordId)
{
Yii::$app->db->createCommand()->delete($viaTableName, [$localTableId => $activeRecordId])->execute();
$batch = [];
foreach ($value as $k => $v) {
// $this->id: the value of the current database model, example when relation ins on user model id would be user id
// $v['id'] extra field values foreached from the join table, so id will represent the joined table pk.
// issue #696 array logic
if (is_array($v)) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6
if (isset($v['value'])) {
$batch[] = [$activeRecordId, $v['value']];
}
} else { // its not an array so it could have been assigned from the frontend
$batch[] = [$activeRecordId, $v];
}
}
if (!empty($batch)) {
Yii::$app->db->createCommand()->batchInsert($viaTableName, [$localTableId, $foreignTableId], $batch)->execute();
}
return true;
} | [
"protected",
"function",
"setRelation",
"(",
"array",
"$",
"value",
",",
"$",
"viaTableName",
",",
"$",
"localTableId",
",",
"$",
"foreignTableId",
",",
"$",
"activeRecordId",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
")",
... | Set the relation data based on the configuration.
@param array $value The valued which is provided from the setter method
@param string $viaTableName Example viaTable name: news_article_tag
@param string $localTableId The name of the field inside the viaTable which represents the match against the local table, example: article_id
@param string $foreignTableId The name of the field inside the viaTable which represents the match against the foreign table, example: tag_id
@return boolean Whether updating the database was successfull or not. | [
"Set",
"the",
"relation",
"data",
"based",
"on",
"the",
"configuration",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/plugins/CheckboxRelation.php#L305-L326 | train |
luyadev/luya-module-admin | src/behaviors/LogBehavior.php | LogBehavior.getUserId | protected function getUserId()
{
if (Yii::$app->has('adminuser') && Yii::$app->adminuser->getIdentity()) {
return Yii::$app->adminuser->id;
}
return 0;
} | php | protected function getUserId()
{
if (Yii::$app->has('adminuser') && Yii::$app->adminuser->getIdentity()) {
return Yii::$app->adminuser->id;
}
return 0;
} | [
"protected",
"function",
"getUserId",
"(",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"has",
"(",
"'adminuser'",
")",
"&&",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"getIdentity",
"(",
")",
")",
"{",
"return",
"Yii",
"::",
"$",
"a... | Returns the user id for the current admin user if logged in and component is existsi.
@return integer
@since 1.2.3 | [
"Returns",
"the",
"user",
"id",
"for",
"the",
"current",
"admin",
"user",
"if",
"logged",
"in",
"and",
"component",
"is",
"existsi",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/behaviors/LogBehavior.php#L54-L61 | train |
luyadev/luya-module-admin | src/behaviors/LogBehavior.php | LogBehavior.isLoggable | protected function isLoggable()
{
if (Yii::$app instanceof Application && Yii::$app->hasModule('admin') && Yii::$app->has('adminuser')) {
return true;
}
return false;
} | php | protected function isLoggable()
{
if (Yii::$app instanceof Application && Yii::$app->hasModule('admin') && Yii::$app->has('adminuser')) {
return true;
}
return false;
} | [
"protected",
"function",
"isLoggable",
"(",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"instanceof",
"Application",
"&&",
"Yii",
"::",
"$",
"app",
"->",
"hasModule",
"(",
"'admin'",
")",
"&&",
"Yii",
"::",
"$",
"app",
"->",
"has",
"(",
"'adminuser'"... | Method to ensure whether the current log process should be run or not as log behavior can also be attached
the very universal models.
@return boolean
@since 1.2.3 | [
"Method",
"to",
"ensure",
"whether",
"the",
"current",
"log",
"process",
"should",
"be",
"run",
"or",
"not",
"as",
"log",
"behavior",
"can",
"also",
"be",
"attached",
"the",
"very",
"universal",
"models",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/behaviors/LogBehavior.php#L70-L77 | train |
luyadev/luya-module-admin | src/behaviors/LogBehavior.php | LogBehavior.eventAfterDelete | public function eventAfterDelete($event)
{
if ($this->isLoggable()) {
Yii::$app->db->createCommand()->insert('{{%admin_ngrest_log}}', [
'user_id' => $this->getUserId(),
'timestamp_create' => time(),
'route' => $this->route,
'api' => $this->api,
'is_insert' => false,
'is_update' => false,
'is_delete' => true,
'attributes_json' => $this->toJson($event->sender->getAttributes()),
'table_name' => $event->sender->tableName(),
'pk_value' => implode("-", $event->sender->getPrimaryKey(true)),
])->execute();
}
} | php | public function eventAfterDelete($event)
{
if ($this->isLoggable()) {
Yii::$app->db->createCommand()->insert('{{%admin_ngrest_log}}', [
'user_id' => $this->getUserId(),
'timestamp_create' => time(),
'route' => $this->route,
'api' => $this->api,
'is_insert' => false,
'is_update' => false,
'is_delete' => true,
'attributes_json' => $this->toJson($event->sender->getAttributes()),
'table_name' => $event->sender->tableName(),
'pk_value' => implode("-", $event->sender->getPrimaryKey(true)),
])->execute();
}
} | [
"public",
"function",
"eventAfterDelete",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLoggable",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"insert",
"(",
"'{{%admin_ngrest_log}}'",
... | After delete event.
@param \yii\base\Event $event | [
"After",
"delete",
"event",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/behaviors/LogBehavior.php#L84-L100 | train |
luyadev/luya-module-admin | src/controllers/LoginController.php | LoginController.actionIndex | public function actionIndex()
{
// redirect logged in users
if (!Yii::$app->adminuser->isGuest) {
return $this->redirect(['/admin/default/index']);
}
$this->registerAsset(Login::class);
$this->view->registerJs("$('#email').focus(); checkInputLabels();
observeLogin('#loginForm', '".Url::toAjax('admin/login/async')."', '".Url::toAjax('admin/login/async-token')."');
");
UserOnline::clearList($this->module->userIdleTimeout);
return $this->render('index');
} | php | public function actionIndex()
{
// redirect logged in users
if (!Yii::$app->adminuser->isGuest) {
return $this->redirect(['/admin/default/index']);
}
$this->registerAsset(Login::class);
$this->view->registerJs("$('#email').focus(); checkInputLabels();
observeLogin('#loginForm', '".Url::toAjax('admin/login/async')."', '".Url::toAjax('admin/login/async-token')."');
");
UserOnline::clearList($this->module->userIdleTimeout);
return $this->render('index');
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"// redirect logged in users",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"isGuest",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'/admin/default/index'",
"]",
")",
... | Login Form.
This action renders and display the login form.
+ Single sign in runs {{luya\admin\controllers\LoginController::actionAsync()}}.
+ 2FA calls {{luya\admin\controllers\LoginController::actionAsyncToken()}} afterwards.
@return \yii\web\Response|string | [
"Login",
"Form",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/controllers/LoginController.php#L74-L90 | train |
luyadev/luya-module-admin | src/controllers/LoginController.php | LoginController.actionAsync | public function actionAsync()
{
if (($lockout = $this->sessionBruteForceLock())) {
return $this->sendArray(false, [Module::t('login_async_submission_limit_reached', ['time' => Yii::$app->formatter->asRelativeTime($lockout)])]);
}
// get the login form model
$model = new LoginForm();
$model->allowedAttempts = $this->module->loginUserAttemptCount;
$model->lockoutTime = $this->module->loginUserAttemptLockoutTime;
$loginData = Yii::$app->request->post('login');
Yii::$app->session->remove('secureId');
// see if values are sent via post
if ($loginData) {
$model->attributes = $loginData;
if (($userObject = $model->login()) !== false) {
// see if secure login is enabled or not
if ($this->module->secureLogin) {
// try to send the secure token to the given user email store the token in the session.
if ($model->sendSecureLogin()) {
Yii::$app->session->set('secureId', $model->getUser()->id);
return $this->sendArray(false, [], true);
}
return $this->sendArray(false, ['Unable to send and store secure token.']);
}
if (Yii::$app->adminuser->login($userObject)) {
return $this->sendArray(true);
}
}
}
return $this->sendArray(false, $model->getErrors(), false);
} | php | public function actionAsync()
{
if (($lockout = $this->sessionBruteForceLock())) {
return $this->sendArray(false, [Module::t('login_async_submission_limit_reached', ['time' => Yii::$app->formatter->asRelativeTime($lockout)])]);
}
// get the login form model
$model = new LoginForm();
$model->allowedAttempts = $this->module->loginUserAttemptCount;
$model->lockoutTime = $this->module->loginUserAttemptLockoutTime;
$loginData = Yii::$app->request->post('login');
Yii::$app->session->remove('secureId');
// see if values are sent via post
if ($loginData) {
$model->attributes = $loginData;
if (($userObject = $model->login()) !== false) {
// see if secure login is enabled or not
if ($this->module->secureLogin) {
// try to send the secure token to the given user email store the token in the session.
if ($model->sendSecureLogin()) {
Yii::$app->session->set('secureId', $model->getUser()->id);
return $this->sendArray(false, [], true);
}
return $this->sendArray(false, ['Unable to send and store secure token.']);
}
if (Yii::$app->adminuser->login($userObject)) {
return $this->sendArray(true);
}
}
}
return $this->sendArray(false, $model->getErrors(), false);
} | [
"public",
"function",
"actionAsync",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"lockout",
"=",
"$",
"this",
"->",
"sessionBruteForceLock",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sendArray",
"(",
"false",
",",
"[",
"Module",
"::",
"t",
"(",
... | Async single sign in action.
This action is triggered by the async request from the login form.
If successfull and 2FA is enabled, a token will be stored and sent to the user's email.
@return array | [
"Async",
"single",
"sign",
"in",
"action",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/controllers/LoginController.php#L101-L136 | train |
luyadev/luya-module-admin | src/controllers/LoginController.php | LoginController.actionAsyncToken | public function actionAsyncToken()
{
if (($lockout = $this->sessionBruteForceLock())) {
return $this->sendArray(false, [Module::t('login_async_submission_limit_reached', ['time' => Yii::$app->formatter->asRelativeTime($lockout)])]);
}
$secureToken = Yii::$app->request->post('secure_token', false);
$model = new LoginForm();
$model->secureTokenExpirationTime = $this->module->secureTokenExpirationTime;
if ($secureToken) {
$user = $model->validateSecureToken($secureToken, Yii::$app->session->get('secureId'));
if ($user && Yii::$app->adminuser->login($user)) {
Yii::$app->session->remove('secureId');
return $this->sendArray(true);
}
return $this->sendArray(false, [Module::t('login_async_token_error')]);
}
return $this->sendArray(false, [Module::t('login_async_token_globalerror')]);
} | php | public function actionAsyncToken()
{
if (($lockout = $this->sessionBruteForceLock())) {
return $this->sendArray(false, [Module::t('login_async_submission_limit_reached', ['time' => Yii::$app->formatter->asRelativeTime($lockout)])]);
}
$secureToken = Yii::$app->request->post('secure_token', false);
$model = new LoginForm();
$model->secureTokenExpirationTime = $this->module->secureTokenExpirationTime;
if ($secureToken) {
$user = $model->validateSecureToken($secureToken, Yii::$app->session->get('secureId'));
if ($user && Yii::$app->adminuser->login($user)) {
Yii::$app->session->remove('secureId');
return $this->sendArray(true);
}
return $this->sendArray(false, [Module::t('login_async_token_error')]);
}
return $this->sendArray(false, [Module::t('login_async_token_globalerror')]);
} | [
"public",
"function",
"actionAsyncToken",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"lockout",
"=",
"$",
"this",
"->",
"sessionBruteForceLock",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sendArray",
"(",
"false",
",",
"[",
"Module",
"::",
"t",
... | Async Secure Token Login.
@return array | [
"Async",
"Secure",
"Token",
"Login",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/controllers/LoginController.php#L143-L166 | train |
luyadev/luya-module-admin | src/controllers/LoginController.php | LoginController.sendArray | private function sendArray($refresh, array $errors = [], $enterSecureToken = false, $message = null)
{
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'refresh' => $refresh,
'message' => $message,
'errors' => $errors,
'enterSecureToken' => $enterSecureToken,
'time' => time(),
];
} | php | private function sendArray($refresh, array $errors = [], $enterSecureToken = false, $message = null)
{
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'refresh' => $refresh,
'message' => $message,
'errors' => $errors,
'enterSecureToken' => $enterSecureToken,
'time' => time(),
];
} | [
"private",
"function",
"sendArray",
"(",
"$",
"refresh",
",",
"array",
"$",
"errors",
"=",
"[",
"]",
",",
"$",
"enterSecureToken",
"=",
"false",
",",
"$",
"message",
"=",
"null",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"format",
"=... | Change the response format to json and return the array.
@param boolean $refresh
@param array $errors
@param boolean $enterSecureToken
@param string $message
@return array | [
"Change",
"the",
"response",
"format",
"to",
"json",
"and",
"return",
"the",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/controllers/LoginController.php#L177-L188 | train |
luyadev/luya-module-admin | src/controllers/LoginController.php | LoginController.sessionBruteForceLock | private function sessionBruteForceLock()
{
$attempt = Yii::$app->session->get('__attempt_count', 0);
$counter = $attempt + 1;
Yii::$app->session->set('__attempt_count', $counter);
$lockout = Yii::$app->session->get('__attempt_lockout');
if ($lockout && $lockout > time()) {
Yii::$app->session->set('__attempt_count', 0);
return $lockout;
}
if ($counter >= $this->module->loginSessionAttemptCount) {
Yii::$app->session->set('__attempt_lockout', time() + $this->module->loginSessionAttemptLockoutTime);
}
return false;
} | php | private function sessionBruteForceLock()
{
$attempt = Yii::$app->session->get('__attempt_count', 0);
$counter = $attempt + 1;
Yii::$app->session->set('__attempt_count', $counter);
$lockout = Yii::$app->session->get('__attempt_lockout');
if ($lockout && $lockout > time()) {
Yii::$app->session->set('__attempt_count', 0);
return $lockout;
}
if ($counter >= $this->module->loginSessionAttemptCount) {
Yii::$app->session->set('__attempt_lockout', time() + $this->module->loginSessionAttemptLockoutTime);
}
return false;
} | [
"private",
"function",
"sessionBruteForceLock",
"(",
")",
"{",
"$",
"attempt",
"=",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"get",
"(",
"'__attempt_count'",
",",
"0",
")",
";",
"$",
"counter",
"=",
"$",
"attempt",
"+",
"1",
";",
"Yii",
"::",
... | Ensure current brute force attempt based on session.
@return boolean|integer
@since 1.2.0 | [
"Ensure",
"current",
"brute",
"force",
"attempt",
"based",
"on",
"session",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/controllers/LoginController.php#L196-L216 | train |
luyadev/luya-module-admin | src/ngrest/base/actions/DeleteAction.php | DeleteAction.run | public function run($id)
{
$model = $this->findModel($id);
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id, $model);
}
if ($model->delete() === false) {
// custom implementation of LUYA in order to throw more informations when delete errors happen.
if ($model->hasErrors()) {
Yii::$app->getResponse()->setStatusCode(422);
$errors = [];
foreach ($model->getErrors() as $field => $errorMessages) {
foreach ($errorMessages as $message) {
$errors[] = ['field' => $field, 'message' => $message];
}
}
return $errors;
}
throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
}
Yii::$app->getResponse()->setStatusCode(204);
} | php | public function run($id)
{
$model = $this->findModel($id);
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id, $model);
}
if ($model->delete() === false) {
// custom implementation of LUYA in order to throw more informations when delete errors happen.
if ($model->hasErrors()) {
Yii::$app->getResponse()->setStatusCode(422);
$errors = [];
foreach ($model->getErrors() as $field => $errorMessages) {
foreach ($errorMessages as $message) {
$errors[] = ['field' => $field, 'message' => $message];
}
}
return $errors;
}
throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
}
Yii::$app->getResponse()->setStatusCode(204);
} | [
"public",
"function",
"run",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkAccess",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"checkAccess",
",",... | Run the delete action with enhanced error checking methods.
@see \yii\rest\DeleteAction::run() | [
"Run",
"the",
"delete",
"action",
"with",
"enhanced",
"error",
"checking",
"methods",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/actions/DeleteAction.php#L25-L52 | train |
luyadev/luya-module-admin | src/importers/PropertyImporter.php | PropertyImporter.install | protected function install($object)
{
$model = Property::find()->where(['var_name' => $object->varName()])->one();
if ($model) {
$model->setAttributes([
'module_name' => $object->moduleName,
'class_name' => $object::className(),
]);
$model->update(false);
return $model->id;
} else {
$model = new Property();
$model->setAttributes([
'var_name' => $object->varName(),
'module_name' => $object->moduleName,
'class_name' => $object::className(),
]);
$insert = $model->insert(false);
if ($insert) {
return $model->id;
}
}
} | php | protected function install($object)
{
$model = Property::find()->where(['var_name' => $object->varName()])->one();
if ($model) {
$model->setAttributes([
'module_name' => $object->moduleName,
'class_name' => $object::className(),
]);
$model->update(false);
return $model->id;
} else {
$model = new Property();
$model->setAttributes([
'var_name' => $object->varName(),
'module_name' => $object->moduleName,
'class_name' => $object::className(),
]);
$insert = $model->insert(false);
if ($insert) {
return $model->id;
}
}
} | [
"protected",
"function",
"install",
"(",
"$",
"object",
")",
"{",
"$",
"model",
"=",
"Property",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'var_name'",
"=>",
"$",
"object",
"->",
"varName",
"(",
")",
"]",
")",
"->",
"one",
"(",
")",
";",
... | Installation of the property | [
"Installation",
"of",
"the",
"property"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/importers/PropertyImporter.php#L45-L68 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFilesArray | public function getFilesArray()
{
if ($this->_filesArray === null) {
$this->_filesArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_file}}')->select(['id', 'is_hidden', 'is_deleted', 'folder_id', 'name_original', 'name_new', 'name_new_compound', 'mime_type', 'extension', 'hash_name', 'hash_file', 'upload_timestamp', 'file_size', 'upload_user_id', 'caption'])->indexBy('id'), self::CACHE_KEY_FILE);
}
return $this->_filesArray;
} | php | public function getFilesArray()
{
if ($this->_filesArray === null) {
$this->_filesArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_file}}')->select(['id', 'is_hidden', 'is_deleted', 'folder_id', 'name_original', 'name_new', 'name_new_compound', 'mime_type', 'extension', 'hash_name', 'hash_file', 'upload_timestamp', 'file_size', 'upload_user_id', 'caption'])->indexBy('id'), self::CACHE_KEY_FILE);
}
return $this->_filesArray;
} | [
"public",
"function",
"getFilesArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_filesArray",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_filesArray",
"=",
"$",
"this",
"->",
"getQueryCacheHelper",
"(",
"(",
"new",
"Query",
"(",
")",
")",
"->",
... | Get all storage files as an array from database.
This method is used to retrieve all files from the database and indexed by file key.
@return array An array with all storage files indexed by the file id. | [
"Get",
"all",
"storage",
"files",
"as",
"an",
"array",
"from",
"database",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L290-L297 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFilesArrayItem | public function getFilesArrayItem($fileId)
{
return isset($this->filesArray[$fileId]) ? $this->filesArray[$fileId] : false;
} | php | public function getFilesArrayItem($fileId)
{
return isset($this->filesArray[$fileId]) ? $this->filesArray[$fileId] : false;
} | [
"public",
"function",
"getFilesArrayItem",
"(",
"$",
"fileId",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"filesArray",
"[",
"$",
"fileId",
"]",
")",
"?",
"$",
"this",
"->",
"filesArray",
"[",
"$",
"fileId",
"]",
":",
"false",
";",
"}"
] | Get a single file by file id from the files array.
@param integer $fileId The file id to find.
@return boolean|array The file array or false if not found. | [
"Get",
"a",
"single",
"file",
"by",
"file",
"id",
"from",
"the",
"files",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L317-L320 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getImagesArray | public function getImagesArray()
{
if ($this->_imagesArray === null) {
$this->_imagesArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_image}}')->select(['id', 'file_id', 'filter_id', 'resolution_width', 'resolution_height'])->indexBy('id'), self::CACHE_KEY_IMAGE);
}
return $this->_imagesArray;
} | php | public function getImagesArray()
{
if ($this->_imagesArray === null) {
$this->_imagesArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_image}}')->select(['id', 'file_id', 'filter_id', 'resolution_width', 'resolution_height'])->indexBy('id'), self::CACHE_KEY_IMAGE);
}
return $this->_imagesArray;
} | [
"public",
"function",
"getImagesArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_imagesArray",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_imagesArray",
"=",
"$",
"this",
"->",
"getQueryCacheHelper",
"(",
"(",
"new",
"Query",
"(",
")",
")",
"->... | Get all storage images as an array from database.
This method is used to retrieve all images from the database and indexed by image key.
@return array An array with all storage images indexed by the image id. | [
"Get",
"all",
"storage",
"images",
"as",
"an",
"array",
"from",
"database",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L331-L338 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getImagesArrayItem | public function getImagesArrayItem($imageId)
{
return isset($this->imagesArray[$imageId]) ? $this->imagesArray[$imageId] : false;
} | php | public function getImagesArrayItem($imageId)
{
return isset($this->imagesArray[$imageId]) ? $this->imagesArray[$imageId] : false;
} | [
"public",
"function",
"getImagesArrayItem",
"(",
"$",
"imageId",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"imagesArray",
"[",
"$",
"imageId",
"]",
")",
"?",
"$",
"this",
"->",
"imagesArray",
"[",
"$",
"imageId",
"]",
":",
"false",
";",
"}"
... | Get a single image by image id from the files array.
@param integer $imageId The image id to find.
@return boolean|array The image array or false if not found. | [
"Get",
"a",
"single",
"image",
"by",
"image",
"id",
"from",
"the",
"files",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L358-L361 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.ensureFileUpload | public function ensureFileUpload($fileSource, $fileName)
{
// throw exception if source or name is empty
if (empty($fileSource) || empty($fileName)) {
throw new Exception("Filename and source can not be empty.");
}
// if filename is blob, its a paste event from the browser, therefore generate the filename from the file source.
// @TODO: move out of ensureFileUpload
if ($fileName == 'blob') {
$ext = FileHelper::getExtensionsByMimeType(FileHelper::getMimeType($fileSource));
$fileName = 'paste-'.date("Y-m-d-H-i").'.'.$ext[0];
}
// get file informations from the name
$fileInfo = FileHelper::getFileInfo($fileName);
// get the mimeType from the fileSource, if $secureFileUpload is disabled, the mime type will be extracted from the file extensions
// instead of using the fileinfo extension, therefore this is not recommend.
$mimeType = FileHelper::getMimeType($fileSource, null, !$this->secureFileUpload);
// empty mime type indicates a wrong file upload.
if (empty($mimeType)) {
throw new Exception("Unable to find mimeType for the given file, make sure the php extension 'fileinfo' is installed.");
}
$extensionsFromMimeType = FileHelper::getExtensionsByMimeType($mimeType);
if (empty($extensionsFromMimeType) && empty($this->whitelistExtensions)) {
throw new Exception("Unable to find extension for given mimeType \"{$mimeType}\" or it contains insecure data.");
}
if (!empty($this->whitelistExtensions)) {
$extensionsFromMimeType = array_merge($extensionsFromMimeType, $this->whitelistExtensions);
}
// check if the file extension is matching the entries from FileHelper::getExtensionsByMimeType array.
if (!in_array($fileInfo->extension, $extensionsFromMimeType) && !in_array($mimeType, $this->whitelistMimeTypes)) {
throw new Exception("The given file extension \"{$fileInfo->extension}\" for file with mimeType \"{$mimeType}\" is not matching any valid extension: ".VarDumper::dumpAsString($extensionsFromMimeType).".");
}
foreach ($extensionsFromMimeType as $extension) {
if (in_array($extension, $this->dangerousExtensions)) {
throw new Exception("The file extension '{$extension}' seems to be dangerous and can not be stored.");
}
}
// check whether a mimetype is in the dangerousMimeTypes list and not whitelisted in whitelistMimeTypes.
if (in_array($mimeType, $this->dangerousMimeTypes) && !in_array($mimeType, $this->whitelistMimeTypes)) {
throw new Exception("The file mimeType '{$mimeType}' seems to be dangerous and can not be stored.");
}
return [
'fileInfo' => $fileInfo,
'mimeType' => $mimeType,
'fileName' => $fileName,
'secureFileName' => Inflector::slug(str_replace('_', '-', $fileInfo->name), '-'),
'fileSource' => $fileSource,
'fileSize' => filesize($fileSource),
'extension' => $fileInfo->extension,
'hashName' => FileHelper::hashName($fileName),
];
} | php | public function ensureFileUpload($fileSource, $fileName)
{
// throw exception if source or name is empty
if (empty($fileSource) || empty($fileName)) {
throw new Exception("Filename and source can not be empty.");
}
// if filename is blob, its a paste event from the browser, therefore generate the filename from the file source.
// @TODO: move out of ensureFileUpload
if ($fileName == 'blob') {
$ext = FileHelper::getExtensionsByMimeType(FileHelper::getMimeType($fileSource));
$fileName = 'paste-'.date("Y-m-d-H-i").'.'.$ext[0];
}
// get file informations from the name
$fileInfo = FileHelper::getFileInfo($fileName);
// get the mimeType from the fileSource, if $secureFileUpload is disabled, the mime type will be extracted from the file extensions
// instead of using the fileinfo extension, therefore this is not recommend.
$mimeType = FileHelper::getMimeType($fileSource, null, !$this->secureFileUpload);
// empty mime type indicates a wrong file upload.
if (empty($mimeType)) {
throw new Exception("Unable to find mimeType for the given file, make sure the php extension 'fileinfo' is installed.");
}
$extensionsFromMimeType = FileHelper::getExtensionsByMimeType($mimeType);
if (empty($extensionsFromMimeType) && empty($this->whitelistExtensions)) {
throw new Exception("Unable to find extension for given mimeType \"{$mimeType}\" or it contains insecure data.");
}
if (!empty($this->whitelistExtensions)) {
$extensionsFromMimeType = array_merge($extensionsFromMimeType, $this->whitelistExtensions);
}
// check if the file extension is matching the entries from FileHelper::getExtensionsByMimeType array.
if (!in_array($fileInfo->extension, $extensionsFromMimeType) && !in_array($mimeType, $this->whitelistMimeTypes)) {
throw new Exception("The given file extension \"{$fileInfo->extension}\" for file with mimeType \"{$mimeType}\" is not matching any valid extension: ".VarDumper::dumpAsString($extensionsFromMimeType).".");
}
foreach ($extensionsFromMimeType as $extension) {
if (in_array($extension, $this->dangerousExtensions)) {
throw new Exception("The file extension '{$extension}' seems to be dangerous and can not be stored.");
}
}
// check whether a mimetype is in the dangerousMimeTypes list and not whitelisted in whitelistMimeTypes.
if (in_array($mimeType, $this->dangerousMimeTypes) && !in_array($mimeType, $this->whitelistMimeTypes)) {
throw new Exception("The file mimeType '{$mimeType}' seems to be dangerous and can not be stored.");
}
return [
'fileInfo' => $fileInfo,
'mimeType' => $mimeType,
'fileName' => $fileName,
'secureFileName' => Inflector::slug(str_replace('_', '-', $fileInfo->name), '-'),
'fileSource' => $fileSource,
'fileSize' => filesize($fileSource),
'extension' => $fileInfo->extension,
'hashName' => FileHelper::hashName($fileName),
];
} | [
"public",
"function",
"ensureFileUpload",
"(",
"$",
"fileSource",
",",
"$",
"fileName",
")",
"{",
"// throw exception if source or name is empty",
"if",
"(",
"empty",
"(",
"$",
"fileSource",
")",
"||",
"empty",
"(",
"$",
"fileName",
")",
")",
"{",
"throw",
"ne... | Ensure a file uploads and return relevant file infos.
@param string $fileSource The file on the server ($_FILES['tmp'])
@param string $fileName Original upload name of the file ($_FILES['name'])
@throws Exception
@return array Returns an array with the following KeywordPatch
+ fileInfo:
+ mimeType:
+ fileName:
+ secureFileName: The file name with all insecure chars removed
+ fileSource:
+ extension: jpg, png, etc.
+ hashName: a short hash name for the given file, not the md5 sum. | [
"Ensure",
"a",
"file",
"uploads",
"and",
"return",
"relevant",
"file",
"infos",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L421-L479 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.addFile | public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
{
$fileData = $this->ensureFileUpload($fileSource, $fileName);
$fileHash = FileHelper::md5sum($fileSource);
$newName = implode([$fileData['secureFileName'].'_'.$fileData['hashName'], $fileData['extension']], '.');
if (!$this->fileSystemSaveFile($fileSource, $newName)) {
return false;
}
$model = new StorageFile();
$model->setAttributes([
'name_original' => $fileName,
'name_new' => $fileData['secureFileName'],
'name_new_compound' => $newName,
'mime_type' => $fileData['mimeType'],
'extension' => $fileData['extension'],
'folder_id' => (int) $folderId,
'hash_file' => $fileHash,
'hash_name' => $fileData['hashName'],
'is_hidden' => $isHidden ? true : false,
'is_deleted' => false,
'file_size' => $fileData['fileSize'],
'caption' => null,
]);
if ($model->validate()) {
if ($model->save()) {
$this->deleteHasCache(self::CACHE_KEY_FILE);
$this->_filesArray[$model->id] = $model->toArray();
return $this->getFile($model->id);
}
}
return false;
} | php | public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
{
$fileData = $this->ensureFileUpload($fileSource, $fileName);
$fileHash = FileHelper::md5sum($fileSource);
$newName = implode([$fileData['secureFileName'].'_'.$fileData['hashName'], $fileData['extension']], '.');
if (!$this->fileSystemSaveFile($fileSource, $newName)) {
return false;
}
$model = new StorageFile();
$model->setAttributes([
'name_original' => $fileName,
'name_new' => $fileData['secureFileName'],
'name_new_compound' => $newName,
'mime_type' => $fileData['mimeType'],
'extension' => $fileData['extension'],
'folder_id' => (int) $folderId,
'hash_file' => $fileHash,
'hash_name' => $fileData['hashName'],
'is_hidden' => $isHidden ? true : false,
'is_deleted' => false,
'file_size' => $fileData['fileSize'],
'caption' => null,
]);
if ($model->validate()) {
if ($model->save()) {
$this->deleteHasCache(self::CACHE_KEY_FILE);
$this->_filesArray[$model->id] = $model->toArray();
return $this->getFile($model->id);
}
}
return false;
} | [
"public",
"function",
"addFile",
"(",
"$",
"fileSource",
",",
"$",
"fileName",
",",
"$",
"folderId",
"=",
"0",
",",
"$",
"isHidden",
"=",
"false",
")",
"{",
"$",
"fileData",
"=",
"$",
"this",
"->",
"ensureFileUpload",
"(",
"$",
"fileSource",
",",
"$",
... | Add a new file based on the source to the storage system.
When using the $_FILES array you can also make usage of the file helper methods:
+ {{luya\admin\helpers\Storage::uploadFromFiles}}
+ {{luya\admin\helpers\Storage::uploadFromFileArray}}
When not using the $_FILES array:
```php
Yii::$app->storage->addFile('/the/path/to/File.jpg', 'File.jpg', 0, 1);
```
@param string $fileSource Path to the file source where the file should be created from
@param string $fileName The name of this file (must contain data type suffix).
@param integer $folderId The id of the folder where the file should be stored in.
@param boolean $isHidden Should the file visible in the filemanager or not.
@return bool|\luya\admin\file\Item|Exception Returns the item object, if an error happens an exception is thrown.
@throws Exception | [
"Add",
"a",
"new",
"file",
"based",
"on",
"the",
"source",
"to",
"the",
"storage",
"system",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L502-L538 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.addImage | public function addImage($fileId, $filterId = 0, $throwException = false)
{
try {
// if the filterId is provded as a string the filter will be looked up by its name in the get filters array list.
if (is_string($filterId) && !is_numeric($filterId)) {
$filterLookup = $this->getFiltersArrayItem($filterId);
if (!$filterLookup) {
throw new Exception("The provided filter name " . $filterId . " does not exist.");
}
$filterId = $filterLookup['id'];
}
$query = (new \luya\admin\image\Query())->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
if ($query && $query->fileExists) {
return $query;
}
$fileQuery = $this->getFile($fileId);
if (!$fileQuery || !$fileQuery->fileExists) {
if ($fileQuery !== false) {
throw new Exception("Unable to create image, the base file server source '{$fileQuery->serverSource}' does not exist.");
}
throw new Exception("Unable to find the file with id '{$fileId}', image can not be created.");
}
$model = $this->createImage($fileId, $filterId);
if (!$model) {
throw new Exception("Unable to create the image on the filesystem.");
}
$this->_imagesArray[$model->id] = $model->toArray();
$this->deleteHasCache(self::CACHE_KEY_IMAGE);
return $this->getImage($model->id);
} catch (\Exception $err) {
if ($throwException) {
throw $err;
}
}
return false;
} | php | public function addImage($fileId, $filterId = 0, $throwException = false)
{
try {
// if the filterId is provded as a string the filter will be looked up by its name in the get filters array list.
if (is_string($filterId) && !is_numeric($filterId)) {
$filterLookup = $this->getFiltersArrayItem($filterId);
if (!$filterLookup) {
throw new Exception("The provided filter name " . $filterId . " does not exist.");
}
$filterId = $filterLookup['id'];
}
$query = (new \luya\admin\image\Query())->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
if ($query && $query->fileExists) {
return $query;
}
$fileQuery = $this->getFile($fileId);
if (!$fileQuery || !$fileQuery->fileExists) {
if ($fileQuery !== false) {
throw new Exception("Unable to create image, the base file server source '{$fileQuery->serverSource}' does not exist.");
}
throw new Exception("Unable to find the file with id '{$fileId}', image can not be created.");
}
$model = $this->createImage($fileId, $filterId);
if (!$model) {
throw new Exception("Unable to create the image on the filesystem.");
}
$this->_imagesArray[$model->id] = $model->toArray();
$this->deleteHasCache(self::CACHE_KEY_IMAGE);
return $this->getImage($model->id);
} catch (\Exception $err) {
if ($throwException) {
throw $err;
}
}
return false;
} | [
"public",
"function",
"addImage",
"(",
"$",
"fileId",
",",
"$",
"filterId",
"=",
"0",
",",
"$",
"throwException",
"=",
"false",
")",
"{",
"try",
"{",
"// if the filterId is provded as a string the filter will be looked up by its name in the get filters array list.",
"if",
... | Add a new image based an existing file Id.
The storage system uses the same file base, for images and files. The difference between a file and an image is the filter which is applied.
Only files of the type image can be used (or added) as an image.
An image object is always based on the {{\luya\admin\file\Item}} object and a {{luya\admin\base\Filter}}.
```php
Yii::$app->storage->addImage(123, 0); // create an image from file object id 123 without filter.
```
@param integer $fileId The id of the file where image should be created from.
@param integer $filterId The id of the filter which should be applied to, if filter is 0, no filter will be added. Filter can new also be the string name of the filter like `tiny-crop`.
@param boolean $throwException Whether the addImage should throw an exception or just return boolean
@return bool|\luya\admin\image\Item|Exception Returns the item object, if an error happens and $throwException is off `false` is returned otherwhise an exception is thrown.
@throws \luya\Exception | [
"Add",
"a",
"new",
"image",
"based",
"an",
"existing",
"file",
"Id",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L602-L647 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.createImage | public function createImage($fileId, $filterId)
{
$image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
// the image exists already in the database and the file system
if ($image && $image->fileExists) {
return $image;
}
$file = StorageFile::findOne($fileId);
if (!$file) {
return false;
}
// create the new image name
$fileName = $filterId.'_'.$file->name_new_compound;
$fromTempFile = tempnam(sys_get_temp_dir(), 'fromFile');
$fromTempFile.= $fileName;
$content = $file->getContent();
// it seems the content can not be found.
if ($content === false) {
return false;
}
$writeFile = FileHelper::writeFile($fromTempFile, $content);
// unable to write the temp file
if (!$writeFile) {
return false;
}
// create a temp file
$tempFile = tempnam(sys_get_temp_dir(), 'destFile');
$tempFile.= $fileName;
// there is no filter, which means we create an image version for a given file.
if (empty($filterId)) {
@copy($fromTempFile, $tempFile);
} else {
$filter = StorageFilter::findOne($filterId);
if (!$filter || !$filter->applyFilterChain($fromTempFile, $tempFile)) {
return false;
}
}
$resolution = Storage::getImageResolution($tempFile);
// now copy the file to the storage system
$this->fileSystemSaveFile($tempFile, $fileName);
unlink($tempFile);
unlink($fromTempFile);
$this->flushImageArray();
// ensure the existing of the model
if ($image) {
$image->resolution_height = $resolution['height'];
$image->resolution_width = $resolution['width'];
$image->save();
return $image;
}
$image = new StorageImage();
$image->file_id = $fileId;
$image->filter_id = $filterId;
$image->resolution_height = $resolution['height'];
$image->resolution_width = $resolution['width'];
if (!$image->save()) {
return false;
}
return $image;
} | php | public function createImage($fileId, $filterId)
{
$image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
// the image exists already in the database and the file system
if ($image && $image->fileExists) {
return $image;
}
$file = StorageFile::findOne($fileId);
if (!$file) {
return false;
}
// create the new image name
$fileName = $filterId.'_'.$file->name_new_compound;
$fromTempFile = tempnam(sys_get_temp_dir(), 'fromFile');
$fromTempFile.= $fileName;
$content = $file->getContent();
// it seems the content can not be found.
if ($content === false) {
return false;
}
$writeFile = FileHelper::writeFile($fromTempFile, $content);
// unable to write the temp file
if (!$writeFile) {
return false;
}
// create a temp file
$tempFile = tempnam(sys_get_temp_dir(), 'destFile');
$tempFile.= $fileName;
// there is no filter, which means we create an image version for a given file.
if (empty($filterId)) {
@copy($fromTempFile, $tempFile);
} else {
$filter = StorageFilter::findOne($filterId);
if (!$filter || !$filter->applyFilterChain($fromTempFile, $tempFile)) {
return false;
}
}
$resolution = Storage::getImageResolution($tempFile);
// now copy the file to the storage system
$this->fileSystemSaveFile($tempFile, $fileName);
unlink($tempFile);
unlink($fromTempFile);
$this->flushImageArray();
// ensure the existing of the model
if ($image) {
$image->resolution_height = $resolution['height'];
$image->resolution_width = $resolution['width'];
$image->save();
return $image;
}
$image = new StorageImage();
$image->file_id = $fileId;
$image->filter_id = $filterId;
$image->resolution_height = $resolution['height'];
$image->resolution_width = $resolution['width'];
if (!$image->save()) {
return false;
}
return $image;
} | [
"public",
"function",
"createImage",
"(",
"$",
"fileId",
",",
"$",
"filterId",
")",
"{",
"$",
"image",
"=",
"StorageImage",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'file_id'",
"=>",
"$",
"fileId",
",",
"'filter_id'",
"=>",
"$",
"filterId",
"]... | Just creating the image based on input informations without usage of storage files or images list.
@param integer $fileId The id of the file to create filter of
@param integer $filterId The filter id to apply on the given file.
@since 1.2.2.1
@return \luya\admin\models\StorageImage|false Returns the storage image model on success, otherwise false. | [
"Just",
"creating",
"the",
"image",
"based",
"on",
"input",
"informations",
"without",
"usage",
"of",
"storage",
"files",
"or",
"images",
"list",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L657-L732 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFoldersArray | public function getFoldersArray()
{
if ($this->_foldersArray === null) {
$query = (new Query())
->from('{{%admin_storage_folder}} as folder')
->select(['folder.id', 'name', 'parent_id', 'timestamp_create', 'COUNT(file.id) filesCount'])
->where(['folder.is_deleted' => false])
->orderBy(['name' => 'ASC'])
->leftJoin('{{%admin_storage_file}} as file', 'folder.id=file.folder_id AND file.is_deleted = 0')
->groupBy(['folder.id'])
->indexBy(['id']);
$this->_foldersArray = $this->getQueryCacheHelper($query, self::CACHE_KEY_FOLDER);
}
return $this->_foldersArray;
} | php | public function getFoldersArray()
{
if ($this->_foldersArray === null) {
$query = (new Query())
->from('{{%admin_storage_folder}} as folder')
->select(['folder.id', 'name', 'parent_id', 'timestamp_create', 'COUNT(file.id) filesCount'])
->where(['folder.is_deleted' => false])
->orderBy(['name' => 'ASC'])
->leftJoin('{{%admin_storage_file}} as file', 'folder.id=file.folder_id AND file.is_deleted = 0')
->groupBy(['folder.id'])
->indexBy(['id']);
$this->_foldersArray = $this->getQueryCacheHelper($query, self::CACHE_KEY_FOLDER);
}
return $this->_foldersArray;
} | [
"public",
"function",
"getFoldersArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_foldersArray",
"===",
"null",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"'{{%admin_storage_folder}} as folder'",
")",
"->",
... | Get all storage folders as an array from database.
This method is used to retrieve all folders from the database and indexed by folder key.
@return array An array with all storage folders indexed by the folder id. | [
"Get",
"all",
"storage",
"folders",
"as",
"an",
"array",
"from",
"database",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L743-L759 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFoldersArrayItem | public function getFoldersArrayItem($folderId)
{
return (isset($this->foldersArray[$folderId])) ? $this->foldersArray[$folderId] : false;
} | php | public function getFoldersArrayItem($folderId)
{
return (isset($this->foldersArray[$folderId])) ? $this->foldersArray[$folderId] : false;
} | [
"public",
"function",
"getFoldersArrayItem",
"(",
"$",
"folderId",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"foldersArray",
"[",
"$",
"folderId",
"]",
")",
")",
"?",
"$",
"this",
"->",
"foldersArray",
"[",
"$",
"folderId",
"]",
":",
"f... | Get a single folder by folder id from the folders array.
@param integer $folderId The folder id to find.
@return boolean|array The folder array or false if not found. | [
"Get",
"a",
"single",
"folder",
"by",
"folder",
"id",
"from",
"the",
"folders",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L767-L770 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.addFolder | public function addFolder($folderName, $parentFolderId = 0)
{
$model = new StorageFolder();
$model->name = $folderName;
$model->parent_id = $parentFolderId;
$model->timestamp_create = time();
$this->deleteHasCache(self::CACHE_KEY_FOLDER);
if ($model->save(false)) {
return $model->id;
}
return false;
} | php | public function addFolder($folderName, $parentFolderId = 0)
{
$model = new StorageFolder();
$model->name = $folderName;
$model->parent_id = $parentFolderId;
$model->timestamp_create = time();
$this->deleteHasCache(self::CACHE_KEY_FOLDER);
if ($model->save(false)) {
return $model->id;
}
return false;
} | [
"public",
"function",
"addFolder",
"(",
"$",
"folderName",
",",
"$",
"parentFolderId",
"=",
"0",
")",
"{",
"$",
"model",
"=",
"new",
"StorageFolder",
"(",
")",
";",
"$",
"model",
"->",
"name",
"=",
"$",
"folderName",
";",
"$",
"model",
"->",
"parent_id... | Add new folder to the storage system.
@param string $folderName The name of the new folder
@param integer $parentFolderId If its a subfolder the id of the parent folder must be provided.
@return boolean|integer Returns the folder id or false if something went wrong. | [
"Add",
"new",
"folder",
"to",
"the",
"storage",
"system",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L822-L834 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFiltersArray | public function getFiltersArray()
{
if ($this->_filtersArray === null) {
$this->_filtersArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_filter}}')->select(['id', 'identifier', 'name'])->indexBy('identifier')->orderBy(['name' => SORT_ASC]), self::CACHE_KEY_FILTER);
}
return $this->_filtersArray;
} | php | public function getFiltersArray()
{
if ($this->_filtersArray === null) {
$this->_filtersArray = $this->getQueryCacheHelper((new Query())->from('{{%admin_storage_filter}}')->select(['id', 'identifier', 'name'])->indexBy('identifier')->orderBy(['name' => SORT_ASC]), self::CACHE_KEY_FILTER);
}
return $this->_filtersArray;
} | [
"public",
"function",
"getFiltersArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_filtersArray",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_filtersArray",
"=",
"$",
"this",
"->",
"getQueryCacheHelper",
"(",
"(",
"new",
"Query",
"(",
")",
")",
... | Get all storage filters as an array from database.
This method is used to retrieve all filters from the database and indexed by filter identifier key.
@return array An array with all storage filters indexed by the filter identifier. | [
"Get",
"all",
"storage",
"filters",
"as",
"an",
"array",
"from",
"database",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L845-L852 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFiltersArrayItem | public function getFiltersArrayItem($filterIdentifier)
{
return isset($this->filtersArray[$filterIdentifier]) ? $this->filtersArray[$filterIdentifier] : false;
} | php | public function getFiltersArrayItem($filterIdentifier)
{
return isset($this->filtersArray[$filterIdentifier]) ? $this->filtersArray[$filterIdentifier] : false;
} | [
"public",
"function",
"getFiltersArrayItem",
"(",
"$",
"filterIdentifier",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"filtersArray",
"[",
"$",
"filterIdentifier",
"]",
")",
"?",
"$",
"this",
"->",
"filtersArray",
"[",
"$",
"filterIdentifier",
"]",
... | Get a single filter by filter identifier from the filters array.
@param integer $filterIdentifier The filter identifier to find use {{luya\admin\base\Filter::identifier()}} method.
@return boolean|array The filter array or false if not found. | [
"Get",
"a",
"single",
"filter",
"by",
"filter",
"identifier",
"from",
"the",
"filters",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L872-L875 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getFilterId | public function getFilterId($identifier)
{
$filter = $this->getFiltersArrayItem($identifier);
return $filter ? (int) $filter['id'] : false;
} | php | public function getFilterId($identifier)
{
$filter = $this->getFiltersArrayItem($identifier);
return $filter ? (int) $filter['id'] : false;
} | [
"public",
"function",
"getFilterId",
"(",
"$",
"identifier",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFiltersArrayItem",
"(",
"$",
"identifier",
")",
";",
"return",
"$",
"filter",
"?",
"(",
"int",
")",
"$",
"filter",
"[",
"'id'",
"]",
":",
... | Get the filter id based on the identifier.
This is a short hand method as its used very often
@param string $identifier
@return integer
@since 1.2.2.1 | [
"Get",
"the",
"filter",
"id",
"based",
"on",
"the",
"identifier",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L886-L890 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.getQueryCacheHelper | private function getQueryCacheHelper(\yii\db\Query $query, $key)
{
$data = $this->getHasCache($key);
if ($data === false) {
$data = $query->all();
$this->setHasCache($key, $data);
}
return $data;
} | php | private function getQueryCacheHelper(\yii\db\Query $query, $key)
{
$data = $this->getHasCache($key);
if ($data === false) {
$data = $query->all();
$this->setHasCache($key, $data);
}
return $data;
} | [
"private",
"function",
"getQueryCacheHelper",
"(",
"\\",
"yii",
"\\",
"db",
"\\",
"Query",
"$",
"query",
",",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getHasCache",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false... | Caching helper method.
@param \yii\db\Query $query
@param string|array $key
@return mixed|boolean | [
"Caching",
"helper",
"method",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L899-L909 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.flushArrays | public function flushArrays()
{
$this->_filesArray = null;
$this->_imagesArray = null;
$this->_foldersArray = null;
$this->_filtersArray = null;
$this->deleteHasCache(self::CACHE_KEY_FILE);
$this->deleteHasCache(self::CACHE_KEY_IMAGE);
$this->deleteHasCache(self::CACHE_KEY_FOLDER);
$this->deleteHasCache(self::CACHE_KEY_FILTER);
} | php | public function flushArrays()
{
$this->_filesArray = null;
$this->_imagesArray = null;
$this->_foldersArray = null;
$this->_filtersArray = null;
$this->deleteHasCache(self::CACHE_KEY_FILE);
$this->deleteHasCache(self::CACHE_KEY_IMAGE);
$this->deleteHasCache(self::CACHE_KEY_FOLDER);
$this->deleteHasCache(self::CACHE_KEY_FILTER);
} | [
"public",
"function",
"flushArrays",
"(",
")",
"{",
"$",
"this",
"->",
"_filesArray",
"=",
"null",
";",
"$",
"this",
"->",
"_imagesArray",
"=",
"null",
";",
"$",
"this",
"->",
"_foldersArray",
"=",
"null",
";",
"$",
"this",
"->",
"_filtersArray",
"=",
... | Will force to refresh all container arrays and clean up the cache | [
"Will",
"force",
"to",
"refresh",
"all",
"container",
"arrays",
"and",
"clean",
"up",
"the",
"cache"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L914-L924 | train |
luyadev/luya-module-admin | src/storage/BaseFileSystemStorage.php | BaseFileSystemStorage.processThumbnails | public function processThumbnails()
{
foreach ($this->findFiles(['is_hidden' => false, 'is_deleted' => false]) as $file) {
if ($file->isImage) {
// create tiny thumbnail
$this->createImage($file->id, $this->getFilterId(TinyCrop::identifier()));
$this->createImage($file->id, $this->getFilterId(MediumThumbnail::identifier()));
}
}
// force auto fix
$this->autoFixMissingImageSources = true;
foreach ($this->findImages() as $image) {
if (!empty($image->file) && !$image->file->isHidden && !$image->file->isDeleted) {
$image->source; // which forces to recreate missing sources.
}
}
return true;
} | php | public function processThumbnails()
{
foreach ($this->findFiles(['is_hidden' => false, 'is_deleted' => false]) as $file) {
if ($file->isImage) {
// create tiny thumbnail
$this->createImage($file->id, $this->getFilterId(TinyCrop::identifier()));
$this->createImage($file->id, $this->getFilterId(MediumThumbnail::identifier()));
}
}
// force auto fix
$this->autoFixMissingImageSources = true;
foreach ($this->findImages() as $image) {
if (!empty($image->file) && !$image->file->isHidden && !$image->file->isDeleted) {
$image->source; // which forces to recreate missing sources.
}
}
return true;
} | [
"public",
"function",
"processThumbnails",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"findFiles",
"(",
"[",
"'is_hidden'",
"=>",
"false",
",",
"'is_deleted'",
"=>",
"false",
"]",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
... | This method allwos you to generate all thumbnails for the file manager, you can trigger this process when
importing or creating several images at once, so the user does not have to create the thumbnails
@return boolean | [
"This",
"method",
"allwos",
"you",
"to",
"generate",
"all",
"thumbnails",
"for",
"the",
"file",
"manager",
"you",
"can",
"trigger",
"this",
"process",
"when",
"importing",
"or",
"creating",
"several",
"images",
"at",
"once",
"so",
"the",
"user",
"does",
"not... | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/BaseFileSystemStorage.php#L943-L963 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.node | public function node($name, $icon, $template = false)
{
$this->_pointers['node'] = self::$index;
$this->_menu[self::$index] = [
'id' => self::$index,
'moduleId' => $this->moduleContext->id,
'template' => $template,
'routing' => $template ? 'custom' : 'default',
'alias' => $name,
'icon' => $icon,
'permissionRoute' => false,
'permissionIsRoute' => false,
'searchModelClass' => false,
];
self::$index++;
return $this;
} | php | public function node($name, $icon, $template = false)
{
$this->_pointers['node'] = self::$index;
$this->_menu[self::$index] = [
'id' => self::$index,
'moduleId' => $this->moduleContext->id,
'template' => $template,
'routing' => $template ? 'custom' : 'default',
'alias' => $name,
'icon' => $icon,
'permissionRoute' => false,
'permissionIsRoute' => false,
'searchModelClass' => false,
];
self::$index++;
return $this;
} | [
"public",
"function",
"node",
"(",
"$",
"name",
",",
"$",
"icon",
",",
"$",
"template",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_pointers",
"[",
"'node'",
"]",
"=",
"self",
"::",
"$",
"index",
";",
"$",
"this",
"->",
"_menu",
"[",
"self",
"::... | The node is the menu entry in the TOP navigation of the luya administration interface.
@param string $name The name of the node, all names will process trough the `Yii::t` function with its module name as prefix.
@param string $icon The icon name based on the google icons font see https://design.google.com/icons/.
@param bool $template Whether to use a custom template or not.
@return \luya\admin\components\AdminMenuBuilder | [
"The",
"node",
"is",
"the",
"menu",
"entry",
"in",
"the",
"TOP",
"navigation",
"of",
"the",
"luya",
"administration",
"interface",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L97-L114 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.nodeRoute | public function nodeRoute($name, $icon, $route, $searchModelClass = null)
{
$this->_pointers['node'] = self::$index;
$this->_menu[self::$index] = [
'id' => self::$index,
'moduleId' => $this->moduleContext->id,
'template' => $route, // as the template is equal to the route of the node which is loaded
'routing' => 'custom',
'alias' => $name,
'icon' => $icon,
'permissionRoute' => $route,
'permissionIsRoute' => true,
'searchModelClass' => $searchModelClass,
];
$this->_permissionRoutes[] = ['route' => $route, 'alias' => $name];
self::$index++;
return $this;
} | php | public function nodeRoute($name, $icon, $route, $searchModelClass = null)
{
$this->_pointers['node'] = self::$index;
$this->_menu[self::$index] = [
'id' => self::$index,
'moduleId' => $this->moduleContext->id,
'template' => $route, // as the template is equal to the route of the node which is loaded
'routing' => 'custom',
'alias' => $name,
'icon' => $icon,
'permissionRoute' => $route,
'permissionIsRoute' => true,
'searchModelClass' => $searchModelClass,
];
$this->_permissionRoutes[] = ['route' => $route, 'alias' => $name];
self::$index++;
return $this;
} | [
"public",
"function",
"nodeRoute",
"(",
"$",
"name",
",",
"$",
"icon",
",",
"$",
"route",
",",
"$",
"searchModelClass",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_pointers",
"[",
"'node'",
"]",
"=",
"self",
"::",
"$",
"index",
";",
"$",
"this",
"-... | A node which is a custom route to open, nodes are the the top menu of the luya administration interfaces.
@param string $name The name of the node, all names will process trough the `Yii::t` function with its module name as prefix.
@param string $icon The icon name based on the google icons font see https://design.google.com/icons/.
@param string $route The route to the template which is going to be render by angular, example `cmsadmin/default/index`.
@param string $searchModelClass The path to the model to search inside the admin global search, must implement the {{luya\admin\base\GenericSearchInterface}}.
@return \luya\admin\components\AdminMenuBuilder | [
"A",
"node",
"which",
"is",
"a",
"custom",
"route",
"to",
"open",
"nodes",
"are",
"the",
"the",
"top",
"menu",
"of",
"the",
"luya",
"administration",
"interfaces",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L125-L144 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.itemApi | public function itemApi($name, $route, $icon, $apiEndpoint, array $options = [])
{
$item = [
'alias' => $name,
'route' => $route,
'icon' => $icon,
'permissionApiEndpoint' => $apiEndpoint,
'permissionIsRoute' => false,
'permissionIsApi' => true,
'searchModelClass' => false,
'options' => $this->verifyOptions($options),
];
$this->_menu[$this->_pointers['node']]['groups'][$this->_pointers['group']]['items'][] = $item;
$this->_permissionApis[] = ['api' => $apiEndpoint, 'alias' => $name, 'pool' => $this->getOptionValue($item, 'pool', null)];
return $this;
} | php | public function itemApi($name, $route, $icon, $apiEndpoint, array $options = [])
{
$item = [
'alias' => $name,
'route' => $route,
'icon' => $icon,
'permissionApiEndpoint' => $apiEndpoint,
'permissionIsRoute' => false,
'permissionIsApi' => true,
'searchModelClass' => false,
'options' => $this->verifyOptions($options),
];
$this->_menu[$this->_pointers['node']]['groups'][$this->_pointers['group']]['items'][] = $item;
$this->_permissionApis[] = ['api' => $apiEndpoint, 'alias' => $name, 'pool' => $this->getOptionValue($item, 'pool', null)];
return $this;
} | [
"public",
"function",
"itemApi",
"(",
"$",
"name",
",",
"$",
"route",
",",
"$",
"icon",
",",
"$",
"apiEndpoint",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"item",
"=",
"[",
"'alias'",
"=>",
"$",
"name",
",",
"'route'",
"=>",
"$"... | Add an item to a group. API items are based on the ngrest crud concept.
@param string $name The name of the Api (displayed as menu point in the left navigation), all names run through the `Yii::t()` method prefixed with the module id.
@param string $route The api route to the ngrest controller `cmsadmin/navcontainer/index`.
@param string $icon The icon name based on the google icons font see https://design.google.com/icons/.
@param string $apiEndpoint The api endpoint defined in the NgRestModel::ngRestApiEndpoint `api-cms-navcontainer`.
@param array $options An array with options you can provided and read inside the admin menu component. See {{\luya\admin\components\AdminMenuBuilder::verifyOptions}} for detail list and informations.
@return \luya\admin\components\AdminMenuBuilder | [
"Add",
"an",
"item",
"to",
"a",
"group",
".",
"API",
"items",
"are",
"based",
"on",
"the",
"ngrest",
"crud",
"concept",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L170-L188 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.itemPoolApi | public function itemPoolApi($name, $route, $icon, $apiEndpoint, $pool, array $options = [])
{
return $this->itemApi($name, $route, $icon, $apiEndpoint, array_merge($options, [
'pool' => $pool,
]));
} | php | public function itemPoolApi($name, $route, $icon, $apiEndpoint, $pool, array $options = [])
{
return $this->itemApi($name, $route, $icon, $apiEndpoint, array_merge($options, [
'pool' => $pool,
]));
} | [
"public",
"function",
"itemPoolApi",
"(",
"$",
"name",
",",
"$",
"route",
",",
"$",
"icon",
",",
"$",
"apiEndpoint",
",",
"$",
"pool",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"itemApi",
"(",
"$",
"name",
... | Generate a permission for an API with a Pool
@param string $name
@param string $route
@param string $icon
@param string $apiEndpoint
@param string $pool
@param array $options
@return AdminMenuBuilder
@since 2.0.0 | [
"Generate",
"a",
"permission",
"for",
"an",
"API",
"with",
"a",
"Pool"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L202-L207 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.itemRoute | public function itemRoute($name, $route, $icon, $searchModelClass = null, array $options = [])
{
$this->_menu[$this->_pointers['node']]['groups'][$this->_pointers['group']]['items'][] = [
'alias' => $name,
'route' => $route,
'icon' => $icon,
'permissionApiEndpoint' => null,
'permissionIsRoute' => true,
'permissionIsApi' => false,
'searchModelClass' => $searchModelClass,
'options' => $this->verifyOptions($options),
];
$this->_permissionRoutes[] = ['route' => $route, 'alias' => $name];
return $this;
} | php | public function itemRoute($name, $route, $icon, $searchModelClass = null, array $options = [])
{
$this->_menu[$this->_pointers['node']]['groups'][$this->_pointers['group']]['items'][] = [
'alias' => $name,
'route' => $route,
'icon' => $icon,
'permissionApiEndpoint' => null,
'permissionIsRoute' => true,
'permissionIsApi' => false,
'searchModelClass' => $searchModelClass,
'options' => $this->verifyOptions($options),
];
$this->_permissionRoutes[] = ['route' => $route, 'alias' => $name];
return $this;
} | [
"public",
"function",
"itemRoute",
"(",
"$",
"name",
",",
"$",
"route",
",",
"$",
"icon",
",",
"$",
"searchModelClass",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_menu",
"[",
"$",
"this",
"->",
"_pointe... | Add an item to a group. Route items opens a angular view.
@param string $name The name of the Api (displayed as menu point in the left navigation), all names run through the `Yii::t()` method prefixed with the module id.
@param string $route The route to the template `cmsadmin/permission/index`.
@param string $icon The icon name based on the google icons font see https://design.google.com/icons/.
@param string $searchModelClass The search model must implement the {{luya\admin\base\GenericSearchInterface}}.
@param array $options An array with options you can provided and read inside the admin menu component. See {{\luya\admin\components\AdminMenuBuilder::verifyOptions}} for detail list and informations.
@return \luya\admin\components\AdminMenuBuilder | [
"Add",
"an",
"item",
"to",
"a",
"group",
".",
"Route",
"items",
"opens",
"a",
"angular",
"view",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L219-L235 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.verifyOptions | protected function verifyOptions(array $options = [])
{
foreach ($options as $key => $value) {
if (!in_array($key, static::$options)) {
unset($options[$key]);
}
}
return $options;
} | php | protected function verifyOptions(array $options = [])
{
foreach ($options as $key => $value) {
if (!in_array($key, static::$options)) {
unset($options[$key]);
}
}
return $options;
} | [
"protected",
"function",
"verifyOptions",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"static",
"::",
"$",
... | Verify the additional options of an itemRoute or itemApi item.
The following options are currently supported
- hiddenInMenu: If set to true the item will be hidden in the left menu, this is usefull when creating ngrest crud's for crud-realtion views.
@param array $options The options to verify
@return array The verified allowed options. | [
"Verify",
"the",
"additional",
"options",
"of",
"an",
"itemRoute",
"or",
"itemApi",
"item",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L247-L256 | train |
luyadev/luya-module-admin | src/components/AdminMenuBuilder.php | AdminMenuBuilder.getOptionValue | public static function getOptionValue(array $item, $optionName, $defaultValue = false)
{
if (!isset($item['options'])) {
return $defaultValue;
}
return isset($item['options'][$optionName]) ? $item['options'][$optionName] : $defaultValue;
} | php | public static function getOptionValue(array $item, $optionName, $defaultValue = false)
{
if (!isset($item['options'])) {
return $defaultValue;
}
return isset($item['options'][$optionName]) ? $item['options'][$optionName] : $defaultValue;
} | [
"public",
"static",
"function",
"getOptionValue",
"(",
"array",
"$",
"item",
",",
"$",
"optionName",
",",
"$",
"defaultValue",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
"$",
"de... | Helper method to get then value of an options inside an item.
@param array $item The item where the option key persists.
@param string $optionName The name of the option to get.
@param mixed $defaultValue The default value if the option is not available for this item.
@return mixed | [
"Helper",
"method",
"to",
"get",
"then",
"value",
"of",
"an",
"options",
"inside",
"an",
"item",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenuBuilder.php#L274-L281 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.getSortField | public function getSortField()
{
if ($this->_sortField === false) {
return [];
}
if ($this->_sortField) {
//
if (is_array($this->_sortField)) {
return [$this->name => $this->_sortField];
}
return [$this->name => [
'asc' => [$this->_sortField => SORT_ASC],
'desc' => [$this->_sortField => SORT_DESC]
]];
}
return [$this->name];
} | php | public function getSortField()
{
if ($this->_sortField === false) {
return [];
}
if ($this->_sortField) {
//
if (is_array($this->_sortField)) {
return [$this->name => $this->_sortField];
}
return [$this->name => [
'asc' => [$this->_sortField => SORT_ASC],
'desc' => [$this->_sortField => SORT_DESC]
]];
}
return [$this->name];
} | [
"public",
"function",
"getSortField",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sortField",
"===",
"false",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_sortField",
")",
"{",
"// ",
"if",
"(",
"is_array",
"(",
"$",
... | Getter method for a sortField defintion.
If no sortField definition has been set, the plugin attribute name is used.
@return array
@since 2.0.0 | [
"Getter",
"method",
"for",
"a",
"sortField",
"defintion",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L213-L232 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.getNgShowCondition | public function getNgShowCondition($ngModel)
{
preg_match_all('/{(.*?)}/', $this->condition, $matches, PREG_SET_ORDER);
$search = [];
$replace = [];
foreach ($matches as $match) {
$search[] = $match[0];
$replace[] = $this->replaceFieldFromNgModelContext($ngModel, $match[1]);
}
return str_replace($search, $replace, $this->condition);
} | php | public function getNgShowCondition($ngModel)
{
preg_match_all('/{(.*?)}/', $this->condition, $matches, PREG_SET_ORDER);
$search = [];
$replace = [];
foreach ($matches as $match) {
$search[] = $match[0];
$replace[] = $this->replaceFieldFromNgModelContext($ngModel, $match[1]);
}
return str_replace($search, $replace, $this->condition);
} | [
"public",
"function",
"getNgShowCondition",
"(",
"$",
"ngModel",
")",
"{",
"preg_match_all",
"(",
"'/{(.*?)}/'",
",",
"$",
"this",
"->",
"condition",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"$",
"search",
"=",
"[",
"]",
";",
"$",
"replace",
... | Get the ng-show condition from a given ngModel context.
Evaluates the ng-show condition from a given ngModel context. A condition like
`{field} == true` would return `data.create.field == true`.
@param string $ngModel The ngModel to get the context informations from.
@return string Returns the condition with replaced field context like `data.create.fieldname == 0`
@since 1.2.0 | [
"Get",
"the",
"ng",
"-",
"show",
"condition",
"from",
"a",
"given",
"ngModel",
"context",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L398-L409 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.createFormTag | public function createFormTag($name, $id, $ngModel, array $options = [])
{
$defaultOptions = [
'fieldid' => $id,
'model' => $ngModel,
'label' => $this->alias,
'fieldname' => $this->name,
'i18n' => $this->i18n ? 1 : '',
];
// if a condition is available, evalute from given context
if ($this->condition) {
$defaultOptions['ng-show'] = $this->getNgShowCondition($ngModel);
}
return $this->createTag($name, null, array_merge($options, $defaultOptions));
} | php | public function createFormTag($name, $id, $ngModel, array $options = [])
{
$defaultOptions = [
'fieldid' => $id,
'model' => $ngModel,
'label' => $this->alias,
'fieldname' => $this->name,
'i18n' => $this->i18n ? 1 : '',
];
// if a condition is available, evalute from given context
if ($this->condition) {
$defaultOptions['ng-show'] = $this->getNgShowCondition($ngModel);
}
return $this->createTag($name, null, array_merge($options, $defaultOptions));
} | [
"public",
"function",
"createFormTag",
"(",
"$",
"name",
",",
"$",
"id",
",",
"$",
"ngModel",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaultOptions",
"=",
"[",
"'fieldid'",
"=>",
"$",
"id",
",",
"'model'",
"=>",
"$",
"ngModel",
... | Helper method to create a form tag based on current object.
@param string $name Name of the form tag.
@param string $id The id tag of the tag.
@param string $ngModel The ngrest model name of the tag.
@param array $options Options to passes to the tag creator.
@return string The generated tag content. | [
"Helper",
"method",
"to",
"create",
"a",
"form",
"tag",
"based",
"on",
"current",
"object",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L420-L436 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.createListTag | public function createListTag($ngModel, array $options = [])
{
return $this->createTag('span', null, ArrayHelper::merge(['ng-bind' => $ngModel], $options));
} | php | public function createListTag($ngModel, array $options = [])
{
return $this->createTag('span', null, ArrayHelper::merge(['ng-bind' => $ngModel], $options));
} | [
"public",
"function",
"createListTag",
"(",
"$",
"ngModel",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"createTag",
"(",
"'span'",
",",
"null",
",",
"ArrayHelper",
"::",
"merge",
"(",
"[",
"'ng-bind'",
"=>",
"$"... | Helper method to create a span tag with the ng-model in angular context for the crud overview
@param string $ngModel
@param array $options An array with options to pass to the list tag
@return string | [
"Helper",
"method",
"to",
"create",
"a",
"span",
"tag",
"with",
"the",
"ng",
"-",
"model",
"in",
"angular",
"context",
"for",
"the",
"crud",
"overview"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L444-L447 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.createCrudLoaderTag | public function createCrudLoaderTag($ngrestModelClass, $ngRestModelSelectMode = null, array $options = [])
{
$menu = Yii::$app->adminmenu->getApiDetail($ngrestModelClass::ngRestApiEndpoint(), Yii::$app->request->get('pool'));
if ($menu) {
if ($ngRestModelSelectMode) {
$options['model-setter'] = $ngRestModelSelectMode;
$options['model-selection'] = 1;
} else {
$options['model-selection'] = 0;
}
return $this->createTag('crud-loader', null, array_merge(['api' => $menu['route'], 'alias' => $menu['alias']], $options));
}
return null;
} | php | public function createCrudLoaderTag($ngrestModelClass, $ngRestModelSelectMode = null, array $options = [])
{
$menu = Yii::$app->adminmenu->getApiDetail($ngrestModelClass::ngRestApiEndpoint(), Yii::$app->request->get('pool'));
if ($menu) {
if ($ngRestModelSelectMode) {
$options['model-setter'] = $ngRestModelSelectMode;
$options['model-selection'] = 1;
} else {
$options['model-selection'] = 0;
}
return $this->createTag('crud-loader', null, array_merge(['api' => $menu['route'], 'alias' => $menu['alias']], $options));
}
return null;
} | [
"public",
"function",
"createCrudLoaderTag",
"(",
"$",
"ngrestModelClass",
",",
"$",
"ngRestModelSelectMode",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"menu",
"=",
"Yii",
"::",
"$",
"app",
"->",
"adminmenu",
"->",
"getApiDet... | Create a tag for relation window toggler with directive crudLoader based on a ngrest model class.
@param string $ngrestModelClass
@return string The generated tag or null if permission does not exists | [
"Create",
"a",
"tag",
"for",
"relation",
"window",
"toggler",
"with",
"directive",
"crudLoader",
"based",
"on",
"a",
"ngrest",
"model",
"class",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L455-L471 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.createSchedulerListTag | public function createSchedulerListTag($ngModel, $values, $dataRow, array $options = [])
{
return $this->createTag('luya-schedule', null, array_merge([
'value' => $ngModel,
'model-class' => get_class($this->renderContext->getModel()),
'title' => $this->alias,
'attribute-name' => $this->name,
'attribute-values' => Angular::optionsArrayInput($values),
'primary-key-value' => 'getRowPrimaryValue('.$dataRow.')',
], $options));
} | php | public function createSchedulerListTag($ngModel, $values, $dataRow, array $options = [])
{
return $this->createTag('luya-schedule', null, array_merge([
'value' => $ngModel,
'model-class' => get_class($this->renderContext->getModel()),
'title' => $this->alias,
'attribute-name' => $this->name,
'attribute-values' => Angular::optionsArrayInput($values),
'primary-key-value' => 'getRowPrimaryValue('.$dataRow.')',
], $options));
} | [
"public",
"function",
"createSchedulerListTag",
"(",
"$",
"ngModel",
",",
"$",
"values",
",",
"$",
"dataRow",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"createTag",
"(",
"'luya-schedule'",
",",
"null",
",",
"arra... | Create the Scheulder tag for a given field.
The scheduler tag allows you to change the given field value based on input values for a given field if a model is ailable.
```
<luya-schedule value="{{currentValueOfTheEntity}}" model-class="luya\admin\models\User" attribute-name="is_deleted" attribute-values="{0:'Not Deleted',1:'Deleted'}"
```
@param [type] $ngModel
@param [type] $values
@return void
@since 2.0.0 | [
"Create",
"the",
"Scheulder",
"tag",
"for",
"a",
"given",
"field",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L487-L497 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.onSave | public function onSave($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeSave($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nFieldEncode($event->sender->getAttribute($this->name)));
}
}
} | php | public function onSave($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeSave($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nFieldEncode($event->sender->getAttribute($this->name)));
}
}
} | [
"public",
"function",
"onSave",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAttributeWriteable",
"(",
"$",
"event",
")",
"&&",
"$",
"this",
"->",
"onBeforeSave",
"(",
"$",
"event",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"i18... | This event will be triggered `onSave` event. If the model property is not writeable the event will not trigger.
If the beforeSave method returns true and i18n is enabled, the value will be json encoded.
@param \yii\base\ModelEvent $event ModelEvent represents the information available in yii\db\ActiveRecord::EVENT_BEFORE_VALIDATE.
@return void | [
"This",
"event",
"will",
"be",
"triggered",
"onSave",
"event",
".",
"If",
"the",
"model",
"property",
"is",
"not",
"writeable",
"the",
"event",
"will",
"not",
"trigger",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L568-L575 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.onListFind | public function onListFind($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeListFind($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nDecodedGetActive($this->i18nFieldDecode($event->sender->getAttribute($this->name), $this->i18nEmptyValue)));
}
$this->onAfterListFind($event);
}
} | php | public function onListFind($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeListFind($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nDecodedGetActive($this->i18nFieldDecode($event->sender->getAttribute($this->name), $this->i18nEmptyValue)));
}
$this->onAfterListFind($event);
}
} | [
"public",
"function",
"onListFind",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAttributeWriteable",
"(",
"$",
"event",
")",
"&&",
"$",
"this",
"->",
"onBeforeListFind",
"(",
"$",
"event",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->"... | This event is only trigger when returning the ngrest crud list data. If the property of this plugin inside the model, the event will not be triggered.
@param \luya\admin\ngrest\base\NgRestModel::EVENT_AFTER_NGREST_FIND $event The NgRestModel after ngrest find event. | [
"This",
"event",
"is",
"only",
"trigger",
"when",
"returning",
"the",
"ngrest",
"crud",
"list",
"data",
".",
"If",
"the",
"property",
"of",
"this",
"plugin",
"inside",
"the",
"model",
"the",
"event",
"will",
"not",
"be",
"triggered",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L615-L623 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.onFind | public function onFind($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeFind($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nDecodedGetActive($this->i18nFieldDecode($event->sender->getAttribute($this->name), $this->i18nEmptyValue)));
}
$this->onAfterFind($event);
}
} | php | public function onFind($event)
{
if ($this->isAttributeWriteable($event) && $this->onBeforeFind($event)) {
if ($this->i18n) {
$event->sender->setAttribute($this->name, $this->i18nDecodedGetActive($this->i18nFieldDecode($event->sender->getAttribute($this->name), $this->i18nEmptyValue)));
}
$this->onAfterFind($event);
}
} | [
"public",
"function",
"onFind",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAttributeWriteable",
"(",
"$",
"event",
")",
"&&",
"$",
"this",
"->",
"onBeforeFind",
"(",
"$",
"event",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"i18... | ActiveRecord afterFind event. If the property of this plugin inside the model, the event will not be triggered.
@param \yii\base\Event $event An event that is triggered after the record is created and populated with query result. | [
"ActiveRecord",
"afterFind",
"event",
".",
"If",
"the",
"property",
"of",
"this",
"plugin",
"inside",
"the",
"model",
"the",
"event",
"will",
"not",
"be",
"triggered",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L654-L663 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.onCollectServiceData | public function onCollectServiceData($event)
{
if ($this->onBeforeCollectServiceData($event)) {
$data = $this->serviceData($event);
if (!empty($data)) {
$event->sender->addNgRestServiceData($this->name, $data);
}
}
} | php | public function onCollectServiceData($event)
{
if ($this->onBeforeCollectServiceData($event)) {
$data = $this->serviceData($event);
if (!empty($data)) {
$event->sender->addNgRestServiceData($this->name, $data);
}
}
} | [
"public",
"function",
"onCollectServiceData",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"onBeforeCollectServiceData",
"(",
"$",
"event",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"serviceData",
"(",
"$",
"event",
")",
";",
"i... | The ngrest services collector.
> The service event is async to the other events, which means the service event collects data before the the other events are called.
@param \luya\admin\ngrest\base\NgRestModel::EVENT_SERVICE_NGREST $event NgRestModel event EVENT_SERVICE_NGREST. | [
"The",
"ngrest",
"services",
"collector",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L735-L743 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.isAttributeWriteable | protected function isAttributeWriteable($event)
{
return ($event->sender->hasAttribute($this->name) || $event->sender->canSetProperty($this->name));
} | php | protected function isAttributeWriteable($event)
{
return ($event->sender->hasAttribute($this->name) || $event->sender->canSetProperty($this->name));
} | [
"protected",
"function",
"isAttributeWriteable",
"(",
"$",
"event",
")",
"{",
"return",
"(",
"$",
"event",
"->",
"sender",
"->",
"hasAttribute",
"(",
"$",
"this",
"->",
"name",
")",
"||",
"$",
"event",
"->",
"sender",
"->",
"canSetProperty",
"(",
"$",
"t... | Check whether the current plugin attribute is writeable in the Model class or not. If not writeable some events will be stopped from
further processing. This is mainly used when adding extraFields to the grid list view.
@param \yii\base\Event $event The current base event object.
@return boolean Whether the current plugin attribute is writeable or not. | [
"Check",
"whether",
"the",
"current",
"plugin",
"attribute",
"is",
"writeable",
"in",
"the",
"Model",
"class",
"or",
"not",
".",
"If",
"not",
"writeable",
"some",
"events",
"will",
"be",
"stopped",
"from",
"further",
"processing",
".",
"This",
"is",
"mainly"... | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L752-L755 | train |
luyadev/luya-module-admin | src/ngrest/base/Plugin.php | Plugin.writeAttribute | protected function writeAttribute($event, $value)
{
$property = $this->name;
$event->sender->{$property} = $value;
} | php | protected function writeAttribute($event, $value)
{
$property = $this->name;
$event->sender->{$property} = $value;
} | [
"protected",
"function",
"writeAttribute",
"(",
"$",
"event",
",",
"$",
"value",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"event",
"->",
"sender",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"value",
";",
"}"
] | Write a value to a plugin attribute or property.
As setAttribute() does only write to attributes therefore this method allwos you to write to
a property or attribute value. As {{isAttributeWriteAble()}} returns true whether its a property
or attribute.
@param \yii\base\Event $event The event to retrieve the values from (via $sender property).
@param mixed $value The value to writte on the attribute or property.
@since 1.2.1 | [
"Write",
"a",
"value",
"to",
"a",
"plugin",
"attribute",
"or",
"property",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Plugin.php#L768-L772 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.decode | public static function decode($value, $onEmptyValue = '')
{
$languages = Yii::$app->adminLanguage->getLanguages();
// if its not already unserialized, decode it
if (!is_array($value) && !empty($value)) {
try {
$value = Json::decode($value);
} catch (InvalidParamException $e) {
$value = [];
}
}
// if value is empty, we create an empty array
if (empty($value)) {
$value = [];
}
// fall back for not transformed values
if (!is_array($value)) {
$value = (array) $value;
}
// add all not existing languages to the array (for example a language has been added after the database item has been created)
foreach ($languages as $lang) {
if (!array_key_exists($lang['short_code'], $value)) {
$value[$lang['short_code']] = $onEmptyValue;
} elseif (empty($value[$lang['short_code']])) {
$value[$lang['short_code']] = $onEmptyValue;
}
}
return $value;
} | php | public static function decode($value, $onEmptyValue = '')
{
$languages = Yii::$app->adminLanguage->getLanguages();
// if its not already unserialized, decode it
if (!is_array($value) && !empty($value)) {
try {
$value = Json::decode($value);
} catch (InvalidParamException $e) {
$value = [];
}
}
// if value is empty, we create an empty array
if (empty($value)) {
$value = [];
}
// fall back for not transformed values
if (!is_array($value)) {
$value = (array) $value;
}
// add all not existing languages to the array (for example a language has been added after the database item has been created)
foreach ($languages as $lang) {
if (!array_key_exists($lang['short_code'], $value)) {
$value[$lang['short_code']] = $onEmptyValue;
} elseif (empty($value[$lang['short_code']])) {
$value[$lang['short_code']] = $onEmptyValue;
}
}
return $value;
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"value",
",",
"$",
"onEmptyValue",
"=",
"''",
")",
"{",
"$",
"languages",
"=",
"Yii",
"::",
"$",
"app",
"->",
"adminLanguage",
"->",
"getLanguages",
"(",
")",
";",
"// if its not already unserialized, decode ... | Decode from Json to PHP
@param string|array $value The value to decode from json to php.
@param string $onEmptyValue Defines the value if the language could not be found and a value will be returns, this value will be used.
@return array Return the decoded php value. | [
"Decode",
"from",
"Json",
"to",
"PHP"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L41-L74 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.decodeArray | public static function decodeArray(array $array, $onEmptyValue = '')
{
$decoded = [];
foreach ($array as $key => $value) {
$decoded[$key] = static::decode($value, $onEmptyValue);
}
return $decoded;
} | php | public static function decodeArray(array $array, $onEmptyValue = '')
{
$decoded = [];
foreach ($array as $key => $value) {
$decoded[$key] = static::decode($value, $onEmptyValue);
}
return $decoded;
} | [
"public",
"static",
"function",
"decodeArray",
"(",
"array",
"$",
"array",
",",
"$",
"onEmptyValue",
"=",
"''",
")",
"{",
"$",
"decoded",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"decode... | Decode an array with i18n values.
In order to decode an arry with json values you can use this function istead of iterator trough
the array items by yourself and calling {{luya\admin\helpers\I18n::decode}}.
```php
$array = ['{"de:"Hallo","en":"Hello"}', '{"de:"Ja","en":"Yes"}'];
$decoded = I18n::decodeArray($array);
print_r($decoded); // dump: array(['de' => 'Hallo', 'en' => 'Hello'], ['de' => 'Ja', 'en' => 'Yes']);
```
@param array $array The array to iterate trough and call the {{luya\admin\helpers\I18n::decode}} for each value.
@param string $onEmptyValue If the decoded value is not existing or empty, this default value will be used instead of null.
@return array | [
"Decode",
"an",
"array",
"with",
"i18n",
"values",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L94-L102 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.decodeFindActive | public static function decodeFindActive($input, $onEmptyValue = '', $lang = null)
{
return static::findActive(static::decode($input, $onEmptyValue), $onEmptyValue, $lang);
} | php | public static function decodeFindActive($input, $onEmptyValue = '', $lang = null)
{
return static::findActive(static::decode($input, $onEmptyValue), $onEmptyValue, $lang);
} | [
"public",
"static",
"function",
"decodeFindActive",
"(",
"$",
"input",
",",
"$",
"onEmptyValue",
"=",
"''",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"findActive",
"(",
"static",
"::",
"decode",
"(",
"$",
"input",
",",
"$",
"on... | Decodes a json string and returns the current active language item.
```php
// assume the default language is `en`
$output = I18n::decodeFindActive('{"de":"Hallo","en":"Hello"}');
echo $output; // output is "Hello"
```
@param string $input The json string
@param string $onEmptyValue If element is not found, this value is returned instead.
@param string $lang The language to return, if no lang is provided, the language resolved trough the admin ui (or user language) is used by default.
@return string The value from the json for the current active language or if not found the value from onEmptyValue. | [
"Decodes",
"a",
"json",
"string",
"and",
"returns",
"the",
"current",
"active",
"language",
"item",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L119-L122 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.decodeFindActiveArray | public static function decodeFindActiveArray(array $input, $onEmptyValue = '', $lang = null)
{
return static::findActiveArray(static::decodeArray($input, $onEmptyValue), $onEmptyValue, $lang);
} | php | public static function decodeFindActiveArray(array $input, $onEmptyValue = '', $lang = null)
{
return static::findActiveArray(static::decodeArray($input, $onEmptyValue), $onEmptyValue, $lang);
} | [
"public",
"static",
"function",
"decodeFindActiveArray",
"(",
"array",
"$",
"input",
",",
"$",
"onEmptyValue",
"=",
"''",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"findActiveArray",
"(",
"static",
"::",
"decodeArray",
"(",
"$",
"i... | Decodes an array with json strings and returns the current active language item for each entry.
```php
// assume the default language is `en`
$output = I18n::decodeFindActiveArray(['{"de":"Hallo","en":"Hello"}'], ['{"de":"Katze","en":"Cat"}']);
var_dump($output); // dump: array('Hello', 'Cat')
```
@param array $input
@param mixed $onEmptyValue The value to use when the requested language could not be found.
@param string $lang The language to return, if no lang is provided, the language resolved trough the admin ui (or user language) is used by default.
@return array | [
"Decodes",
"an",
"array",
"with",
"json",
"strings",
"and",
"returns",
"the",
"current",
"active",
"language",
"item",
"for",
"each",
"entry",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L139-L142 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.findActive | public static function findActive(array $fieldValues, $onEmptyValue = '', $lang = null)
{
$langShortCode = $lang ? $lang : Yii::$app->adminLanguage->getActiveShortCode();
return array_key_exists($langShortCode, $fieldValues) ? $fieldValues[$langShortCode] : $onEmptyValue;
} | php | public static function findActive(array $fieldValues, $onEmptyValue = '', $lang = null)
{
$langShortCode = $lang ? $lang : Yii::$app->adminLanguage->getActiveShortCode();
return array_key_exists($langShortCode, $fieldValues) ? $fieldValues[$langShortCode] : $onEmptyValue;
} | [
"public",
"static",
"function",
"findActive",
"(",
"array",
"$",
"fieldValues",
",",
"$",
"onEmptyValue",
"=",
"''",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"$",
"langShortCode",
"=",
"$",
"lang",
"?",
"$",
"lang",
":",
"Yii",
"::",
"$",
"app",
"->"... | Find the corresponding element inside an array for the current active language.
```php
// assume the default language is `en`
$output = I18n::findActive(['de' => 'Hallo', 'en' => 'Hello']);
echo $output; // output is "Hello"
```
@param array $fieldValues The array you want to to find the current
@param mixed $onEmptyValue The value you can set when the language could not be found
@param string $lang The language to return, if no lang is provided, the language resolved trough the admin ui (or user language) is used by default.
@return mixed | [
"Find",
"the",
"corresponding",
"element",
"inside",
"an",
"array",
"for",
"the",
"current",
"active",
"language",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L159-L164 | train |
luyadev/luya-module-admin | src/helpers/I18n.php | I18n.findActiveArray | public static function findActiveArray(array $array, $onEmptyValue = '', $lang = null)
{
$output = [];
foreach ($array as $key => $value) {
$output[$key] = static::findActive($value, $onEmptyValue, $lang);
}
return $output;
} | php | public static function findActiveArray(array $array, $onEmptyValue = '', $lang = null)
{
$output = [];
foreach ($array as $key => $value) {
$output[$key] = static::findActive($value, $onEmptyValue, $lang);
}
return $output;
} | [
"public",
"static",
"function",
"findActiveArray",
"(",
"array",
"$",
"array",
",",
"$",
"onEmptyValue",
"=",
"''",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$... | Find the corresponding element inside an array for the current active language
```php
// assume the default language is `en`
$output = I18n::findActiveArray([
['de' => 'Hallo', 'en' => 'Hello'],
['de' => 'Katze', 'en' => 'Cat'],
]);
var_dump($output); // dump: array('Hello', 'Cat')
```
@param array $fieldValues The array you want to to find the current
@param mixed $onEmptyValue The value you can set when the language could not be found.
@param string $lang The language to return, if no lang is provided, the language resolved trough the admin ui (or user language) is used by default.
@return array | [
"Find",
"the",
"corresponding",
"element",
"inside",
"an",
"array",
"for",
"the",
"current",
"active",
"language"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/helpers/I18n.php#L184-L192 | train |
luyadev/luya-module-admin | src/apis/MenuController.php | MenuController.actionItems | public function actionItems($nodeId)
{
UserOnline::unlock(Yii::$app->adminuser->id);
return Yii::$app->adminmenu->getModuleItems($nodeId);
} | php | public function actionItems($nodeId)
{
UserOnline::unlock(Yii::$app->adminuser->id);
return Yii::$app->adminmenu->getModuleItems($nodeId);
} | [
"public",
"function",
"actionItems",
"(",
"$",
"nodeId",
")",
"{",
"UserOnline",
"::",
"unlock",
"(",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"id",
")",
";",
"return",
"Yii",
"::",
"$",
"app",
"->",
"adminmenu",
"->",
"getModuleItems",
"(",
"... | The items action returns all items for a given node.
@param integer $nodeId The id of the node to find all items from.
@return array | [
"The",
"items",
"action",
"returns",
"all",
"items",
"for",
"a",
"given",
"node",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/apis/MenuController.php#L35-L39 | train |
luyadev/luya-module-admin | src/apis/MenuController.php | MenuController.actionDashboard | public function actionDashboard($nodeId)
{
$data = Yii::$app->adminmenu->getNodeData($nodeId);
$accessList = [];
// verify if no permissions has ben seet for this know or no groups are available trough permissions issues.
if (!isset($data['groups'])) {
return [];
}
foreach ($data['groups'] as $groupkey => $groupvalue) {
foreach ($groupvalue['items'] as $row) {
if ($row['permissionIsApi']) {
try {
$row['alias'] = Yii::t($data['moduleId'], $row['alias'], [], Yii::$app->language);
} catch (\Exception $e) {
}
$accessList[] = $row;
}
}
}
$log = [];
foreach ($accessList as $access) {
$data = (new Query())
->select(['timestamp_create', 'user_id', 'admin_ngrest_log.id', 'is_update', 'is_delete', 'is_insert', 'admin_user.firstname', 'admin_user.lastname'])
->from('{{%admin_ngrest_log}}')
->leftJoin('{{%admin_user}}', '{{%admin_ngrest_log}}.user_id = {{%admin_user}}.id')
->orderBy('timestamp_create DESC')
->limit(30)
->where('api=:api and user_id!=0', [':api' => $access['permissionApiEndpoint']])->all();
foreach ($data as $row) {
$date = mktime(0, 0, 0, date('n', $row['timestamp_create']), date('j', $row['timestamp_create']), date('Y', $row['timestamp_create']));
if ($row['is_update']) {
$message = Module::t('dashboard_log_message_edit', ['container' => $access['alias']]);
} elseif ($row['is_insert']) {
$message = Module::t('dashboard_log_message_add', ['container' => $access['alias']]);
} elseif ($row['is_delete']) {
$message = Module::t('dashboard_log_message_delete', ['container' => $access['alias']]);
}
$log[$date][] = [
'name' => $row['firstname'].' '.$row['lastname'],
'is_update' => $row['is_update'],
'is_insert' => $row['is_insert'],
'is_delete' => $row['is_delete'],
'timestamp' => $row['timestamp_create'],
'alias' => $access['alias'],
'message' => $message,
'icon' => $access['icon'],
];
}
}
$array = [];
krsort($log, SORT_NUMERIC);
foreach ($log as $day => $values) {
$array[] = [
'day' => $day,
'items' => $values,
];
}
return $array;
} | php | public function actionDashboard($nodeId)
{
$data = Yii::$app->adminmenu->getNodeData($nodeId);
$accessList = [];
// verify if no permissions has ben seet for this know or no groups are available trough permissions issues.
if (!isset($data['groups'])) {
return [];
}
foreach ($data['groups'] as $groupkey => $groupvalue) {
foreach ($groupvalue['items'] as $row) {
if ($row['permissionIsApi']) {
try {
$row['alias'] = Yii::t($data['moduleId'], $row['alias'], [], Yii::$app->language);
} catch (\Exception $e) {
}
$accessList[] = $row;
}
}
}
$log = [];
foreach ($accessList as $access) {
$data = (new Query())
->select(['timestamp_create', 'user_id', 'admin_ngrest_log.id', 'is_update', 'is_delete', 'is_insert', 'admin_user.firstname', 'admin_user.lastname'])
->from('{{%admin_ngrest_log}}')
->leftJoin('{{%admin_user}}', '{{%admin_ngrest_log}}.user_id = {{%admin_user}}.id')
->orderBy('timestamp_create DESC')
->limit(30)
->where('api=:api and user_id!=0', [':api' => $access['permissionApiEndpoint']])->all();
foreach ($data as $row) {
$date = mktime(0, 0, 0, date('n', $row['timestamp_create']), date('j', $row['timestamp_create']), date('Y', $row['timestamp_create']));
if ($row['is_update']) {
$message = Module::t('dashboard_log_message_edit', ['container' => $access['alias']]);
} elseif ($row['is_insert']) {
$message = Module::t('dashboard_log_message_add', ['container' => $access['alias']]);
} elseif ($row['is_delete']) {
$message = Module::t('dashboard_log_message_delete', ['container' => $access['alias']]);
}
$log[$date][] = [
'name' => $row['firstname'].' '.$row['lastname'],
'is_update' => $row['is_update'],
'is_insert' => $row['is_insert'],
'is_delete' => $row['is_delete'],
'timestamp' => $row['timestamp_create'],
'alias' => $access['alias'],
'message' => $message,
'icon' => $access['icon'],
];
}
}
$array = [];
krsort($log, SORT_NUMERIC);
foreach ($log as $day => $values) {
$array[] = [
'day' => $day,
'items' => $values,
];
}
return $array;
} | [
"public",
"function",
"actionDashboard",
"(",
"$",
"nodeId",
")",
"{",
"$",
"data",
"=",
"Yii",
"::",
"$",
"app",
"->",
"adminmenu",
"->",
"getNodeData",
"(",
"$",
"nodeId",
")",
";",
"$",
"accessList",
"=",
"[",
"]",
";",
"// verify if no permissions has ... | Get all dashabord items for a given node.
@param integer $nodeId The id of the node to find all items from.
@return array | [
"Get",
"all",
"dashabord",
"items",
"for",
"a",
"given",
"node",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/apis/MenuController.php#L47-L112 | train |
luyadev/luya-module-admin | src/folder/Item.php | Item.hasChild | public function hasChild()
{
return ((new \luya\admin\folder\Query())->where(['is_deleted' => 0, 'parent_id' => $this->getId()])->count() > 0 ? true: false);
} | php | public function hasChild()
{
return ((new \luya\admin\folder\Query())->where(['is_deleted' => 0, 'parent_id' => $this->getId()])->count() > 0 ? true: false);
} | [
"public",
"function",
"hasChild",
"(",
")",
"{",
"return",
"(",
"(",
"new",
"\\",
"luya",
"\\",
"admin",
"\\",
"folder",
"\\",
"Query",
"(",
")",
")",
"->",
"where",
"(",
"[",
"'is_deleted'",
"=>",
"0",
",",
"'parent_id'",
"=>",
"$",
"this",
"->",
... | Whether the current folder has at least one child folder.
@return boolean Whether a child folder exists or not. | [
"Whether",
"the",
"current",
"folder",
"has",
"at",
"least",
"one",
"child",
"folder",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/folder/Item.php#L68-L71 | train |
luyadev/luya-module-admin | src/folder/Item.php | Item.getParent | public function getParent()
{
return (!empty($this->getParentId())) ? Yii::$app->storage->getFolder($this->getParentId()) : false;
} | php | public function getParent()
{
return (!empty($this->getParentId())) ? Yii::$app->storage->getFolder($this->getParentId()) : false;
} | [
"public",
"function",
"getParent",
"(",
")",
"{",
"return",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getParentId",
"(",
")",
")",
")",
"?",
"Yii",
"::",
"$",
"app",
"->",
"storage",
"->",
"getFolder",
"(",
"$",
"this",
"->",
"getParentId",
"(",
... | Get the parent folder object.
@return boolean|\luya\admin\folder\Item The item object or false if not found. | [
"Get",
"the",
"parent",
"folder",
"object",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/folder/Item.php#L78-L81 | train |
luyadev/luya-module-admin | src/storage/ItemAbstract.php | ItemAbstract.getKey | public function getKey($key, $exception = true)
{
if (!array_key_exists($key, $this->_itemArray)) {
if ($exception) {
throw new Exception("Unable to find the requested item key '$key' in item " . var_export($this->_itemArray, true));
} else {
return false;
}
}
return $this->_itemArray[$key];
} | php | public function getKey($key, $exception = true)
{
if (!array_key_exists($key, $this->_itemArray)) {
if ($exception) {
throw new Exception("Unable to find the requested item key '$key' in item " . var_export($this->_itemArray, true));
} else {
return false;
}
}
return $this->_itemArray[$key];
} | [
"public",
"function",
"getKey",
"(",
"$",
"key",
",",
"$",
"exception",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_itemArray",
")",
")",
"{",
"if",
"(",
"$",
"exception",
")",
"{",
"throw",... | Returns a value for a given key inside the itemArray.
@param string $key The requested key.
@param boolean $exception Whether getKey should throw an exception if the key is not found or just return false instead.
@throws Exception If the key is not found inside the array an exception is thrown. If $exception is disabled false is returned instead. | [
"Returns",
"a",
"value",
"for",
"a",
"given",
"key",
"inside",
"the",
"itemArray",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/storage/ItemAbstract.php#L51-L62 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.getWithRelation | public function getWithRelation($actionName)
{
$rel = $this->withRelations();
$expand = Yii::$app->request->get('expand', null);
$relationPrefixes = [];
foreach (StringHelper::explode($expand, ',', true, true) as $relation) {
// check for subrelation dot notation.
$relationPrefixes[] = current(explode(".", $relation));
}
// no expand param found, return empty join with array.
if (empty($relationPrefixes)) {
return [];
}
foreach ($rel as $relationName) {
// it seem to be the advance strucutre for given actions.
if (is_array($relationName) && isset($rel[$actionName])) {
return $this->relationsFromExpand($rel[$actionName], $relationPrefixes);
}
}
// simple structure
return $this->relationsFromExpand($rel, $relationPrefixes);
} | php | public function getWithRelation($actionName)
{
$rel = $this->withRelations();
$expand = Yii::$app->request->get('expand', null);
$relationPrefixes = [];
foreach (StringHelper::explode($expand, ',', true, true) as $relation) {
// check for subrelation dot notation.
$relationPrefixes[] = current(explode(".", $relation));
}
// no expand param found, return empty join with array.
if (empty($relationPrefixes)) {
return [];
}
foreach ($rel as $relationName) {
// it seem to be the advance strucutre for given actions.
if (is_array($relationName) && isset($rel[$actionName])) {
return $this->relationsFromExpand($rel[$actionName], $relationPrefixes);
}
}
// simple structure
return $this->relationsFromExpand($rel, $relationPrefixes);
} | [
"public",
"function",
"getWithRelation",
"(",
"$",
"actionName",
")",
"{",
"$",
"rel",
"=",
"$",
"this",
"->",
"withRelations",
"(",
")",
";",
"$",
"expand",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
"'expand'",
",",
"null",
")... | Get the relations for the corresponding action name.
Since version 1.2.3 it also checks if the $expand get param is provided for the given relations, otherwise
the relation will not be joined trough `with`. This reduces the database querie time.
@param string $actionName The action name like `index`, `list`, `search`, `relation-call`.
@return array An array with relation names.
@since 1.2.2 | [
"Get",
"the",
"relations",
"for",
"the",
"corresponding",
"action",
"name",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L143-L167 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.relationsFromExpand | private function relationsFromExpand(array $relations, array $expandPrefixes)
{
$valid = [];
foreach ($expandPrefixes as $prefix) {
foreach ($relations as $relation) {
if (StringHelper::startsWith($relation, $prefix)) {
$valid[] = $relation;
}
}
}
return $valid;
} | php | private function relationsFromExpand(array $relations, array $expandPrefixes)
{
$valid = [];
foreach ($expandPrefixes as $prefix) {
foreach ($relations as $relation) {
if (StringHelper::startsWith($relation, $prefix)) {
$valid[] = $relation;
}
}
}
return $valid;
} | [
"private",
"function",
"relationsFromExpand",
"(",
"array",
"$",
"relations",
",",
"array",
"$",
"expandPrefixes",
")",
"{",
"$",
"valid",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expandPrefixes",
"as",
"$",
"prefix",
")",
"{",
"foreach",
"(",
"$",
"rel... | Ensure if the expand prefix exists in the relation.
@param array $relations The available relations
@param array $expandPrefixes The available expand relation names
@return array
@since 1.2.3 | [
"Ensure",
"if",
"the",
"expand",
"prefix",
"exists",
"in",
"the",
"relation",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L177-L188 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.prepareListQuery | public function prepareListQuery()
{
/* @var $modelClass \yii\db\BaseActiveRecord */
$modelClass = $this->modelClass;
$find = $modelClass::ngRestFind();
// check if a pool id is requested:
$this->appendPoolWhereCondition($find);
// add tags condition
$tagIds = Yii::$app->request->get('tags');
if ($tagIds) {
$subQuery = clone $find;
$inQuery = $subQuery->joinWith(['tags tags'])->andWhere(['tags.id' => array_unique(explode(",", $tagIds))])->select(['pk_id']);
$find->andWhere(['in', $modelClass::primaryKey(), $inQuery]);
}
return $find->with($this->getWithRelation('list'));
} | php | public function prepareListQuery()
{
/* @var $modelClass \yii\db\BaseActiveRecord */
$modelClass = $this->modelClass;
$find = $modelClass::ngRestFind();
// check if a pool id is requested:
$this->appendPoolWhereCondition($find);
// add tags condition
$tagIds = Yii::$app->request->get('tags');
if ($tagIds) {
$subQuery = clone $find;
$inQuery = $subQuery->joinWith(['tags tags'])->andWhere(['tags.id' => array_unique(explode(",", $tagIds))])->select(['pk_id']);
$find->andWhere(['in', $modelClass::primaryKey(), $inQuery]);
}
return $find->with($this->getWithRelation('list'));
} | [
"public",
"function",
"prepareListQuery",
"(",
")",
"{",
"/* @var $modelClass \\yii\\db\\BaseActiveRecord */",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"modelClass",
";",
"$",
"find",
"=",
"$",
"modelClass",
"::",
"ngRestFind",
"(",
")",
";",
"// check if a pool i... | Prepare the NgRest List Query.
> This will call the `ngRestFind()` method of the model.
Use in list, export
@see {{prepareIndexQuery()}}
@return \yii\db\ActiveQuery
@since 1.2.2 | [
"Prepare",
"the",
"NgRest",
"List",
"Query",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L227-L246 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.findModel | public function findModel($id)
{
$model = $this->findModelClassObject($this->modelClass, $id, 'view');
if (!$model) {
throw new NotFoundHttpException("Unable to find the Model for the given ID");
}
return $model;
} | php | public function findModel($id)
{
$model = $this->findModelClassObject($this->modelClass, $id, 'view');
if (!$model) {
throw new NotFoundHttpException("Unable to find the Model for the given ID");
}
return $model;
} | [
"public",
"function",
"findModel",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"findModelClassObject",
"(",
"$",
"this",
"->",
"modelClass",
",",
"$",
"id",
",",
"'view'",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"throw... | Get the Model for the API based on a given Id.
If not found a NotFoundHttpException will be thrown.
@params integer|string $id The id to performe the findOne() method.
@throws NotFoundHttpException
@return \luya\admin\ngrest\base\NgRestModel | [
"Get",
"the",
"Model",
"for",
"the",
"API",
"based",
"on",
"a",
"given",
"Id",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L363-L372 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.findModelClassObject | public function findModelClassObject($modelClass, $id, $relationContext)
{
$keys = $modelClass::primaryKey();
if (count($keys) > 1) {
$values = explode(',', $id);
if (count($keys) === count($values)) {
return $this->findModelFromCondition(array_combine($keys, $values), $keys, $modelClass, $relationContext);
}
} elseif ($id !== null) {
return $this->findModelFromCondition($id, $keys, $modelClass, $relationContext);
}
return false;
} | php | public function findModelClassObject($modelClass, $id, $relationContext)
{
$keys = $modelClass::primaryKey();
if (count($keys) > 1) {
$values = explode(',', $id);
if (count($keys) === count($values)) {
return $this->findModelFromCondition(array_combine($keys, $values), $keys, $modelClass, $relationContext);
}
} elseif ($id !== null) {
return $this->findModelFromCondition($id, $keys, $modelClass, $relationContext);
}
return false;
} | [
"public",
"function",
"findModelClassObject",
"(",
"$",
"modelClass",
",",
"$",
"id",
",",
"$",
"relationContext",
")",
"{",
"$",
"keys",
"=",
"$",
"modelClass",
"::",
"primaryKey",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"1",
... | Find the model for a given class and id.
@param [type] $modelClass
@param [type] $id
@return void | [
"Find",
"the",
"model",
"for",
"a",
"given",
"class",
"and",
"id",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L382-L395 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionServices | public function actionServices()
{
$this->checkAccess('services');
$settings = [];
$apiEndpoint = $this->model->ngRestApiEndpoint();
$userSortSettings = Yii::$app->adminuser->identity->setting->get('ngrestorder.admin/'.$apiEndpoint, false);
if ($userSortSettings && is_array($userSortSettings)) {
if ($userSortSettings['sort'] == SORT_DESC) {
$order = '-'.$userSortSettings['field'];
} else {
$order = '+'.$userSortSettings['field'];
}
$settings['order'] = $order;
}
$userFilter = Yii::$app->adminuser->identity->setting->get('ngrestfilter.admin/'.$apiEndpoint, false);
if ($userFilter) {
$settings['filterName'] = $userFilter;
}
$modelClass = $this->modelClass;
// check if taggable exists, if yes return all used tags for the
if (ObjectHelper::isTraitInstanceOf($this->model, TaggableTrait::class)) {
$tags = $this->model->findTags();
} else {
$tags = false;
}
return [
'service' => $this->model->getNgRestServices(),
'_tags' => $tags,
'_hints' => $this->model->attributeHints(),
'_settings' => $settings,
'_locked' => [
'data' => UserOnline::find()->select(['lock_pk', 'last_timestamp', 'u.firstname', 'u.lastname', 'u.id'])->joinWith('user as u')->where(['lock_table' => $modelClass::tableName()])->createCommand()->queryAll(),
'userId' => Yii::$app->adminuser->id,
],
];
} | php | public function actionServices()
{
$this->checkAccess('services');
$settings = [];
$apiEndpoint = $this->model->ngRestApiEndpoint();
$userSortSettings = Yii::$app->adminuser->identity->setting->get('ngrestorder.admin/'.$apiEndpoint, false);
if ($userSortSettings && is_array($userSortSettings)) {
if ($userSortSettings['sort'] == SORT_DESC) {
$order = '-'.$userSortSettings['field'];
} else {
$order = '+'.$userSortSettings['field'];
}
$settings['order'] = $order;
}
$userFilter = Yii::$app->adminuser->identity->setting->get('ngrestfilter.admin/'.$apiEndpoint, false);
if ($userFilter) {
$settings['filterName'] = $userFilter;
}
$modelClass = $this->modelClass;
// check if taggable exists, if yes return all used tags for the
if (ObjectHelper::isTraitInstanceOf($this->model, TaggableTrait::class)) {
$tags = $this->model->findTags();
} else {
$tags = false;
}
return [
'service' => $this->model->getNgRestServices(),
'_tags' => $tags,
'_hints' => $this->model->attributeHints(),
'_settings' => $settings,
'_locked' => [
'data' => UserOnline::find()->select(['lock_pk', 'last_timestamp', 'u.firstname', 'u.lastname', 'u.id'])->joinWith('user as u')->where(['lock_table' => $modelClass::tableName()])->createCommand()->queryAll(),
'userId' => Yii::$app->adminuser->id,
],
];
} | [
"public",
"function",
"actionServices",
"(",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'services'",
")",
";",
"$",
"settings",
"=",
"[",
"]",
";",
"$",
"apiEndpoint",
"=",
"$",
"this",
"->",
"model",
"->",
"ngRestApiEndpoint",
"(",
")",
";",
"$... | Service Action provides mutliple CRUD informations.
@return array | [
"Service",
"Action",
"provides",
"mutliple",
"CRUD",
"informations",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L432-L474 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionSearch | public function actionSearch($query = null)
{
$this->checkAccess('search');
if (empty($query)) {
$query = Yii::$app->request->post('query');
}
$find = $this->model->ngRestFullQuerySearch($query);
return new ActiveDataProvider([
'query' => $find->with($this->getWithRelation('search')),
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($this->model->getNgRestConfig()),
]
]);
} | php | public function actionSearch($query = null)
{
$this->checkAccess('search');
if (empty($query)) {
$query = Yii::$app->request->post('query');
}
$find = $this->model->ngRestFullQuerySearch($query);
return new ActiveDataProvider([
'query' => $find->with($this->getWithRelation('search')),
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($this->model->getNgRestConfig()),
]
]);
} | [
"public",
"function",
"actionSearch",
"(",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'search'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"=",
"Yii",
"::",
"$",
"app",
"->",
"... | Generate a response with pagination disabled.
Search querys with Pagination will be handled by this action.
@param string $query The search paramter, if empty post will be used.
@return \yii\data\ActiveDataProvider | [
"Generate",
"a",
"response",
"with",
"pagination",
"disabled",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L484-L501 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.generateSortAttributes | public function generateSortAttributes(Config $config)
{
$sortAttributes = [];
foreach ($config->getPointerPlugins('list') as $plugin) {
$sortAttributes = ArrayHelper::merge($plugin->getSortField(), $sortAttributes);
}
return $sortAttributes;
} | php | public function generateSortAttributes(Config $config)
{
$sortAttributes = [];
foreach ($config->getPointerPlugins('list') as $plugin) {
$sortAttributes = ArrayHelper::merge($plugin->getSortField(), $sortAttributes);
}
return $sortAttributes;
} | [
"public",
"function",
"generateSortAttributes",
"(",
"Config",
"$",
"config",
")",
"{",
"$",
"sortAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"->",
"getPointerPlugins",
"(",
"'list'",
")",
"as",
"$",
"plugin",
")",
"{",
"$",
"sortAttrib... | Generate an array of sortable attribute defintions from a ngrest config object.
@param Config $config The Ngrest Config object
@return array
@since 2.0.0 | [
"Generate",
"an",
"array",
"of",
"sortable",
"attribute",
"defintions",
"from",
"a",
"ngrest",
"config",
"object",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L510-L518 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionRelationCall | public function actionRelationCall($arrayIndex, $id, $modelClass, $query = null)
{
$this->checkAccess('relation-call');
$modelClass = base64_decode($modelClass);
$model = $modelClass::findOne((int) $id);
if (!$model) {
throw new InvalidCallException("Unable to resolve relation call model.");
}
/** @var $relation \luya\admin\ngrest\base\NgRestRelationInterface */
$relation = $model->getNgRestRelationByIndex($arrayIndex);
if (!$relation) {
throw new InvalidCallException("Unable to find the given ng rest relation for this index value.");
}
$find = $relation->getDataProvider();
if ($find instanceof ActiveQuery && !$find->multiple) {
throw new InvalidConfigException("The relation definition must be a hasMany() relation.");
}
if ($find instanceof ActiveQueryInterface) {
$find->with($this->getWithRelation('relation-call'));
}
$this->appendPoolWhereCondition($find);
$targetModel = Yii::createObject(['class' => $relation->getTargetModel()]);
if ($query) {
foreach ($targetModel->getNgRestPrimaryKey() as $pkName) {
$searchQuery = $targetModel->ngRestFullQuerySearch($query)->select([$targetModel->tableName() . '.' . $pkName]);
$find->andWhere(['in', $targetModel->tableName() . '.' . $pkName, $searchQuery]);
}
}
return new ActiveDataProvider([
'query' => $find,
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($targetModel->getNgRestConfig()),
]
]);
} | php | public function actionRelationCall($arrayIndex, $id, $modelClass, $query = null)
{
$this->checkAccess('relation-call');
$modelClass = base64_decode($modelClass);
$model = $modelClass::findOne((int) $id);
if (!$model) {
throw new InvalidCallException("Unable to resolve relation call model.");
}
/** @var $relation \luya\admin\ngrest\base\NgRestRelationInterface */
$relation = $model->getNgRestRelationByIndex($arrayIndex);
if (!$relation) {
throw new InvalidCallException("Unable to find the given ng rest relation for this index value.");
}
$find = $relation->getDataProvider();
if ($find instanceof ActiveQuery && !$find->multiple) {
throw new InvalidConfigException("The relation definition must be a hasMany() relation.");
}
if ($find instanceof ActiveQueryInterface) {
$find->with($this->getWithRelation('relation-call'));
}
$this->appendPoolWhereCondition($find);
$targetModel = Yii::createObject(['class' => $relation->getTargetModel()]);
if ($query) {
foreach ($targetModel->getNgRestPrimaryKey() as $pkName) {
$searchQuery = $targetModel->ngRestFullQuerySearch($query)->select([$targetModel->tableName() . '.' . $pkName]);
$find->andWhere(['in', $targetModel->tableName() . '.' . $pkName, $searchQuery]);
}
}
return new ActiveDataProvider([
'query' => $find,
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($targetModel->getNgRestConfig()),
]
]);
} | [
"public",
"function",
"actionRelationCall",
"(",
"$",
"arrayIndex",
",",
"$",
"id",
",",
"$",
"modelClass",
",",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'relation-call'",
")",
";",
"$",
"modelClass",
"=",
"base64_decode... | Call the dataProvider for a foreign model.
@param mixed $arrayIndex
@param mixed $id
@param string $modelClass The name of the model where the ngRestRelation is defined.
@param string $query An optional query to filter the response for the given search term (since 2.0.0)
@throws InvalidCallException
@return \yii\data\ActiveDataProvider | [
"Call",
"the",
"dataProvider",
"for",
"a",
"foreign",
"model",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L530-L576 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionFilter | public function actionFilter($filterName, $query = null)
{
$this->checkAccess('filter');
$model = $this->model;
$filterName = Html::encode($filterName);
if (!array_key_exists($filterName, $model->ngRestFilters())) {
throw new InvalidCallException("The requested filter '$filterName' does not exists in the filter list.");
}
$find = $model->ngRestFilters()[$filterName];
if ($query) {
foreach ($model->getNgRestPrimaryKey() as $pkName) {
$searchQuery = $model->ngRestFullQuerySearch($query)->select([$model->tableName() . '.' . $pkName]);
$find->andWhere(['in', $model->tableName() . '.' . $pkName, $searchQuery]);
}
}
$this->appendPoolWhereCondition($find);
return new ActiveDataProvider([
'query' => $find,
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($model->getNgRestConfig()),
]
]);
} | php | public function actionFilter($filterName, $query = null)
{
$this->checkAccess('filter');
$model = $this->model;
$filterName = Html::encode($filterName);
if (!array_key_exists($filterName, $model->ngRestFilters())) {
throw new InvalidCallException("The requested filter '$filterName' does not exists in the filter list.");
}
$find = $model->ngRestFilters()[$filterName];
if ($query) {
foreach ($model->getNgRestPrimaryKey() as $pkName) {
$searchQuery = $model->ngRestFullQuerySearch($query)->select([$model->tableName() . '.' . $pkName]);
$find->andWhere(['in', $model->tableName() . '.' . $pkName, $searchQuery]);
}
}
$this->appendPoolWhereCondition($find);
return new ActiveDataProvider([
'query' => $find,
'pagination' => $this->pagination,
'sort' => [
'attributes' => $this->generateSortAttributes($model->getNgRestConfig()),
]
]);
} | [
"public",
"function",
"actionFilter",
"(",
"$",
"filterName",
",",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'filter'",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
";",
"$",
"filterName",
"=",
"Html",
"... | Filter the Api response by a defined Filtername.
@param string $filterName
@param string $query An optional query to filter the response for the given search term (since 2.0.0)
@throws InvalidCallException
@return \yii\data\ActiveDataProvider | [
"Filter",
"the",
"Api",
"response",
"by",
"a",
"defined",
"Filtername",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L586-L616 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionActiveWindowCallback | public function actionActiveWindowCallback()
{
$this->checkAccess('active-window-callback');
$config = $this->model->getNgRestConfig();
$render = new RenderActiveWindowCallback();
$ngrest = new NgRest($config);
return $ngrest->render($render);
} | php | public function actionActiveWindowCallback()
{
$this->checkAccess('active-window-callback');
$config = $this->model->getNgRestConfig();
$render = new RenderActiveWindowCallback();
$ngrest = new NgRest($config);
return $ngrest->render($render);
} | [
"public",
"function",
"actionActiveWindowCallback",
"(",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'active-window-callback'",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"model",
"->",
"getNgRestConfig",
"(",
")",
";",
"$",
"render",
"=",
"new",... | Renders the Callback for an ActiveWindow.
@return string | [
"Renders",
"the",
"Callback",
"for",
"an",
"ActiveWindow",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L623-L632 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionActiveWindowRender | public function actionActiveWindowRender()
{
$this->checkAccess('active-window-render');
// generate ngrest active window
$render = new RenderActiveWindow();
$render->setItemId(Yii::$app->request->getBodyParam('itemId', false));
$render->setActiveWindowHash(Yii::$app->request->getBodyParam('activeWindowHash', false));
// process ngrest render view with config context
$ngrest = new NgRest($this->model->getNgRestConfig());
return [
'content' => $ngrest->render($render),
'icon' => $render->getActiveWindowObject()->getIcon(),
'label' => $render->getActiveWindowObject()->getLabel(),
'title' => $render->getActiveWindowObject()->getTitle(),
'requestDate' => time(),
];
} | php | public function actionActiveWindowRender()
{
$this->checkAccess('active-window-render');
// generate ngrest active window
$render = new RenderActiveWindow();
$render->setItemId(Yii::$app->request->getBodyParam('itemId', false));
$render->setActiveWindowHash(Yii::$app->request->getBodyParam('activeWindowHash', false));
// process ngrest render view with config context
$ngrest = new NgRest($this->model->getNgRestConfig());
return [
'content' => $ngrest->render($render),
'icon' => $render->getActiveWindowObject()->getIcon(),
'label' => $render->getActiveWindowObject()->getLabel(),
'title' => $render->getActiveWindowObject()->getTitle(),
'requestDate' => time(),
];
} | [
"public",
"function",
"actionActiveWindowRender",
"(",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'active-window-render'",
")",
";",
"// generate ngrest active window",
"$",
"render",
"=",
"new",
"RenderActiveWindow",
"(",
")",
";",
"$",
"render",
"->",
"se... | Renders the index page of an ActiveWindow.
@return array | [
"Renders",
"the",
"index",
"page",
"of",
"an",
"ActiveWindow",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L639-L658 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionExport | public function actionExport()
{
$this->checkAccess('export');
$header = Yii::$app->request->getBodyParam('header', 1);
$type = Yii::$app->request->getBodyParam('type');
$attributes = Yii::$app->request->getBodyParam('attributes', []);
$fields = ArrayHelper::getColumn($attributes, 'value');
switch (strtolower($type)) {
case "csv":
$mime = 'application/csv';
$extension = 'csv';
break;
case "xlsx":
$mime = 'application/vnd.ms-excel';
$extension = 'xlsx';
break;
}
$query = $this->prepareListQuery()->select($fields);
$tempData = ExportHelper::$type($query, $fields, (bool) $header);
$key = uniqid('ngrestexport', true);
$store = FileHelper::writeFile('@runtime/'.$key.'.tmp', $tempData);
$menu = Yii::$app->adminmenu->getApiDetail($this->model->ngRestApiEndpoint());
$route = $menu['route'];
$route = str_replace("/index", "/export-download", $route);
if ($store) {
Yii::$app->session->set('tempNgRestFileName', Inflector::slug($this->model->tableName()) . '-export-'.date("Y-m-d-H-i").'.' . $extension);
Yii::$app->session->set('tempNgRestFileMime', $mime);
Yii::$app->session->set('tempNgRestFileKey', $key);
$url = Url::toRoute(['/'.$route], true);
$param = http_build_query(['key' => base64_encode($key), 'time' => time()]);
if (StringHelper::contains('?', $url)) {
$route = $url . "&" . $param;
} else {
$route = $url . "?" . $param;
}
return [
'url' => $route,
];
}
throw new ErrorException("Unable to write the temporary file. Make sure the runtime folder is writeable.");
} | php | public function actionExport()
{
$this->checkAccess('export');
$header = Yii::$app->request->getBodyParam('header', 1);
$type = Yii::$app->request->getBodyParam('type');
$attributes = Yii::$app->request->getBodyParam('attributes', []);
$fields = ArrayHelper::getColumn($attributes, 'value');
switch (strtolower($type)) {
case "csv":
$mime = 'application/csv';
$extension = 'csv';
break;
case "xlsx":
$mime = 'application/vnd.ms-excel';
$extension = 'xlsx';
break;
}
$query = $this->prepareListQuery()->select($fields);
$tempData = ExportHelper::$type($query, $fields, (bool) $header);
$key = uniqid('ngrestexport', true);
$store = FileHelper::writeFile('@runtime/'.$key.'.tmp', $tempData);
$menu = Yii::$app->adminmenu->getApiDetail($this->model->ngRestApiEndpoint());
$route = $menu['route'];
$route = str_replace("/index", "/export-download", $route);
if ($store) {
Yii::$app->session->set('tempNgRestFileName', Inflector::slug($this->model->tableName()) . '-export-'.date("Y-m-d-H-i").'.' . $extension);
Yii::$app->session->set('tempNgRestFileMime', $mime);
Yii::$app->session->set('tempNgRestFileKey', $key);
$url = Url::toRoute(['/'.$route], true);
$param = http_build_query(['key' => base64_encode($key), 'time' => time()]);
if (StringHelper::contains('?', $url)) {
$route = $url . "&" . $param;
} else {
$route = $url . "?" . $param;
}
return [
'url' => $route,
];
}
throw new ErrorException("Unable to write the temporary file. Make sure the runtime folder is writeable.");
} | [
"public",
"function",
"actionExport",
"(",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'export'",
")",
";",
"$",
"header",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'header'",
",",
"1",
")",
";",
"$",
"type",
"=... | Export the Data into a temp CSV.
@return array
@throws ErrorException | [
"Export",
"the",
"Data",
"into",
"a",
"temp",
"CSV",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L666-L717 | train |
luyadev/luya-module-admin | src/ngrest/base/Api.php | Api.actionActiveButton | public function actionActiveButton($hash, $id)
{
$this->checkAccess('active-button');
$model = $this->findModel($id);
return $model->handleNgRestActiveButton($hash);
} | php | public function actionActiveButton($hash, $id)
{
$this->checkAccess('active-button');
$model = $this->findModel($id);
return $model->handleNgRestActiveButton($hash);
} | [
"public",
"function",
"actionActiveButton",
"(",
"$",
"hash",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'active-button'",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"findModel",
"(",
"$",
"id",
")",
";",
"return",
"$",
"m... | Trigger an Active Button handler.
@param string $hash The hash from the class name.
@param string|integer $id
@return void
@since 1.2.3 | [
"Trigger",
"an",
"Active",
"Button",
"handler",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/base/Api.php#L727-L733 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.textInput | public function textInput(array $options = [])
{
$this->element = Angular::text('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function textInput(array $options = [])
{
$this->element = Angular::text('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"textInput",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"text",
"(",
"'{model}'",
",",
"'{label}'",
",",
"[",
"'fieldid'",
"=>",
"$",
"this",
"->",
"form",
"->",
"g... | Text input field
@param array $options Optional data for the text input array.
@return \luya\admin\ngrest\aw\ActiveField | [
"Text",
"input",
"field"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L91-L99 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.passwordInput | public function passwordInput(array $options = [])
{
$this->element = Angular::password('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function passwordInput(array $options = [])
{
$this->element = Angular::password('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"passwordInput",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"password",
"(",
"'{model}'",
",",
"'{label}'",
",",
"[",
"'fieldid'",
"=>",
"$",
"this",
"->",
"form",
"-... | Passwword input field
@param array $options Optional data for the text input array.
@return \luya\admin\ngrest\aw\ActiveField | [
"Passwword",
"input",
"field"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L107-L115 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.dropDownList | public function dropDownList(array $data, array $options = [])
{
$this->element = Angular::select('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function dropDownList(array $data, array $options = [])
{
$this->element = Angular::select('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"dropDownList",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"select",
"(",
"'{model}'",
",",
"'{label}'",
",",
"$",
"data",
",",
"[",
"'fi... | Generate a select dropdown with data as array.
@param array $data
@param array $options
@return \luya\admin\ngrest\aw\ActiveField
@since 1.2.2 | [
"Generate",
"a",
"select",
"dropdown",
"with",
"data",
"as",
"array",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L141-L149 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.checkboxList | public function checkboxList(array $data)
{
$this->element = Angular::checkboxArray('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function checkboxList(array $data)
{
$this->element = Angular::checkboxArray('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"checkboxList",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"checkboxArray",
"(",
"'{model}'",
",",
"'{label}'",
",",
"$",
"data",
",",
"[",
"'fieldid'",
"=>",
"$",
"this",
"->",
"form",
... | Checkbox list input
@param array $data The items
@return ActiveField
@since 2.0.0 | [
"Checkbox",
"list",
"input"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L174-L182 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.radioList | public function radioList(array $data)
{
$this->element = Angular::radio('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function radioList(array $data)
{
$this->element = Angular::radio('{model}', '{label}', $data, [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"radioList",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"radio",
"(",
"'{model}'",
",",
"'{label}'",
",",
"$",
"data",
",",
"[",
"'fieldid'",
"=>",
"$",
"this",
"->",
"form",
"->",
"... | radio list input
@param array $data The items
@return ActiveField
@since 2.0.0 | [
"radio",
"list",
"input"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L191-L199 | train |
luyadev/luya-module-admin | src/ngrest/aw/ActiveWindowFormField.php | ActiveWindowFormField.datetimePicker | public function datetimePicker()
{
$this->element = Angular::datetime('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | php | public function datetimePicker()
{
$this->element = Angular::datetime('{model}', '{label}', [
'fieldid' => $this->form->getFieldId($this->attribute),
'ng-init' => '{initValue}',
]);
return $this;
} | [
"public",
"function",
"datetimePicker",
"(",
")",
"{",
"$",
"this",
"->",
"element",
"=",
"Angular",
"::",
"datetime",
"(",
"'{model}'",
",",
"'{label}'",
",",
"[",
"'fieldid'",
"=>",
"$",
"this",
"->",
"form",
"->",
"getFieldId",
"(",
"$",
"this",
"->",... | date time picker
@return ActiveField
@since 2.0.0 | [
"date",
"time",
"picker"
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/ngrest/aw/ActiveWindowFormField.php#L255-L263 | train |
luyadev/luya-module-admin | src/traits/SoftDeleteTrait.php | SoftDeleteTrait.internalUpdateValues | private static function internalUpdateValues()
{
$update = [];
foreach (static::fieldStateDescriber() as $field => $value) {
$update[$field] = (is_array($value)) ? $value[0] : $value;
}
return $update;
} | php | private static function internalUpdateValues()
{
$update = [];
foreach (static::fieldStateDescriber() as $field => $value) {
$update[$field] = (is_array($value)) ? $value[0] : $value;
}
return $update;
} | [
"private",
"static",
"function",
"internalUpdateValues",
"(",
")",
"{",
"$",
"update",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"fieldStateDescriber",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"update",
"[",
"$",
"fiel... | Evalate the values to update.
@return array | [
"Evalate",
"the",
"values",
"to",
"update",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/traits/SoftDeleteTrait.php#L102-L109 | train |
luyadev/luya-module-admin | src/folder/Query.php | Query.getStorage | public function getStorage()
{
if ($this->_storage === null) {
$this->_storage = Yii::$app->storage;
}
return $this->_storage;
} | php | public function getStorage()
{
if ($this->_storage === null) {
$this->_storage = Yii::$app->storage;
}
return $this->_storage;
} | [
"public",
"function",
"getStorage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_storage",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_storage",
"=",
"Yii",
"::",
"$",
"app",
"->",
"storage",
";",
"}",
"return",
"$",
"this",
"->",
"_storage",
"... | Singleton behavior for storage component getter.
@return \luya\admin\storage\BaseFileSystemStorage | [
"Singleton",
"behavior",
"for",
"storage",
"component",
"getter",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/folder/Query.php#L30-L37 | train |
luyadev/luya-module-admin | src/components/AdminMenu.php | AdminMenu.getMenu | public function getMenu()
{
if ($this->_menu !== null) {
return $this->_menu;
}
$menu = [];
foreach ($this->getAdminModuleMenus() as $menuBuilder) {
// removed legacy support, menu must be instance of AdminmenuBuilderInterface
if (!$menuBuilder instanceof AdminMenuBuilderInterface) {
throw new Exception("admin menu must be instance of AdminMenuBuilderInterface");
}
// call the interface menu method returns the array for the given Module.
$data = $menuBuilder->menu();
$menu = ArrayHelper::merge($data, $menu);
}
$this->_menu = $menu;
return $menu;
} | php | public function getMenu()
{
if ($this->_menu !== null) {
return $this->_menu;
}
$menu = [];
foreach ($this->getAdminModuleMenus() as $menuBuilder) {
// removed legacy support, menu must be instance of AdminmenuBuilderInterface
if (!$menuBuilder instanceof AdminMenuBuilderInterface) {
throw new Exception("admin menu must be instance of AdminMenuBuilderInterface");
}
// call the interface menu method returns the array for the given Module.
$data = $menuBuilder->menu();
$menu = ArrayHelper::merge($data, $menu);
}
$this->_menu = $menu;
return $menu;
} | [
"public",
"function",
"getMenu",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_menu",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_menu",
";",
"}",
"$",
"menu",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAdminModuleMenus... | Return the menu array entries from all registered admin modules.
Response array is organized as follow:
+ Node (Root level menu)
+ Group
+ Items
Example array response:
```php
Array (
[id] => 1, // auto assigned
[moduleId] => admin
[template] =>
[routing] => default
[alias] => menu_node_system
[icon] => layers
[permissionRoute] =>
[permissionIsRoute] =>
[searchModelClass] =>
[groups] => Array ( // Optional
[menu_group_access] => Array (
[name] => menu_group_access
[items] => Array (
[0] => Array (
[alias] => menu_access_item_user
[route] => admin/user/index
[icon] => person
[permissionApiEndpoint] => api-admin-user
[permissionIsRoute] =>
[permissionIsApi] => 1
[searchModelClass] =>
[options] => Array ()
)
[1] => Array (
[alias] => menu_access_item_group
[route] => admin/group/index
[icon] => group
[permissionApiEndpoint] => api-admin-group
[permissionIsRoute] =>
[permissionIsApi] => 1
[searchModelClass] =>
[options] => Array ( )
)
)
)
)
```
@return array | [
"Return",
"the",
"menu",
"array",
"entries",
"from",
"all",
"registered",
"admin",
"modules",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenu.php#L98-L118 | train |
luyadev/luya-module-admin | src/components/AdminMenu.php | AdminMenu.getNodeData | public function getNodeData($id)
{
if (!isset($this->getMenu()[$id])) {
return false;
}
return $this->getMenu()[$id];
} | php | public function getNodeData($id)
{
if (!isset($this->getMenu()[$id])) {
return false;
}
return $this->getMenu()[$id];
} | [
"public",
"function",
"getNodeData",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"getMenu",
"(",
")",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getMenu",
"(",
"... | Get the node for a given array key.
@param integer $id
@return boolean|array | [
"Get",
"the",
"node",
"for",
"a",
"given",
"array",
"key",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenu.php#L126-L133 | train |
luyadev/luya-module-admin | src/components/AdminMenu.php | AdminMenu.getModules | public function getModules()
{
if ($this->_modules !== null) {
return $this->_modules;
}
$responseData = [];
foreach ($this->getMenu() as $item) {
// check if this is an entrie with a permission
if ($item['permissionIsRoute']) {
// verify if the permission is provided for this user:
// if the permission is granted will write inti $responseData,
// if not we continue;
if (!Yii::$app->auth->matchRoute($this->getUserId(), $item['permissionRoute'])) {
continue;
}
}
// this item does have groups
if (isset($item['groups'])) {
$permissionGranted = false;
// see if the groups has items
foreach ($item['groups'] as $groupName => $groupItem) {
if (count($groupItem['items']) > 0) {
if ($permissionGranted) {
continue;
}
foreach ($groupItem['items'] as $groupItemEntry) {
// a previous entry already has solved the question if the permission is granted
if ($permissionGranted) {
continue;
}
if ($groupItemEntry['permissionIsRoute']) {
// when true, set permissionGranted to true
if (Yii::$app->auth->matchRoute($this->getUserId(), $groupItemEntry['route'])) {
$permissionGranted = true;
}
} elseif ($groupItemEntry['permissionIsApi']) {
// when true, set permissionGranted to true
if (Yii::$app->auth->matchApi($this->getUserId(), $groupItemEntry['permissionApiEndpoint'])) {
$permissionGranted = true;
}
} else {
throw new Exception('Menu item detected without permission entry');
}
}
}
}
if (!$permissionGranted) {
continue;
}
}
try {
// check if a translation exists, otherwise use alias instead.
$alias = Yii::t($item['moduleId'], $item['alias'], [], Yii::$app->language);
} catch (\Exception $err) {
$alias = $item['alias'];
}
// ok we have passed all the tests, lets make an entry
$responseData[] = [
'moduleId' => $item['moduleId'],
'id' => $item['id'],
'template' => $item['template'],
'routing' => $item['routing'],
'alias' => $alias,
'icon' => $item['icon'],
'searchModelClass' => $item['searchModelClass'],
];
}
$this->_modules = $responseData;
return $responseData;
} | php | public function getModules()
{
if ($this->_modules !== null) {
return $this->_modules;
}
$responseData = [];
foreach ($this->getMenu() as $item) {
// check if this is an entrie with a permission
if ($item['permissionIsRoute']) {
// verify if the permission is provided for this user:
// if the permission is granted will write inti $responseData,
// if not we continue;
if (!Yii::$app->auth->matchRoute($this->getUserId(), $item['permissionRoute'])) {
continue;
}
}
// this item does have groups
if (isset($item['groups'])) {
$permissionGranted = false;
// see if the groups has items
foreach ($item['groups'] as $groupName => $groupItem) {
if (count($groupItem['items']) > 0) {
if ($permissionGranted) {
continue;
}
foreach ($groupItem['items'] as $groupItemEntry) {
// a previous entry already has solved the question if the permission is granted
if ($permissionGranted) {
continue;
}
if ($groupItemEntry['permissionIsRoute']) {
// when true, set permissionGranted to true
if (Yii::$app->auth->matchRoute($this->getUserId(), $groupItemEntry['route'])) {
$permissionGranted = true;
}
} elseif ($groupItemEntry['permissionIsApi']) {
// when true, set permissionGranted to true
if (Yii::$app->auth->matchApi($this->getUserId(), $groupItemEntry['permissionApiEndpoint'])) {
$permissionGranted = true;
}
} else {
throw new Exception('Menu item detected without permission entry');
}
}
}
}
if (!$permissionGranted) {
continue;
}
}
try {
// check if a translation exists, otherwise use alias instead.
$alias = Yii::t($item['moduleId'], $item['alias'], [], Yii::$app->language);
} catch (\Exception $err) {
$alias = $item['alias'];
}
// ok we have passed all the tests, lets make an entry
$responseData[] = [
'moduleId' => $item['moduleId'],
'id' => $item['id'],
'template' => $item['template'],
'routing' => $item['routing'],
'alias' => $alias,
'icon' => $item['icon'],
'searchModelClass' => $item['searchModelClass'],
];
}
$this->_modules = $responseData;
return $responseData;
} | [
"public",
"function",
"getModules",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_modules",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_modules",
";",
"}",
"$",
"responseData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"ge... | Returns an Array with modules and checks the permission for those.
Example Response:
```php
Array (
'moduleId' => 'admin',
'id' => 1,
'template' => $item['template'],
'routing' => $item['routing'],
'alias' => $alias,
'icon' => $item['icon'],
'searchModelClass' => $item['searchModelClass'],
)
```
@throws Exception
@return array Returns an array with all modules you have permission for. | [
"Returns",
"an",
"Array",
"with",
"modules",
"and",
"checks",
"the",
"permission",
"for",
"those",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenu.php#L157-L236 | train |
luyadev/luya-module-admin | src/components/AdminMenu.php | AdminMenu.getItems | public function getItems()
{
if ($this->_items !== null) {
return $this->_items;
}
$data = [];
foreach ($this->getModules() as $node) {
foreach (ArrayHelper::getValue($this->getModuleItems($node['id']), 'groups', []) as $groupValue) {
foreach ($groupValue['items'] as $array) {
$array['module'] = $node;
$data[] = $array;
}
}
}
$this->_items = $data;
return $data;
} | php | public function getItems()
{
if ($this->_items !== null) {
return $this->_items;
}
$data = [];
foreach ($this->getModules() as $node) {
foreach (ArrayHelper::getValue($this->getModuleItems($node['id']), 'groups', []) as $groupValue) {
foreach ($groupValue['items'] as $array) {
$array['module'] = $node;
$data[] = $array;
}
}
}
$this->_items = $data;
return $data;
} | [
"public",
"function",
"getItems",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_items",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_items",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModules",
"... | Get all items for all nodes.
@return array | [
"Get",
"all",
"items",
"for",
"all",
"nodes",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenu.php#L322-L341 | train |
luyadev/luya-module-admin | src/components/AdminMenu.php | AdminMenu.getApiDetail | public function getApiDetail($api, $pool = null)
{
$items = $this->getItems();
if ($pool) {
$items = ArrayHelper::searchColumns($items, 'pool', $pool);
}
$items = array_values($items); // reset keys to fix isset error
return ArrayHelper::searchColumn($items, 'permissionApiEndpoint', $api);
} | php | public function getApiDetail($api, $pool = null)
{
$items = $this->getItems();
if ($pool) {
$items = ArrayHelper::searchColumns($items, 'pool', $pool);
}
$items = array_values($items); // reset keys to fix isset error
return ArrayHelper::searchColumn($items, 'permissionApiEndpoint', $api);
} | [
"public",
"function",
"getApiDetail",
"(",
"$",
"api",
",",
"$",
"pool",
"=",
"null",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"getItems",
"(",
")",
";",
"if",
"(",
"$",
"pool",
")",
"{",
"$",
"items",
"=",
"ArrayHelper",
"::",
"searchColumn... | Return all informations about a menu point based on the api endpoint name.
@param string $api The Api Endpoint
@return array|boolean | [
"Return",
"all",
"informations",
"about",
"a",
"menu",
"point",
"based",
"on",
"the",
"api",
"endpoint",
"name",
"."
] | 58ddcefc96df70af010076216e43a78dd2bc61db | https://github.com/luyadev/luya-module-admin/blob/58ddcefc96df70af010076216e43a78dd2bc61db/src/components/AdminMenu.php#L349-L358 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.