Back to PhocacartUser class

Method getUser

public static
getUser
(mixed $id = 0)

Method getUser - Source code

/*protected $guest = array();

	protected $user 	= array();
	protected $vendor	= array();
	protected $ticket	= array();
	protected $pos		= false;*/
/*public function __construct($pos) {


		$this->user		= Factory::getUser();
		$this->pos		= $pos;
	}*/
public static function getUser($id = 0)
{
    $app = Factory::getApplication();
    $pUser = $vendor = $ticket = $unit = $section = array();
    $isVendor = false;
    if ((int) $id > 0) {
        $jUser = Factory::getUser($id);
        return $jUser;
    } else {
        if (PhocacartPos::isPos()) {
            $isVendor = self::defineUser($pUser, $vendor, $ticket, $unit, $section);
            if ($isVendor) {
                // Current Joomla! User is Vendor (in POS)
                // Check if this vendor has selected some customer
                // If yes: switch the selected user as current Joomla! user
                //         for example to check access rights: Vendor selected User A
                //         so we must check the rights of User A and not of Vendor
                if (!empty($pUser)) {
                    // ======= LOGGED JOOMLA! USER IS VENDOR - CUSTOMER SELECTED
                    return $pUser;
                } else {
                    // ======= LOGGED JOOMLA! USER IS VENDOR - NO CUSTOMER SELECTED
                    return false;
                    // Joomla! User is vendor and he/she didn't select any customer
                }
            } else {
                // ======= LOGGED JOOMLA! USER IS NOT VENDOR - BUT IN POS WE NEED VENDOR
                return false;
            }
        } else {
            if ($app->getName() == 'administrator') {
                // ======= LOGGED JOOMLA! USER IS ADMINISTRATOR
                // We want to get information about user's cart in administration
                $userid = $app->input->get('userid', 0, 'int');
                //$vendorid  = $app->input->get('vendorid', 0, 'int');
                //$ticketid  = $app->input->get('ticketid', 0, 'int');
                //$unitid    = $app->input->get('unitid', 0, 'int');
                //$sectionid = $app->input->get('sectionid', 0, 'int');
                // Test if we ask POS user
                //$userIdPos = PhocacartPos::getUserIdByVendorAndTicket($vendorid, $ticketid, $unitid, $sectionid);
                if ((int) $userid > 0) {
                    // ======= LOGGED JOOMLA! USER IS ADMINISTRATOR - CUSTOMER FOUND
                    return Factory::getUser($userid);
                } else {
                    // ======= LOGGED JOOMLA! USER IS ADMINISTRATOR - NO CUSTOMER FOUND
                    return JFactory::getUser(0);
                    // Joomla! User is administrator and there is no information about user
                }
            } else {
                // ======= LOGGED JOOMLA! USER IS CUSTOMER
                // No POS, return standard Joomla! User
                $jUser = Factory::getUser();
                return $jUser;
            }
        }
    }
    // ======= NO LOGGED JOOMLA! USER
    return false;
}