method copy documentation in bbn\User\Manager

function(string $type, string $id, array $data) { $pref = Preferences::getPreferences(); $cfg = $pref->getClassCfg(); switch ($type) { case 'user': if ($src = $this->getUser($id)) { $data = X::mergeArrays($src, $data); unset($data[$this->class_cfg['arch']['users']['id']]); $col = $cfg['arch']['user_options']['id_user']; $id_new = $this->add($data); } break; case 'group': if ($src = $this->getGroup($id)) { $data = X::mergeArrays($src, $data); unset($data[$this->class_cfg['arch']['groups']['id']]); $col = $cfg['arch']['user_options']['id_group']; $id_new = $this->groupInsert($data); } break; } if (!empty($id_new)) { if ($options = $this->getOptions($type, $id)) { $ids = []; foreach ($options as $o) { $old_id = $o['id']; unset($o['id']); $o[$col] = $id_new; if ($this->db->insertIgnore($cfg['table'], $o)) { $ids[$old_id] = $this->db->lastId(); } } $bids = []; foreach ($ids as $oid => $nid) { $bits = $this->db->rselectAll( $cfg['tables']['user_options_bits'], [], [ $cfg['arch']['user_options_bits']['id_user_option'] => $oid, $cfg['arch']['user_options_bits']['id_parent'] => null ] ); foreach ($bits as $bit) { $old_id = $bit[$cfg['arch']['user_options_bits']['id']]; unset($bit[$cfg['arch']['user_options_bits']['id']]); $bit[$cfg['arch']['user_options_bits']['id_user_option']] = $nid; $this->db->insert($cfg['tables']['user_options_bits'], $bit); $bids[$old_id] = $this->db->lastId(); } } $remaining = -1; $before = 0; $done = []; while ($remaining && ($before !== $remaining)) { if ($remaining === -1) { $before = 0; } else { $before = $remaining; } $remaining = 0; foreach ($ids as $oid => $nid) { if (in_array($nid, $done)) { continue; } $bits = $this->db->rselectAll( $cfg['tables']['user_options_bits'], [], [ $cfg['arch']['user_options_bits']['id_user_option'] => $oid, [$cfg['arch']['user_options_bits']['id_parent'], 'isnotnull'] ] ); if (!count($bits)) { $done[] = $nid; continue; } foreach ($bits as $bit) { $old_id = $bit[$cfg['arch']['user_options_bits']['id']]; if (isset($bids[$old_id])) { continue; } if (!isset($bids[$bit[$cfg['arch']['user_options_bits']['id_parent']]])) { $remaining++; } else { unset($bit[$cfg['arch']['user_options_bits']['id']]); $bit[$cfg['arch']['user_options_bits']['id_user_option']] = $nid; $bit[$cfg['arch']['user_options_bits']['id_parent']] = $bids[$bit[$cfg['arch']['user_options_bits']['id_parent']]]; $this->db->insert($cfg['tables']['user_options_bits'], $bit); $bids[$old_id] = $this->db->lastId(); } } } } } return $id_new; } return null; }

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.