<?php

/**
 * Subclass for performing query and update operations on the 'katao_order_product' table.
 *
 * @package lib.model
 */
class KataoOrderProductPeer extends BaseKataoOrderProductPeer {
    /**
     * KataoOrderProductPeer::receiveQuantity()
     *
     * @param int $id
     * @param int $quantity
     * @return
     */
    public static function receiveQuantity($id, $quantity) {
        $criteria_update = new Criteria();
        $criteria_update->add(self::QUANTITY_RECEIVED, $quantity);
        $criteria_update->add(self::HAS_BEEN_RECEIVED, true);
        $criteria_where = new Criteria();
        $criteria_where->add(self::ID, $id);
        BasePeer::doUpdate($criteria_where, $criteria_update, Propel::getConnection());
    }

    /**
     * KataoOrderProductPeer::getIdByProductAndPeriodAndNode()
     *
     * @param int $katao_product_id
     * @param int $katao_period_id
     * @param int $katao_node_id
     * @return int
     */
    public static function getIdByProductAndPeriodAndNode($katao_product_id, $katao_period_id, $katao_node_id) {
        $return = null;

        $criteria = new Criteria();
        $criteria->addSelectColumn(self::ID);
        $criteria->addJoin(self::KATAO_ORDER_ID, KataoOrderPeer::ID);
        $criteria->add(self::KATAO_PRODUCT_ID, $katao_product_id);
        $criteria->add(KataoOrderPeer::KATAO_PERIOD_ID, $katao_period_id);
        $criteria->add(KataoOrderPeer::KATAO_NODE_ID, $katao_node_id);
        $criteria->setLimit(1);

        $rs = self::doSelectRS($criteria);
        if ($rs->next()) {
            $return = $rs->getInt(1);
        }

        return $return;
    }
}