<?php

/**
 * Subclass for performing query and update operations on the 'katao_product_category' table.
 *
 * @package lib.model
 */
class KataoProductCategoryPeer extends BaseKataoProductCategoryPeer {
    /**
     * KataoProductCategoryPeer::retrieveByUrlIdentifier()
     *
     * @param string $url_identifier
     * @return KataoProductCategory
     */
    public static function retrieveByUrlIdentifier($url_identifier) {
        $criteria = new Criteria();
        $criteria->add(self::URL_IDENTIFIER, $url_identifier);
        return self::doSelectOne($criteria);
    }

    public static function getAll() {
        $return = array();

        $criteria = new Criteria();
        $criteria->addSelectColumn(self::ID);
        $criteria->addSelectColumn(self::NAME);
        $criteria->addSelectColumn(self::URL_IDENTIFIER);
        $criteria->addJoin(self::ID, KataoProductFamilyPeer::KATAO_PRODUCT_CATEGORY_ID);
        $criteria->addJoin(KataoProductFamilyPeer::ID, KataoProductPeer::KATAO_PRODUCT_FAMILY_ID);
        $criteria->add(KataoProductPeer::ID, sfContext::getInstance()->getUser()->getAvailableProducts(), Criteria::IN);
        $criterion = $criteria->getNewCriterion(KataoProductPeer::IS_ARCHIVED, null);
        $criterion->addOr($criteria->getNewCriterion(KataoProductPeer::IS_ARCHIVED, false));
        $criteria->addAnd($criterion);
        $criteria->addAscendingOrderByColumn(self::SORT_ORDER);

        $rs = self::doSelectRS($criteria);
        while ($rs->next()) {
            $return[$rs->getInt(1)] = array('name' => $rs->getString(2), 'url' => $rs->getString(3));
        }

        return $return;
    }

    public static function getAllSimple() {
        $return = array();

        $criteria = new Criteria();
        $criteria->addSelectColumn(self::ID);
        $criteria->addSelectColumn(self::NAME);
        $criteria->addAscendingOrderByColumn(self::SORT_ORDER);

        $rs = self::doSelectRS($criteria);
        while ($rs->next()) {
            $return[$rs->getInt(1)] = $rs->getString(2);
        }

        return $return;
    }
}