vendor/pimcore/pimcore/models/WebsiteSetting/Dao.php line 76

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 Pimcore\Model\WebsiteSetting;
  15. use Pimcore\Model;
  16. use Pimcore\Model\Exception\NotFoundException;
  17. /**
  18.  * @internal
  19.  *
  20.  * @property \Pimcore\Model\WebsiteSetting $model
  21.  */
  22. class Dao extends Model\Dao\AbstractDao
  23. {
  24.     /**
  25.      * @param int|null $id
  26.      *
  27.      * @throws NotFoundException
  28.      */
  29.     public function getById($id null)
  30.     {
  31.         if ($id != null) {
  32.             $this->model->setId($id);
  33.         }
  34.         $data $this->db->fetchAssociative('SELECT * FROM website_settings WHERE id = ?', [$this->model->getId()]);
  35.         $this->assignVariablesToModel($data);
  36.         if (!empty($data['id'])) {
  37.             $this->assignVariablesToModel($data);
  38.         } else {
  39.             throw new NotFoundException('Website Setting with id: ' $this->model->getId() . ' does not exist');
  40.         }
  41.     }
  42.     /**
  43.      * @param string|null $name
  44.      * @param int|null $siteId
  45.      * @param string|null $language
  46.      *
  47.      * @throws NotFoundException
  48.      */
  49.     public function getByName($name null$siteId null$language null)
  50.     {
  51.         if ($name != null) {
  52.             $this->model->setName($name);
  53.         }
  54.         $data $this->db->fetchAssociative(
  55.             "SELECT *
  56.             FROM website_settings
  57.             WHERE name = ?
  58.                 AND (
  59.                     siteId IS NULL
  60.                     OR siteId = 0
  61.                     OR siteId = ?
  62.                 )
  63.                 AND (
  64.                     language IS NULL
  65.                     OR language = ''
  66.                     OR language = ?
  67.                 )
  68.             ORDER BY CONCAT(siteId, language) DESC, siteId DESC, language DESC",
  69.             [$this->model->getName(), $siteId$language]
  70.         );
  71.         if (!empty($data['id'])) {
  72.             $this->assignVariablesToModel($data);
  73.         } else {
  74.             throw new NotFoundException('Website Setting with name: ' $this->model->getName() . ' does not exist');
  75.         }
  76.     }
  77.     public function save()
  78.     {
  79.         if ($this->model->getId()) {
  80.             $this->update();
  81.         } else {
  82.             $this->create();
  83.         }
  84.     }
  85.     public function delete()
  86.     {
  87.         $this->db->delete('website_settings', ['id' => $this->model->getId()]);
  88.         $this->model->clearDependentCache();
  89.     }
  90.     public function update()
  91.     {
  92.         $ts time();
  93.         $this->model->setModificationDate($ts);
  94.         $dataRaw $this->model->getObjectVars();
  95.         $data = [];
  96.         foreach ($dataRaw as $key => $value) {
  97.             if (in_array($key$this->getValidTableColumns('website_settings'))) {
  98.                 $data[$key] = $value;
  99.             }
  100.         }
  101.         $this->db->update('website_settings'$data, ['id' => $this->model->getId()]);
  102.         $this->model->clearDependentCache();
  103.     }
  104.     public function create()
  105.     {
  106.         $ts time();
  107.         $this->model->setModificationDate($ts);
  108.         $this->model->setCreationDate($ts);
  109.         $this->db->insert('website_settings', ['name' => $this->model->getName(), 'siteId' => $this->model->getSiteId()]);
  110.         $this->model->setId((int) $this->db->lastInsertId());
  111.         $this->update();
  112.     }
  113. }