* @package MCMS\System */ class DBHelper { /** * Creates the global name for a module table. * * This method creates the common prefixed table name from the local table info. * * @param string $mod * the module identifier * @param mixed $info * the table information, string or TableInfo * @return string the table name */ public static function buildModTableName($mod, $info) { return 'm_' . str_replace('.', '#', $mod) . '_' . (is_object($info) ? $info->getName() : $info); } public static function globalizeModRefs($mod, &$info) { if ($info instanceof ViewInfo) return; // TODO: check if this is correct $refs = $info->getRefs(); /** * @var $ref RefInfo */ foreach($refs as $name=>$ref) { $tblName = self::buildModTableName($mod, $ref->getRefTable()); $info->setRef($name, $tblName, $ref->getRefColumns()); } } /** * Creates the global name for a plugin table. * * This method creates the common prefixed table name from the local table info. * * @param string $pi * the module identifier * @param mixed $info * the table information, string or TableInfo * @return string the table name */ public static function buildPluginTableName($pi, $info) { if (empty($info)) throw new \InvalidArgumentException("info is empty"); return 'pi_' . strtolower(str_replace('.', '#', $pi)) . '_' . (is_object($info) ? $info->getName() : $info); } public static function globalizePluginRefs($pi, &$info) { $refs = $info->getRefs(); /** * @var $ref RefInfo */ foreach($refs as $name=>$ref) { $tblName = self::buildPluginTableName($pi, $ref->getRefTable()); $info->setRef($name, $tblName, $ref->getRefColumns()); } } }