[xoops-cvslog 1346] CVS update: xoops2jp/html/modules/user/admin/class

Back to archive index

Minahito minah****@users*****
2005年 12月 24日 (土) 19:11:07 JST


Index: xoops2jp/html/modules/user/admin/class/Permission.class.php
diff -u xoops2jp/html/modules/user/admin/class/Permission.class.php:1.1.2.1 xoops2jp/html/modules/user/admin/class/Permission.class.php:1.1.2.2
--- xoops2jp/html/modules/user/admin/class/Permission.class.php:1.1.2.1	Thu Dec 22 20:26:01 2005
+++ xoops2jp/html/modules/user/admin/class/Permission.class.php	Sat Dec 24 19:11:07 2005
@@ -8,7 +8,7 @@
 {
 	var $mGroupId;
 	var $mName;
-	var $mValue;
+	var $mValue = USER_PERMISSION_NONE;
 
 	/**
 	 * User_PermissionItem
@@ -22,15 +22,76 @@
 		$this->_load();
 	}
 	
+	function getId()
+	{
+		return $this->mItem->getId();
+	}
+	
+	function setValue($value)
+	{
+		$value = intval($value);
+		if ($value >= USER_PERMISSION_NONE && $value <= USER_PERMISSION_ADMIN) {
+			$this->mValue = $value;
+		}
+	}
+
 	function _load()
 	{
 		$this->mValue = $this->mItem->loadPermission($this->mGroupId);
 	}
+
+	/**
+	 * Save a permission to database.
+	 */
+	function save()
+	{
+		$gpermHandler =& xoops_gethandler('groupperm');
+
+		if ($this->mValue & USER_PERMISSION_READ) {
+			$name = $this->mItem->getReadPermName();
+			if ($name) {
+				$gperm =& $this->_createGperm($name);
+				if (!$gpermHandler->insert($gperm))
+					return false;
+			}
+		}
+
+		if ($this->mValue & USER_PERMISSION_ADMIN) {
+			$name = $this->mItem->getAdminPermName();
+			if ($name) {
+				$gperm =& $this->_createGperm($name);
+				if (!$gpermHandler->insert($gperm))
+					return false;
+			}
+		}
+		
+		return true;
+	}
+
+	function _createGperm($gperm_name = null)
+	{
+		$gpermHandler =& xoops_gethandler('groupperm');
+		$gperm =& $gpermHandler->create();
+		
+		$gperm->setVar('gperm_groupid', $this->mGroupId);
+		$gperm->setVar('gperm_itemid', $this->getId());
+		$gperm->setVar('gperm_modid', 1);
+		$gperm->setVar('gperm_name', $gperm_name);
+		
+		return $gperm;
+	}
 }
 
 class User_PermissionItem
 {
 	/**
+	 * @return int
+	 */
+	function getId()
+	{
+	}
+
+	/**
 	 * Return name
 	 */
 	function getName()
@@ -54,6 +115,22 @@
 	function loadPermission($groupId)
 	{
 	}
+	
+	/**
+	 * @return string
+	 */
+	function getReadPermName()
+	{
+		return null;
+	}
+
+	/**
+	 * @return string
+	 */
+	function getAdminPermName()
+	{
+		return null;
+	}
 }
 
 class User_PermissionModuleItem extends User_PermissionItem
@@ -65,6 +142,11 @@
 		$this->mModule =& $module;
 	}
 	
+	function getId()
+	{
+		return $this->mModule->getVar('mid');
+	}
+
 	function getName()
 	{
 		return $this->mModule->getProperty('name');
@@ -94,6 +176,16 @@
 
 		return $ret;
 	}
+
+	function getReadPermName()
+	{
+		return "module_read";
+	}
+
+	function getAdminPermName()
+	{
+		return "module_admin";
+	}
 }
 
 class User_PermissionBlockItem extends User_PermissionItem
@@ -105,6 +197,11 @@
 		$this->mBlock =& $block;
 	}
 	
+	function getId()
+	{
+		return $this->mBlock->getVar('bid');
+	}
+	
 	function getName()
 	{
 		return $this->mBlock->getProperty('title');
@@ -130,6 +227,63 @@
 
 		return $ret;
 	}
+
+	
+	function getReadPermName()
+	{
+		return "block_read";
+	}
+}
+
+/**
+ * This class exists for X2 system module.
+ */
+class User_PermissionSystemAdminItem extends User_PermissionItem
+{
+	var $mId;
+	var $mName;
+	
+	function User_PermissionSystemAdminItem($id, $name)
+	{
+		$this->mId = $id;
+		$this->mName = $name;
+	}
+
+	function getId()
+	{
+		return $this->mId;
+	}
+
+	function getName()
+	{
+		return $this->mName;
+	}
+	
+	function getAdminUrl()
+	{
+	}
+	
+	function isActive()
+	{
+		return true;
+	}
+
+	function loadPermission($groupId)
+	{
+		$ret = USER_PERMISSION_NONE;
+
+		$gpermHandler =& xoops_gethandler('groupperm');
+		if ($gpermHandler->checkRight("system_admin", $this->mId, $groupId)) {
+			$ret |= USER_PERMISSION_ADMIN;
+		}
+		
+		return $ret;
+	}
+
+	function getAdminPermName()
+	{
+		return "system_admin";
+	}
 }
 
 ?>
\ No newline at end of file


xoops-cvslog メーリングリストの案内
Back to archive index