vendor/pimcore/output-data-config-toolkit-bundle/src/OutputDefinition.php line 43

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace OutputDataConfigToolkitBundle;
  15. use OutputDataConfigToolkitBundle\OutputDefinition\Dao;
  16. use Pimcore\Logger;
  17. class OutputDefinition extends \Pimcore\Model\AbstractModel
  18. {
  19.     public $id;
  20.     public $o_id;
  21.     public $o_classId;
  22.     public $channel;
  23.     public $configuration;
  24.     /**
  25.      * @return OutputDefinition
  26.      */
  27.     public static function getByO_IdClassIdChannel($o_id$classId$channel)
  28.     {
  29.         $cacheKey self::getCacheKey($o_id$classId$channel);
  30.         try {
  31.             $config \Pimcore\Cache\Runtime::get($cacheKey);
  32.         } catch (\Exception $e) {
  33.             try {
  34.                 $config = new self();
  35.                 try {
  36.                     $config->getDao()->getByO_IdClassIdChannel($o_id$classId$channel);
  37.                     \Pimcore\Cache\Runtime::set($cacheKey$config);
  38.                 } catch (\Exception $e) {
  39.                     Logger::info($e->getMessage());
  40.                     $config null;
  41.                 }
  42.             } catch (\Exception $ex) {
  43.                 Logger::debug($ex->getMessage());
  44.                 return null;
  45.             }
  46.         }
  47.         return $config;
  48.     }
  49.     public static function getById($id)
  50.     {
  51.         try {
  52.             $config = new self();
  53.             $config->getDao()->getById($id);
  54.             return $config;
  55.         } catch (\Exception $ex) {
  56.             Logger::debug($ex->getMessage());
  57.             return null;
  58.         }
  59.     }
  60.     private static function getCacheKey($o_id$classId$channel)
  61.     {
  62.         return Dao::TABLE_NAME '_' $o_id '_' $classId '_' $channel;
  63.     }
  64.     /**
  65.      * @param array $values
  66.      *
  67.      * @return OutputDefinition
  68.      */
  69.     public static function create($values = [])
  70.     {
  71.         $config = new self();
  72.         $config->setValues($values);
  73.         return $config;
  74.     }
  75.     /**
  76.      * @return void
  77.      */
  78.     public function save()
  79.     {
  80.         $this->getDao()->save();
  81.     }
  82.     /**
  83.      * @return void
  84.      */
  85.     public function delete()
  86.     {
  87.         $cacheKey self::getCacheKey($this->getO_id(), $this->getO_ClassId(), $this->getChannel());
  88.         \Pimcore\Cache\Runtime::set($cacheKeynull);
  89.         $this->getDao()->delete();
  90.     }
  91.     public function setChannel($channel)
  92.     {
  93.         $this->channel $channel;
  94.     }
  95.     public function getChannel()
  96.     {
  97.         return $this->channel;
  98.     }
  99.     public function setConfiguration($configuration)
  100.     {
  101.         $this->configuration $configuration;
  102.     }
  103.     public function getConfiguration()
  104.     {
  105.         return $this->configuration;
  106.     }
  107.     public function setO_ClassId($o_classId)
  108.     {
  109.         $this->o_classId $o_classId;
  110.     }
  111.     public function getO_ClassId()
  112.     {
  113.         return $this->o_classId;
  114.     }
  115.     public function setO_Id($o_id)
  116.     {
  117.         $this->o_id $o_id;
  118.     }
  119.     public function getO_Id()
  120.     {
  121.         return $this->o_id;
  122.     }
  123.     public function setId($id)
  124.     {
  125.         $this->id $id;
  126.     }
  127.     public function getId()
  128.     {
  129.         return $this->id;
  130.     }
  131. }