<?php
 class vB_Library_Prefix extends vB_Library { public function buildDatastore() { $db = vB::getDbAssertor(); $prefixes = []; $set = $db->select('vBForum:prefix', [], ['displayorder'], ['prefixsetid', 'prefixid']); foreach ($set AS $row) { $prefixes[$row['prefixsetid']][] = $row['prefixid']; } $prefixRestrictions = []; $set = $db->select('vBForum:prefixpermission', []); foreach ($set AS $row) { $prefixRestrictions[$row['prefixid']][] = $row['usergroupid']; } $channelPrefixset = []; $set = $db->assertQuery('vBForum:getChannelPrefixset', []); foreach ($set AS $row) { if (isset($prefixes[$row['prefixsetid']])) { $channelPrefixset[$row['nodeid']][] = $row['prefixsetid']; } } $data = [ 'prefixes' => $prefixes, 'restrictions' => $prefixRestrictions, 'channelPrefixset' => $channelPrefixset, ]; vB::getDatastore()->build('prefixcache', serialize($data), 1); return $data; } public function prefixExists($prefixid) { $data = $this->getPrefixData(); foreach ($data['prefixes'] AS $prefixes) { if (in_array($prefixid, $prefixes)) { return true; } } return false; } public function channelHasPrefix($nodeid) { $data = $this->getPrefixData(); foreach (($data['channelPrefixset'][$nodeid] ?? []) AS $prefixSetId) { if (!empty($data['prefixes'][$prefixSetId])) { return true; } } return false; } public function deletePrefixSet($prefixsetids) { $db = vB::getDbAssertor(); if (!is_array($prefixsetids)) { $prefixsetids = [$prefixsetids]; } $setfilter = ['prefixsetid' => $prefixsetids]; $db->delete('vBForum:prefixset', $setfilter); $db->delete('vBForum:channelprefixset', $setfilter); $phrases = []; foreach ($prefixsetids AS $prefixsetid) { $phrases[] = 'prefixset_' . $prefixsetid . '_title'; } $prefixes = $db->getColumn('vBForum:prefix', 'prefixid', $setfilter); foreach ($prefixes AS $prefixid) { $phrases[] = 'prefix_' . $prefixid . '_title_plain'; $phrases[] = 'prefix_' . $prefixid . '_title_rich'; } vB_Library::instance('phrase')->deleteByVarname($phrases); $db->update('vBForum:node', ['prefixid' => ''], ['prefixid' => $prefixes]); $db->delete('vBForum:prefixpermission', ['prefixid' => $prefixes]); $db->delete('vBForum:prefix', $setfilter); $this->buildDatastore(); } public function deletePrefix($prefixids) { $db = vB::getDbAssertor(); if (!is_array($prefixids)) { $prefixids = [$prefixids]; } $prefixfilter = ['prefixid' => $prefixids]; $db->delete('vBForum:prefix', $prefixfilter); $db->update('vBForum:node', ['prefixid' => ''], $prefixfilter); $db->delete('vBForum:prefixpermission', $prefixfilter); $phrases = []; foreach ($prefixids AS $prefixid) { $phrases[] = 'prefix_' . $prefixid . '_title_plain'; $phrases[] = 'prefix_' . $prefixid . '_title_rich'; } vB_Library::instance('phrase')->deleteByVarname($phrases); $this->buildDatastore(); } public function getPrefixData() { $prefixes = vB::getDatastore()->getValue('prefixcache'); if (is_null($prefixes)) { $prefixes = $this->buildDatastore(); } return $prefixes; } } 