Current File : /home/karenpetzb/application/models/LivraisonPoids.php
<?php
class LivraisonPoids extends Zend_Db_Table
{
    protected $_name = 'livraison_poids';
    protected $_primary = 'ID';

    public function getLists() {
    	return $this->select()->order('FROM ASC')->query()->fetchAll();
	}
	
	public function getGoodPrice($type, $poidsTotal) {
		$myresult = array();
		try {
			$sql = "
				SELECT lp.PRICE PRICE, lt.CMDFRANCO CMDFRANCO, lt.NOM NOMLIV
				FROM livraison_poids lp
				LEFT JOIN livraison_type lt ON lt.ID = lp.TYPE 
				WHERE lp.TYPE = ".$type."
				AND lp.FROM <= ".$poidsTotal."
				AND lp.TO >= ".$poidsTotal;
			$results = $this->getAdapter()->fetchAll($sql);
			if (isset($results) && !empty($results)) {
				foreach ($results as $result) {
					$myresult['PRICE'] = $result['PRICE'];
					$myresult['CMDFRANCO'] = $result['CMDFRANCO'];
					$myresult['NOMLIV'] = $result['NOMLIV'];
					break;
				}
			} else {
				$sql = "
					SELECT lt.CMDFRANCO CMDFRANCO, lt.NOM NOMLIV
					FROM livraison_type lt
					WHERE lt.ID = ".$type;
				$result = $this->getAdapter()->fetchRow($sql);
				$myresult['PRICE'] = 0;
				$myresult['CMDFRANCO'] = $result['CMDFRANCO'];
				$myresult['NOMLIV'] = $result['NOMLIV'];
			}
		} catch (Zend_Exception $e) {}
		return $myresult;
	}
}
?>