vendor/pimcore/pimcore/models/Document/Link/Dao.php line 46

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\Document\Link;
  15. use Pimcore\Model;
  16. /**
  17.  * @internal
  18.  *
  19.  * @property \Pimcore\Model\Document\Link $model
  20.  */
  21. class Dao extends Model\Document\Dao
  22. {
  23.     /**
  24.      * Get the data for the object by the given id, or by the id which is set in the object
  25.      *
  26.      * @param int $id
  27.      *
  28.      * @throws Model\Exception\NotFoundException
  29.      */
  30.     public function getById($id null)
  31.     {
  32.         if ($id != null) {
  33.             $this->model->setId($id);
  34.         }
  35.         $data $this->db->fetchAssociative("SELECT documents.*, documents_link.*, tree_locks.locked FROM documents
  36.             LEFT JOIN documents_link ON documents.id = documents_link.id
  37.                 LEFT JOIN tree_locks ON documents.id = tree_locks.id AND tree_locks.type = 'document'
  38.                 WHERE documents.id = ?", [$this->model->getId()]);
  39.         if (!empty($data['id'])) {
  40.             $this->assignVariablesToModel($data);
  41.             $this->model->getHref();
  42.         } else {
  43.             throw new Model\Exception\NotFoundException('Link with the ID ' $this->model->getId() . " doesn't exists");
  44.         }
  45.     }
  46.     public function create()
  47.     {
  48.         parent::create();
  49.         $this->db->insert('documents_link', [
  50.             'id' => $this->model->getId(),
  51.         ]);
  52.     }
  53. }