Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // +---------------------------------------------------------------------------+
- // | This file is part of the Riobel Website project. |
- // | Copyright (C) Lemieux Bedard Communications |
- // | |
- // | For the full copyright and license information, please view the LICENSE |
- // | file that was distributed with this source code. |
- // +---------------------------------------------------------------------------+
- /**
- * RiobelProductsModel model is the business logic around a product.
- * @package model
- * @subpackage models
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @copyright Lemieux Bedard Communication (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- * @version 1.0.0
- */
- class RiobelProductModel extends RiobelBasePropelModel
- {
- const DEFAULT_HANDLE = 'L';
- const DEFAULT_COLOR = 'BN';
- /**
- * Initialize this model.
- * @param array [om] To specify the default record.
- * @return void
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function initialize(AgaviContext $context, array $parameters = array())
- {
- parent::initialize($context, $parameters, new RiobelProduct());
- }
- /**
- * Transfer a general field name associated to this model to a propel
- * constant field name the database transparent from the outside.
- * @param string The field name.
- * @return string The translated field name.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- protected function translateFieldName($name)
- {
- try {
- $translation = RiobelProductPeer::translateFieldName($name, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
- } catch (PropelException $e) {
- return null;
- }
- return $translation;
- }
- /**
- * Return the default instance of this product.
- * @return object The default instance.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getDefaultInstance()
- {
- return $this->context->getModel('RiobelProductInstance', null, array('om' => $this->om->getProductInstance()));
- }
- /**
- * Return the translated collection description.
- * @return string The translated field name.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getName()
- {
- switch ($this->context->getTranslationManager()->getCurrentLocale()->getLocaleLanguage()) {
- case 'en' : return $this->om->getNameEn();
- case 'fr' : return $this->om->getNameFr();
- }
- }
- /**
- * Return the translated collection description.
- * @return string The translated field name.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getDesc()
- {
- switch ($this->context->getTranslationManager()->getCurrentLocale()->getLocaleLanguage()) {
- case 'en' : return $this->om->getDescEn();
- case 'fr' : return $this->om->getDescFr();
- }
- }
- /**
- * Return the translated collection specification.
- * @return string The translated field name.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getSpec()
- {
- switch ($this->context->getTranslationManager()->getCurrentLocale()->getLocaleLanguage()) {
- case 'en' : return $this->om->getSpecEn();
- case 'fr' : return $this->om->getSpecFr();
- }
- }
- /**
- * Return the code of this product.
- * @param string The handle.
- * @param string The color
- * @return string The code.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getCode($handle = null, $color = null)
- {
- if ($handle != null && $color != null) {
- $h = $this->formatHandle($handle);
- $h = $this->hasHandle($h) ? $h : self::DEFAULT_HANDLE;
- $c = $this->hasColor($color) ? $color : self::DEFAULT_COLOR;
- // load the instance from the data that was supplied. If however there is no
- // instance that match the demand, the default instance will be returned
- $instance = $this->context->getModel('RiobelProductInstances')->getProductInstanceByHandleAndColor($this->om->getId(), $h, $c);
- if ($instance == null) {
- $instance = $this->getDefaultInstance();
- }
- return $instance->getCode();
- }
- return $this->om->getCode();
- }
- /**
- * Return the image of this product.
- * @param string The handle.
- * @param string The color
- * @return string The image.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getImage($handle = null, $color = null)
- {
- $h = $this->formatHandle($handle);
- $h = $this->hasHandle($h) ? $h : self::DEFAULT_HANDLE;
- $c = $this->hasColor($color) ? $color : self::DEFAULT_COLOR;
- // load the instance from the data that was supplied. If however there is no
- // instance that match the demand, the default instance will be returned
- $instance = $this->context->getModel('RiobelProductInstances')->getProductInstanceByHandleAndColor($this->om->getId(), $h, $c);
- if ($instance == null) {
- $instance = $this->getDefaultInstance();
- }
- return $instance->getImage();
- }
- /**
- * Return the viewable image of this product.
- * @param string The handle.
- * @param string The color
- * @return string The image.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getViewableImage($handle = null, $color = null)
- {
- $file = $this->getImage($handle, $color);
- $path = 'images/products/%s';
- $path = sprintf($path, $file);
- return is_readable($path) && is_file($path) ? $file : 'empty_product.gif';
- }
- /**
- * Return the colors of this product.
- * @param object The criteria.
- * @param string The order.
- * @param int The limit.
- * @param int The offset.
- * @return array The results.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getColors($order = null, $limit = null, $offset = null)
- {
- return $this->context->getModel('RiobelProductColors')->getProductColors($this->om->getId(), null, $order, $limit, $offset);
- }
- /**
- * Return the available codes.
- * @return array The available codes.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getAvailableCodes()
- {
- return explode(',', $this->om->getAvailableCodes());
- }
- /**
- * Return the available colors.
- * @return array The available colors.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getAvailableColors()
- {
- return explode(',', $this->om->getAvailableColors());
- }
- /**
- * Return the available colors objects.
- * @return array The available colors objects.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getAvailableColorObjects()
- {
- switch ($this->context->getTranslationManager()->getCurrentLocale()->getLocaleLanguage()) {
- case 'en' : return $this->context->getModel('RiobelColors')->getColorsByCodes($this->getAvailableColors(), 'name_en');
- case 'fr' : return $this->context->getModel('RiobelColors')->getColorsByCodes($this->getAvailableColors(), 'name_fr');
- }
- }
- /**
- * Return the available handles.
- * @return array The available handles.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function getAvailableHandles()
- {
- return explode(',', $this->om->getAvailableHandles());
- }
- /**
- * Indicate whether or not this product have this code.
- * @param string The code.
- * @return bool True if the product have the code.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function hasCode($code)
- {
- return in_array($code, $this->getAvailableCodes());
- }
- /**
- * Indicate whether or not this product have this color.
- * @param string The color.
- * @return bool True if the product have the color.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function hasColor($color)
- {
- return in_array($color, $this->getAvailableColors());
- }
- /**
- * Indicate whether or not this product have this handle.
- * @param string The handle.
- * @return bool True if the product have the handle.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function hasHandle($handle)
- {
- return in_array($this->formatHandle($handle), $this->getAvailableHandles());
- }
- /**
- * Indicate whether or not the product provides a lever handle.
- * @return bool True if the product have the handle.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function providesLeverHandle()
- {
- return $this->hasHandle('L');
- }
- /**
- * Indicate whether or not the product provides a cross handle.
- * @return bool True if the product have the handle.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- public function providesCrossHandle()
- {
- return $this->hasHandle('+');
- }
- /**
- * Change the cross handle C sign to a + sign.
- * @param string The cross handle sign.
- * @return string The cross handle sign.
- * @author Jean-Philippe Dery (jean-philippe.dery@lemieuxbedard.com)
- * @since 1.0.0
- */
- protected function formatHandle($handle)
- {
- return str_replace('C', '+', $handle);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment