<?php

namespace Entity;

class ModuleHook extends ModelBase
{
    protected function install()
    {
        $dbPrefix = $this->getDbPrefix();
        $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}modulehook` (
            `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
            `module_id` INTEGER(11) UNSIGNED NOT NULL,
            `hookName` VARCHAR(32) NOT NULL,
            `hookPosition` INTEGER(11) NOT NULL,
            FOREIGN KEY (`module_id`) REFERENCES `{$dbPrefix}module`(id),
            UNIQUE(`module_id`, `hookName`)
        )");
        if ($result === false)
            throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
        return true;
    }

    public static function getModules($moduleIds)
    {
        $fetcher = new self();
        return $fetcher->selects(array("module_id" => $moduleIds), array("hookName", "hookPosition"));
    }
}

