⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gacl_api.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		}		$this->debug_text("get_object_data(): Group does not exist.");		return false;	}	/**	 * get_group_parent_id()	 *	 * Grabs the parent_id of a given group	 *	 * @return int Parent ID of the Group	 *	 * @param int Group ID #	 * @param string Group Type, either 'ARO' or 'AXO'	 */	function get_group_parent_id($id, $group_type='ARO') {		$this->debug_text("get_group_parent_id(): ID: $id Group Type: $group_type");		switch(strtolower(trim($group_type))) {			case 'axo':				$table = $this->_db_table_prefix .'axo_groups';				break;			default:				$table = $this->_db_table_prefix .'aro_groups';				break;		}		if (empty($id) ) {			$this->debug_text("get_group_parent_id(): ID ($id) is empty, this is required");			return false;		}		$query = 'SELECT parent_id FROM '. $table .' WHERE id='. (int) $id;		$rs = $this->db->Execute($query);		if (!is_object($rs)) {			$this->debug_db('get_group_parent_id');			return false;		}		$row_count = $rs->RecordCount();		if ($row_count > 1) {			$this->debug_text("get_group_parent_id(): Returned $row_count rows, can only return one. Please make your names unique.");			return false;		}		if ($row_count == 0) {			$this->debug_text("get_group_parent_id(): Returned $row_count rows");			return false;		}		$row = $rs->FetchRow();		//Return the ID.		return $row[0];	}	/**	 * get_root_group_id ()	 *	 * Grabs the id of the root group for the specified tree	 *	 * @return int Root Group ID #	 *	 * @param string Group Type, either 'ARO' or 'AXO'	 */	function get_root_group_id($group_type='ARO') {		$this->debug_text('get_root_group_id(): Group Type: '. $group_type);		switch (strtolower($group_type)) {			case 'axo':				$table = $this->_db_table_prefix .'axo_groups';				break;			case 'aro':				$table = $this->_db_table_prefix .'aro_groups';				break;			default:				$this->debug_text('get_root_group_id(): Invalid Group Type: '. $group_type);				return FALSE;		}		$query = 'SELECT id FROM '. $table .' WHERE parent_id=0';		$rs = $this->db->Execute($query);		if (!is_object($rs)) {			$this->debug_db('get_root_group_id');			return FALSE;		}		$row_count = $rs->RecordCount();		switch ($row_count) {			case 1:				$row = $rs->FetchRow();				// Return the ID.				return $row[0];			case 0:				$this->debug_text('get_root_group_id(): Returned 0 rows, you do not have a root group defined yet.');				return FALSE;		}		$this->debug_text('get_root_group_id(): Returned '. $row_count .' rows, can only return one. Your tree is very broken.');		return FALSE;	}	/*======================================================================*\		Function:	map_path_to_root()		Purpose:	Maps a unique path to root to a specific group. Each group can only have						one path to root.	\*======================================================================*/	/** REMOVED **/	/*======================================================================*\		Function:	put_path_to_root()		Purpose:	Writes the unique path to root to the database. There should really only be						one path to root for each level "deep" the groups go. If the groups are branched						10 levels deep, there should only be 10 unique path to roots. These of course						overlap each other more and more the closer to the root/trunk they get.	\*======================================================================*/	/** REMOVED **/	/*======================================================================*\		Function:	clean_path_to_root()		Purpose:	Cleans up any paths that are not being used.	\*======================================================================*/	/** REMOVED **/	/*======================================================================*\		Function:	get_path_to_root()		Purpose:	Generates the path to root for a given group.	\*======================================================================*/	/** REMOVED **/	/**	 * add_group()	 *	 * Inserts a group, defaults to be on the "root" branch.	 *	 * Since v3.3.x you can only create one group with Parent_ID=0	 * So, its a good idea to create a "Virtual Root" group with Parent_ID=0	 * Then assign other groups to that.	 *	 * @return int New Group ID # if successful, FALSE if otherwise.	 *	 * @param string Group Value	 * @param string Group Name	 * @param int Parent Group ID #	 * @param string Group Type, either 'ARO' or 'AXO'	 */	function add_group($value, $name, $parent_id=0, $group_type='ARO') {		switch(strtolower(trim($group_type))) {			case 'axo':				$group_type = 'axo';				$table = $this->_db_table_prefix .'axo_groups';				break;			default:				$group_type = 'aro';				$table = $this->_db_table_prefix .'aro_groups';				break;		}		$this->debug_text("add_group(): Name: $name Value: $value Parent ID: $parent_id Group Type: $group_type");		$name = trim($name);		$value = trim($value);		if ( $name == '' ) {			$this->debug_text("add_group(): name ($name) OR parent id ($parent_id) is empty, this is required");			return false;		}		//This has to be outside the transaction, because the first time it is run, it will say the sequence		//doesn't exist. Then try to create it, but the transaction will already by aborted by then.		$insert_id = $this->db->GenID($table.'_id_seq', $this->_defaultGenID( $table ));		if ( $value === '' ) {			$value = $insert_id;		}		$this->db->BeginTrans();		// special case for root group		if ($parent_id == 0) {			// check a root group is not already defined			$query = 'SELECT id FROM '. $table .' WHERE parent_id=0';			$rs = $this->db->Execute($query);			if (!is_object($rs)) {				$this->debug_db('add_group');				$this->db->RollBackTrans();				return FALSE;			}			if ($rs->RowCount() > 0) {				$this->debug_text('add_group (): A root group already exists.');				$this->db->RollBackTrans();				return FALSE;			}			$parent_lft = 0;			$parent_rgt = 1;		} else {			if (empty($parent_id)) {				$this->debug_text("add_group (): parent id ($parent_id) is empty, this is required");				$this->db->RollbackTrans();				return FALSE;			}			// grab parent details from database			$query = 'SELECT id, lft, rgt FROM '. $table .' WHERE id='. (int) $parent_id;			$row = $this->db->GetRow($query);			if (!is_array($row)) {				$this->debug_db('add_group');				$this->db->RollBackTrans();				return FALSE;			}			if (empty($row)) {				$this->debug_text('add_group (): Parent ID: '. $parent_id .' not found.');				$this->db->RollBackTrans();				return FALSE;			}			$parent_lft = &$row[1];			$parent_rgt = &$row[2];			// make room for the new group			$query  = 'UPDATE '. $table .' SET rgt=rgt+2 WHERE rgt>='. (int) $parent_rgt;			$rs = $this->db->Execute($query);			if (!is_object($rs)) {				$this->debug_db('add_group');				$this->db->RollBackTrans();				return FALSE;			}			$query  = 'UPDATE '. $table .' SET lft=lft+2 WHERE lft>'. $parent_rgt;			$rs = $this->db->Execute($query);			if (!is_object($rs)) {				$this->debug_db('add_group');				$this->db->RollBackTrans();				return FALSE;			}		}		$query = 'INSERT INTO '. $table .' (id,parent_id,name,value,lft,rgt) VALUES ('. $insert_id .','. $parent_id .','. $this->db->quote($name) .','. $this->db->quote($value) .','. $parent_rgt .','. ($parent_rgt + 1) .')';		$rs = $this->db->Execute($query);		if (!is_object($rs)) {			$this->debug_db('add_group');			$this->db->RollBackTrans();			return FALSE;		}		$this->db->CommitTrans();		// Joomla/MySQL		$insert_id = $this->db->insertid();		$this->debug_text('add_group (): Added group as ID: '. $insert_id);		return $insert_id;	}	/**	 * get_group_objects()	 *	 * Gets all objects assigned to a group.	 *	 * If $option == 'RECURSE' it will get all objects in child groups as well.	 * defaults to omit child groups.	 *	 * @return array Associative array, item={Section Value}, key={Array of Object Values} i.e. ["<Section Value>" => ["<Value 1>", "<Value 2>", "<Value 3>"], ...]	 *	 * @param int Group ID #	 * @param string Group Type, either 'ARO' or 'AXO'	 * @param string Option, either 'RECURSE' or 'NO_RECURSE'	 */	function get_group_objects($group_id, $group_type='ARO', $option='NO_RECURSE') {		switch(strtolower(trim($group_type))) {			case 'axo':				$group_type = 'axo';				$object_table = $this->_db_table_prefix .'axo';				$group_table = $this->_db_table_prefix .'axo_groups';				$map_table = $this->_db_table_prefix .'groups_axo_map';				break;			default:				$group_type = 'aro';				$object_table = $this->_db_table_prefix .'aro';				$group_table = $this->_db_table_prefix .'aro_groups';				$map_table = $this->_db_table_prefix .'groups_aro_map';				break;		}		$this->debug_text("get_group_objects(): Group ID: $group_id");		if (empty($group_id)) {			$this->debug_text("get_group_objects(): Group ID:  ($group_id) is empty, this is required");			return false;		}		$query  = '				SELECT		o.section_value,o.value';		if ($option == 'RECURSE') {			$query .= '				FROM		'. $group_table .' g2				JOIN		'. $group_table .' g1 ON g1.lft>=g2.lft AND g1.rgt<=g2.rgt				JOIN		'. $map_table .' AS gm ON gm.group_id=g1.id				JOIN		'. $object_table .' AS o ON o.id=gm.'. $group_type .'_id				WHERE		g2.id='. (int) $group_id;		} else {			$query .= '				FROM		'. $map_table .' AS gm				JOIN		'. $object_table .' AS o ON o.id=gm.'. $group_type .'_id				WHERE		gm.group_id='. (int) $group_id;		}		$rs = $this->db->Execute($query);		if (!is_object($rs)) {			$this->debug_db('get_group_objects');			return false;		}		$this->debug_text("get_group_objects(): Got group objects, formatting array.");		$retarr = array();		//format return array.		while ($row = $rs->FetchRow()) {			$section = &$row[0];			$value = &$row[1];			$retarr[$section][] = $value;		}		return $retarr;	}	/**	 * add_group_object()	 *	 * Assigns an Object to a group	 *	 * @return bool Returns TRUE if successful, FALSE otherwise.	 *	 * @param int Group ID #	 * @param string Object Section Value	 * @param string Object Value	 * @param string Group Type, either 'ARO' or 'AXO'	 */	function add_group_object($group_id, $object_section_value, $object_value, $group_type='ARO') {		switch(strtolower(trim($group_type))) {			case 'axo':				$group_type = 'axo';				$table = $this->_db_table_prefix .'groups_axo_map';				$object_table = $this->_db_table_prefix .'axo';				$group_table = $this->_db_table_prefix .'axo_groups';				break;			default:				$group_type = 'aro';				$table = $this->_db_table_prefix .'groups_aro_map';				$object_table = $this->_db_table_prefix .'aro';				$group_table = $this->_db_table_prefix .'aro_groups';				break;		}		$this->debug_text("add_group_object(): Group ID: $group_id Section Value: $object_section_value Value: $object_value Group Type: $group_type");		$object_section_value = trim($object_section_value);		$object_value = trim($object_value);		if (empty($group_id) OR $object_value === '' OR $object_section_value === '') {			$this->debug_text("add_group_object(): Group ID: ($group_id) OR Value ($object_value) OR Section value ($object_section_value) is empty, this is required");			return false;		}		// test to see if object & group exist and if object is already a member		$query  = '				SELECT		o.id AS id,g.id AS group_id,gm.group_id AS member				FROM		'. $object_table .' o				LEFT JOIN	'. $group_table .' g ON g.id='. (int) $group_id .'				LEFT JOIN	'. $table .' gm ON (gm.'. $group_type .'_id=o.id AND gm.group_id=g.id)				WHERE		(o.section_value='. $this->db->quote($object_section_value) .' AND o.value='. $this->db->quote($object_value) .')';	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -