/** * Adds a permission to the permissions system. The permission must first * be created with newPermission(), and have any initial users added to * it, before this function is called. * * @param Horde_Perms_Permission_Sql $perm The perm object. * * @return integer Permission ID in the database. * @throws Horde_Perms_Exception */ public function addPermission(Horde_Perms_Permission $perm) { $name = $perm->getName(); if (empty($name)) { throw new Horde_Perms_Exception('Permission name must be non-empty.'); } $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name); $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name); // remove root from the name $root = Horde_Perms::ROOT . ':'; if (substr($name, 0, strlen($root)) == $root) { $name = substr($name, strlen($root)); } // build parents $parents = ''; if (($pos = strrpos($name, ':')) !== false) { $parent_name = substr($name, 0, $pos); $query = 'SELECT perm_id, perm_parents FROM ' . $this->_params['table'] . ' WHERE perm_name = ?'; $result = $this->_db->selectOne($query, array($parent_name)); if (empty($result)) { throw new Horde_Perms_Exception(Horde_Perms_Translation::t("Trying to create sub permission of non-existent parent permission. Create parent permission(s) first.")); } $parents = $result['perm_parents'] . ':' . $result['perm_id']; } $query = 'INSERT INTO ' . $this->_params['table'] . ' (perm_name, perm_parents) VALUES (?, ?)'; try { $id = $this->_db->insert($query, array($name, $parents)); } catch (Horde_Db_Exception $e) { throw new Horde_Perms_Exception($e); } $perm->setId($id); $perm->save(); return $id; }
/** * Returns an hash of the available permissions. * * @return array The available permissions as a hash. */ public static function getPermsArray() { return array(self::SHOW => Horde_Perms_Translation::t("Show"), self::READ => Horde_Perms_Translation::t("Read"), self::EDIT => Horde_Perms_Translation::t("Edit"), self::DELETE => Horde_Perms_Translation::t("Delete")); }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Perms'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Perms/locale'; return parent::ngettext($singular, $plural, $number); }