<?php
	require_once( $GLOBALS["site_root"] . "/includes/widgets/JobsGrid.inc.php" );
	
	class MyQuoteRequestsGrid extends JobsGrid {
		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
			$this->unsetFilter( "currents" );
			$this->setFilter( "posted_by_me" ,
				$this->job_model->getJobFilter( "posted_by_me",
					array("user_id"=> $this->mymember_model->getLoggedinUserId() ) ) );
		}

		public function constructColumns() {
			parent::constructColumns();
		}

		protected function prepareDataset() {
			parent::prepareDataset();
			// job ids
			$job_ids=array();
			foreach ($this->aData as $row) $job_ids[] = $row["id"];
			// FIXME ide jon az, hogy melyikre hany accepted van

			$d = array();
			foreach ($this->aData as $row) {
				$item = $row;
				// FIXME most csak virtual, itt kell majd kiszedni a datasetbol
				$item["numofacceptedquotes"]=rand()%5;
				$d[] = $item;
			}
			$this->aData = $d;
		}

		public function modifyGetPost( &$g , &$p ) {
			parent::modifyGetPost( $g , $p );
			if (!isset( $g[$this->_ordering] )) {
				// BASK
				// ha nincs rendezes
				if (isset( $g["active"] ) && $g["active"] ) {
					// ha csak az aktiv, akkor a lejaros van felul
					$this->setFilter( "not_expireds" , $this->job_model->getJobFilter( "not_expireds" ) );

					$g[$this->_ordering]="job_quote_deadline";
					$g[$this->_orderingdir]="asc";
				} else {
					// ha nem aktiv, akkor a legfrissebb van legfelul
					$g[$this->_ordering]="job_quote_deadline";
					$g[$this->_orderingdir]="desc";
				}
			}
		}

		public function constructField( $rownum , $row , $colname ) {
			$field = parent::constructField( $rownum , $row , $colname );
			switch ($colname) {
			case "job_title":
				$val = $field->getValue();
				$rd = $this->aData[$rownum];
				$curtime = fo3_date( "Y-m-d H:i:s" );
				/*
				if ($rd["is_closed"]=="t") {
					// lezarta
					$status = __("myquoterequestspage_status_closed" );
				} else if ($curtime>$rd["job_deadline"]) {
					$status = __("myquoterequestspage_status_after_deadline" );
				} else if ($curtime>$rd["job_quote_deadline"]) {
					// lejart az ajanlatteteli hatarido
					$status = __("myquoterequestspage_status_after_quote_deadline");
				} else {
					// meg nyitott
					$status = __("myquoterequestspage_status_open" );
				}
				$val.=sprintf( "<br/>(%s)",$status );
				*/
				$field->setValue( $val );
				break;
			}
			return $field;
		}
	}
?>
