<?php

/**
 * Subclass for representing a row from the 'katao_product_family' table.
 *
 * @package lib.model
 */
class KataoProductFamily extends BaseKataoProductFamily {
    public function __toString() {
        return $this->getName();
    }

    public function save($con = null) {
        if ('' == $this->getUrlIdentifier()) {
            $this->setUrlIdentifier(Catalyz::normalizeUrlIdentifier($this->getName()));
        }
        parent::save($con);
    }

    public function getKataoProductCategoryLink($with_link = false) {
        $result = '';
        if (null != $katao_product_category = $this->getKataoProductCategory()) {
            if ($with_link) {
                $result = link_to($katao_product_category->getName(), '@katao_product_category_show?id=' . $katao_product_category->getId());
            } else {
                $result = $katao_product_category->getName();
            }
        }
        return $result;
    }

    public function isDeletable() {
        return (0 == $this->countKataoProducts());
    }
}