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

📄 member.php

📁 讲的是网络编程
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * @param int $group_id ID of the group
     * @param array $user_ids array of user-IDs
     * @return bool success?
     */
    function removeUsersFromGroup($group_id, $user_ids = array())
    {
        $criteria = new CriteriaCompo();
        $criteria->add(new Criteria('groupid', $group_id));
        $criteria2 = new CriteriaCompo();
        foreach ($user_ids as $uid) {
            $criteria2->add(new Criteria('uid', $uid), 'OR');
        }
        $criteria->add($criteria2);
        return $this->_mHandler->deleteAll($criteria);
    }

    /**
     * get a list of users belonging to a group
     *
     * @param int $group_id ID of the group
     * @param bool $asobject return the users as objects?
     * @param int $limit number of users to return
     * @param int $start index of the first user to return
     * @return array Array of {@link XoopsUser} objects (if $asobject is TRUE)
     * or of associative arrays matching the record structure in the database.
     */
    function getUsersByGroup($group_id, $asobject = false, $limit = 0, $start = 0)
    {
        $user_ids = $this->_mHandler->getUsersByGroup($group_id, $limit, $start);
        if (!$asobject) {
           return $user_ids;
        } else {
           $ret = array();
           foreach ($user_ids as $u_id) {
               $user =& $this->getUser($u_id);
				if (is_object($user)) {
					$ret[] =& $user;
				}
				unset($user);
           }
           return $ret;
        }
    }

    /**
     * get a list of groups that a user is member of
     *
     * @param int $user_id ID of the user
     * @param bool $asobject return groups as {@link XoopsGroup} objects or arrays?
     * @return array array of objects or arrays
     */
    function getGroupsByUser($user_id, $asobject = false)
    {
        $group_ids = $this->_mHandler->getGroupsByUser($user_id);
        if (!$asobject) {
           return $group_ids;
        } else {
           foreach ($group_ids as $g_id) {
               $ret[] =& $this->getGroup($g_id);
           }
           return $ret;
        }
    }

    /**
     * log in a user
     *
     * @param string $uname username as entered in the login form
     * @param string $pwd password entered in the login form
     * @return object XoopsUser reference to the logged in user. FALSE if failed to log in
     */
    function &loginUser($uname, $pwd)
    {
        $criteria = new CriteriaCompo(new Criteria('uname', $uname));
        $criteria->add(new Criteria('pass', md5($pwd)));
        $user = $this->_uHandler->getObjects($criteria, false);
        if (!$user || count($user) != 1) {
        	$user = false;
            return $user;
        }
        return $user[0];
    }

    /**
     * logs in a user with an nd5 encrypted password
     *
     * @param string $uname username
     * @param string $md5pwd password encrypted with md5
     * @return object XoopsUser reference to the logged in user. FALSE if failed to log in
     */
    function &loginUserMd5($uname, $md5pwd)
    {
        $criteria = new CriteriaCompo(new Criteria('uname', $uname));
        $criteria->add(new Criteria('pass', $md5pwd));
        $user = $this->_uHandler->getObjects($criteria, false);
        if (!$user || count($user) != 1) {
        	$user = false;
            return $user;
        }
        return $user[0];
    }

    /**
     * count users matching certain conditions
     *
     * @param object $criteria {@link CriteriaElement} object
     * @return int
     */
    function getUserCount($criteria = null)
    {
        return $this->_uHandler->getCount($criteria);
    }

    /**
     * count users belonging to a group
     *
     * @param int $group_id ID of the group
     * @return int
     */
    function getUserCountByGroup($group_id)
    {
        return $this->_mHandler->getCount(new Criteria('groupid', $group_id));
    }

    /**
     * updates a single field in a users record
     *
     * @param object $user reference to the {@link XoopsUser} object
     * @param string $fieldName name of the field to update
     * @param string $fieldValue updated value for the field
     * @return bool TRUE if success or unchanged, FALSE on failure
     */
    function updateUserByField(&$user, $fieldName, $fieldValue)
    {
        $user->setVar($fieldName, $fieldValue);
        return $this->insertUser($user);
    }

    /**
     * updates a single field in a users record
     *
     * @param string $fieldName name of the field to update
     * @param string $fieldValue updated value for the field
     * @param object $criteria {@link CriteriaElement} object
     * @return bool TRUE if success or unchanged, FALSE on failure
     */
    function updateUsersByField($fieldName, $fieldValue, $criteria = null)
    {
        return $this->_uHandler->updateAll($fieldName, $fieldValue, $criteria);
    }

    /**
     * activate a user
     *
     * @param object $user reference to the {@link XoopsUser} object
     * @return bool successful?
     */
    function activateUser(&$user)
    {
        if ($user->getVar('level') != 0) {
            return true;
        }
        $user->setVar('level', 1);
        return $this->_uHandler->insert($user, true);
    }

    /**
     * Get a list of users belonging to certain groups and matching criteria
     * Temporary solution
     *
     * @param int $groups IDs of groups
     * @param object $criteria {@link CriteriaElement} object
     * @param bool $asobject return the users as objects?
     * @param bool $id_as_key use the UID as key for the array if $asobject is TRUE
     * @return array Array of {@link XoopsUser} objects (if $asobject is TRUE)
     * or of associative arrays matching the record structure in the database.
     */
    function getUsersByGroupLink($groups, $criteria = null, $asobject = false, $id_as_key = false)
    {
	    $ret = array();

	    $select = $asobject ? "u.*" : "u.uid";
	    $sql[] = "	SELECT DISTINCT {$select} ".
	    		"	FROM " . $this->_uHandler->db->prefix("users") . " AS u".
	    		"		LEFT JOIN ". $this->_mHandler->db->prefix("groups_users_link") . " AS m ON m.uid = u.uid".
	    		"	WHERE 1 = 1";
	    if (!empty($groups)) {
		    $sql[] = "m.groupid IN (".implode(", ", $groups).")";
	    }
        $limit = $start = 0;
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
            $sql_criteria = $criteria->render();
            if ($criteria->getSort() != '') {
                $sql_criteria .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
            }
            $limit = $criteria->getLimit();
            $start = $criteria->getStart();
            if ($sql_criteria) {
	            $sql[] = $sql_criteria;
            }
        }
        $sql_string = implode(" AND ", array_filter($sql));
        if (!$result = $this->_uHandler->db->query($sql_string, $limit, $start)) {
            return $ret;
        }
        while ($myrow = $this->_uHandler->db->fetchArray($result)) {
	        if ($asobject) {
	            $user = new XoopsUser();
	            $user->assignVars($myrow);
	            if (!$id_as_key) {
	                $ret[] =& $user;
	            } else {
	                $ret[$myrow['uid']] =& $user;
	            }
	            unset($user);
            } else {
	            $ret[] = $myrow['uid'];
            }
        }
        return $ret;
    }

    /**
     * Get count of users belonging to certain groups and matching criteria
     * Temporary solution
     *
     * @param int $groups IDs of groups
     * @return int count of users
     */
    function getUserCountByGroupLink($groups, $criteria = null)
    {
	    $ret = 0;

	    $sql[] = "	SELECT COUNT(DISTINCT u.uid) ".
	    		"	FROM " . $this->_uHandler->db->prefix("users") . " AS u".
	    		"		LEFT JOIN ". $this->_mHandler->db->prefix("groups_users_link") . " AS m ON m.uid = u.uid".
	    		"	WHERE 1 = 1";
	    if (!empty($groups)) {
		    $sql[] = "m.groupid IN (".implode(", ", $groups).")";
	    }
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
            $sql[] = $criteria->render();
        }
        $sql_string = implode(" AND ", array_filter($sql));
        if (!$result = $this->_uHandler->db->query($sql_string)) {
            return $ret;
        }
        list($ret) = $this->_uHandler->db->fetchRow($result);
        return $ret;
    }

}
?>

⌨️ 快捷键说明

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