Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_requests()

Description

Fetch a list of requests assigned to the logged in user

Parameters

ColumnTypeDefaultDescription
$excludecompleted boolean false Exclude completed requests?
$excludeassigned boolean false Exclude assigned requests? (e.g. if the user is able to assign unassigned requests) unless assigned to the logged in user
$returnsql boolean false Return SQL query object instead of the results?

Return

mixed Resulting array of requests or an SQL query object

Location

include/request_functions.php lines 226 to 273

Definition

 
function get_requests($excludecompleted=false,$excludeassigned=false,$returnsql=false)
    {
    global 
$userref;
    
$condition="";

    
$parameters=array();

    
# Include requests assigned to the user if the user can accept requests (permission "Rb")
    
if (checkperm("Rb")) 
        {
        
$condition="WHERE r.assigned_to=?";
        
$parameters=array("i",$userref);
        }
    
# Include all requests if the user can assign requests (permission "Ra")
    
if (checkperm("Ra")) 
        {
        
$condition="";
        
$parameters=array();
        
# Excluding assigned requests only makes sense if user is able to assign requests 
        
if ($excludeassigned
            {
            
$condition "WHERE (r.assigned_to IS null OR r.assigned_to = ?)"// Ensure they see requests that have been assigned to them
            
$parameters=array("i",$userref);
            }
        }
    
# Exclude completed requests if necessary
    
if ($excludecompleted
        {
        
$condition .= (($condition!="") ? " AND" "WHERE") . " r.status=0";
        }
        
    
$sql="SELECT u.username,u.fullname,r.*,
          (SELECT count(*) FROM collection_resource cr WHERE cr.collection=r.collection) c,
          u2.username assigned_to_username 
          FROM request r 
          LEFT OUTER JOIN user u ON r.user=u.ref LEFT OUTER JOIN user u2 ON r.assigned_to=u2.ref 
$condition  ORDER BY status,ref desc";
    
    
$request_query = new PreparedStatementQuery($sql$parameters);

    if (
$returnsql
        {
        return 
$request_query;
        }
    else 
        {
        return 
ps_query($request_query->sql,$request_query->parameters);
        }
    }

This article was last updated 2nd October 2022 16:35 Europe/London time based on the source file dated 29th September 2022 16:25 Europe/London time.