method import documentation in bbn\Appui\Option

Insert into the option table an exported array of options

Example

function(array $options, $id_parent = NULL, array &$todo = NULL) { if (is_array($id_parent)) { $id_parent = $this->fromCode($id_parent); } elseif (null === $id_parent) { $id_parent = $this->default; } if (!empty($options) && $this->check() && $this->exists($id_parent)) { $c =& $this->fields; $num = 0; $is_root = false; if ($todo === null) { $is_root = true; $todo = []; } if (!isset($options[0])) { $options = [$options]; } if (X::isAssoc($options)) { $options = [$options]; } foreach ($options as $o) { $tmp = []; $items = []; /** @todo Temp solution */ if (!is_array($o)) { continue; } if (isset($o[$c['id']])) { if ($this->exists($o[$c['id']])) { unset($o[$c['id']]); } } $o[$c['id_parent']] = $id_parent ?: $this->default; if (isset($o['items'])) { $items = $o['items'] ?: null; unset($o['items']); } if (isset($o[$c['id_alias']])) { $tmp['id_alias'] = $o[$c['id_alias']]; unset($o[$c['id_alias']]); } if (isset($o[$c['cfg']]) && !empty($o[$c['cfg']]['id_root_alias'])) { $tmp['id_root_alias'] = $o[$c['cfg']]['id_root_alias']; unset($o[$c['cfg']]['id_root_alias']); } if ($id = $this->add($o, true)) { if (!empty($tmp)) { $todo[$id] = $tmp; } $num++; if (!empty($items)) { $num += $this->import($items, $id, $todo); } } else { X::log($o); throw new \Exception(X::_("Error while importing: impossible to add")); } } if ($is_root && !empty($todo)) { foreach ($todo as $id => $td) { if (!empty($td['id_alias'])) { if ($id_alias = $this->fromCode(...$td['id_alias'])) { try { $this->setAlias($id, $id_alias); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } else { X::log($td['id_alias']); throw new \Exception( X::_( "Error while importing: impossible to set the alias %s", json_encode($td['id_alias'], JSON_PRETTY_PRINT) ) ); } } if (!empty($td['id_root_alias']) && ($id_root_alias = $this->fromCode(...$td['id_root_alias'])) ) { $this->setcfg($id, ['id_root_alias' => $id_root_alias], true); } } } return $num; } return null; }

Insert into the option table an exported array of options BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.