<?php

class AdcVendorDetails extends AdcWidget{

	static function register_shortcode( $atts ){
		$w = new self();
 		return $w->widget(array(),array());
	}

    public function __construct() {
        parent::__construct("text_widget", "ADC Vendor Details", array("description" => ""));
    }	

    public function addHead()
    {
		$product_uid = get_query_var("vendor", "");
		$product = $this->api->product($product_uid);
		$view = new View("vendor_details_head");
		$view->setVar("product", $product, false);
		echo $view->fetch();
    }

    function pageTitle($title)
    {
		$product_uid = get_query_var("vendor", "");
		$product = $this->api->product($product_uid);
		if ($product){
			$title['title'] = $product['vendor_title']." - ".$product['product_title'];
			$title['site'] = "Autodesk Community";
		}
        return $title;
    }

	public function widget($args, $instance) {
		$view = new View("vendor_details");
 		$settings = $this->getSettings();
 		$view->setVar("settings", $settings);
		$product_uid = get_query_var("vendor", "");
		$product = $this->api->product($product_uid);
		if (!$product){
    		global $wp_query;
    		$wp_query->set_404();
    		status_header(404);	
    		include( get_query_template( '404' ) );		
    		exit;
		}
 		$view->setVar("product", $product, false);
	    return $view->fetch();
	}    
}