<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Library_Icon extends vB_Library { private $iconTypeInfo = [ 'avatar' => [ 'type' => 'avatar', 'typeplural' => 'avatars', 'catid' => 1, ], 'icon' => [ 'type' => 'post_icon', 'typeplural' => 'post_icons', 'catid' => 2, ], 'smilie' => [ 'type' => 'smilie', 'typeplural' => 'smilies', 'catid' => 3, ], ]; public function setCategoryPermissions($categoryid, $permissions) { $db = vB::getDbAssertor(); $categoryinfo = $db->getRow('vBForum:imagecategory', [ 'imagecategoryid' => $categoryid, vB_dB_Query::COLUMNS_KEY => ['imagetype'], ]); if(!$categoryinfo) { throw new vB_Exception_Api('invalid_data_w_x_y_z', [$categoryid, 'categoryid', __CLASS__, __FUNCTION__]); } if ($categoryinfo['imagetype'] == 3) { throw new vB_Exception_Api('smilie_categories_dont_support_permissions'); } $insert = []; foreach($permissions AS $usergroupid => $canuse) { $usergroupid = intval($usergroupid); if (!$canuse) { $insert[] = [$categoryid, $usergroupid]; } } $db->delete('vBForum:imagecategorypermission', [ 'imagecategoryid' => $categoryid, 'usergroupid' => array_keys($permissions), ]); if($insert) { $db->assertQuery('vBForum:imagecategorypermission',[ vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_MULTIPLEINSERT, vB_dB_Query::FIELDS_KEY => ['imagecategoryid', 'usergroupid'], vB_dB_Query::VALUES_KEY => $insert, ]); } } public function getIconTypeInfo($type) { $result = $this->iconTypeInfo[$type] ?? null; if($result) { return $result; } throw new vB_Exception_Api('invalid_table_specified'); } } 