<?php
namespace OfficeBrain\Bundle\CoreBundle\Manager\Extended;

use Symfony\Component\HttpFoundation\Request;
use OfficeBrain\Bundle\CoreBundle\Manager\AbstractManager\DeviceDetectAbstract as DeviceDetectAbstract;

/**
 * @author Employee Id: 4471
 * OB eCommerce Product - Device Detection
 * DeviceDetectExtended class added to overwrite the logic of DeviceDetectAbstract Class
 */
class DeviceDetectExtended extends DeviceDetectAbstract
{
	/**
     * @author Employee Id: 5460
     * Initialize the required variable on class load
     *
     */  
	public function __construct($entityManager, $request, $deviceAppDownloadType)
    {
		parent::__construct($entityManager, $request, $deviceAppDownloadType);
    }

    public function __destruct()
    {
        parent::__destruct();
    }
    
    public function findAppDownloadLink()
    {
    	$httpUserAgent = $this->request->server->get("HTTP_USER_AGENT");
    	$deviceDetails = array("device_type" => "","app_download_link" => "");

    	foreach($this->deviceAppDownloadType as $device=>$applink){
    		if( stristr($httpUserAgent,$device) || strstr($httpUserAgent,$device)  ) {
    			$deviceDetails['device_type'] = $device;
    			$deviceDetails['app_download_link'] = $applink;
    		}
    	}
    	
    	unset($httpUserAgent);
    	return  $deviceDetails;
    }
}
