178 lines
3.5 KiB
PHP
178 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Subclass for representing a row from the 'app_product_attribute_variant' table.
|
|
*
|
|
*
|
|
*
|
|
* @package plugins.appProductAttributesPlugin.lib.model
|
|
*/
|
|
class appProductAttributeVariant extends BaseappProductAttributeVariant
|
|
{
|
|
const UPLOAD_DIR = '/uploads/product_attributes/colors';
|
|
|
|
protected $oldPictureFilename = null;
|
|
|
|
public static function getTypes()
|
|
{
|
|
return array(
|
|
appProductAttributeVariantPeer::COLOR_TYPE => __('Kolor'),
|
|
appProductAttributeVariantPeer::PICTURE_TYPE => __('Obrazek'),
|
|
);
|
|
}
|
|
|
|
public function getAdminGeneratorTitle()
|
|
{
|
|
return null === $this->type ? $this->getValue() : $this->getName();
|
|
}
|
|
|
|
public function getValue()
|
|
{
|
|
if ($this->getCulture() == stLanguage::getOptLanguage())
|
|
{
|
|
return stLanguage::getDefaultValue($this, __METHOD__);
|
|
}
|
|
|
|
$v = parent::getValue();
|
|
|
|
if (null === $v)
|
|
{
|
|
$v = stLanguage::getDefaultValue($this, __METHOD__);
|
|
}
|
|
|
|
return $v;
|
|
}
|
|
|
|
public function setValue($v)
|
|
{
|
|
if ($this->getCulture() == stLanguage::getOptLanguage())
|
|
{
|
|
stLanguage::setDefaultValue($this, __METHOD__, $v);
|
|
}
|
|
|
|
parent::setValue($v);
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
if ($this->getCulture() == stLanguage::getOptLanguage())
|
|
{
|
|
return stLanguage::getDefaultValue($this, __METHOD__);
|
|
}
|
|
|
|
$v = parent::getName();
|
|
|
|
if (null === $v)
|
|
{
|
|
$v = stLanguage::getDefaultValue($this, __METHOD__);
|
|
}
|
|
|
|
return $v;
|
|
}
|
|
|
|
public function setName($v)
|
|
{
|
|
if ($this->getCulture() == stLanguage::getOptLanguage())
|
|
{
|
|
stLanguage::setDefaultValue($this, __METHOD__, $v);
|
|
}
|
|
|
|
parent::setName($v);
|
|
}
|
|
|
|
public function setColorType($v)
|
|
{
|
|
$this->setType($v);
|
|
}
|
|
|
|
public function setColor($v)
|
|
{
|
|
$this->setOptValue($v);
|
|
}
|
|
|
|
public function setPicture($v)
|
|
{
|
|
$this->setOptValue($v);
|
|
}
|
|
|
|
public function isColorType()
|
|
{
|
|
return $this->type == appProductAttributeVariantPeer::COLOR_TYPE;
|
|
}
|
|
|
|
public function isPictureType()
|
|
{
|
|
return $this->type == appProductAttributeVariantPeer::PICTURE_TYPE;
|
|
}
|
|
|
|
public function getTypeLabel()
|
|
{
|
|
$types = self::getTypes();
|
|
|
|
return $types[$this->type];
|
|
}
|
|
|
|
public function getUploadDir($systemDir = false)
|
|
{
|
|
return $systemDir ? sfConfig::get('sf_web_dir') . self::UPLOAD_DIR : self::UPLOAD_DIR;
|
|
}
|
|
|
|
public function getPicturePath($systemDir = false)
|
|
{
|
|
$path = $this->getOptValue();
|
|
|
|
if ($path[0] != '/')
|
|
{
|
|
return $this->getUploadDir($systemDir) . '/'. $path;
|
|
}
|
|
|
|
if ($systemDir)
|
|
{
|
|
return sfConfig::get('sf_web_dir') . $path;
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
public function getColor()
|
|
{
|
|
return $this->getOptValue();
|
|
}
|
|
|
|
public function delete($con = null)
|
|
{
|
|
$ret = parent::delete($con);
|
|
|
|
$fc = new stFunctionCache('appProductAttributeVariant');
|
|
|
|
$fc->removeAll();
|
|
|
|
if ($this->isPictureType())
|
|
{
|
|
$this->removePicture();
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
public function save($con = null)
|
|
{
|
|
$ret = parent::save($con);
|
|
|
|
$fc = new stFunctionCache('appProductAttributeVariant');
|
|
|
|
$fc->removeAll();
|
|
|
|
return $ret;
|
|
}
|
|
|
|
public function removePicture()
|
|
{
|
|
$file = sfConfig::get('sf_web_dir').$this->getPicturePath();
|
|
|
|
if (is_file($file))
|
|
{
|
|
unlink($file);
|
|
}
|
|
}
|
|
} |