forked from pimcore/pimcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dao.php
87 lines (74 loc) · 2.83 KB
/
Dao.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Pimcore
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2009-2016 pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GNU General Public License version 3 (GPLv3)
*/
namespace Pimcore\Model\Search\Backend\Data;
use Pimcore\Model;
class Dao extends \Pimcore\Model\Dao\AbstractDao {
/**
* @param $element
* @throws
*/
public function getForElement($element) {
try {
if($element instanceof Model\Document){
$maintype = "document";
} else if ($element instanceof Model\Asset){
$maintype = "asset";
} else if ($element instanceof Model\Object\AbstractObject){
$maintype = "object";
} else {
throw Exception("unknown type of element with id [ ".$element->getId()." ] ");
}
$data = $this->db->fetchRow("SELECT * FROM search_backend_data WHERE id= ? AND maintype = ? ", array($element->getId(),$maintype));
if(is_array($data)){
$this->assignVariablesToModel($data);
$this->model->setId(new Model\Search\Backend\Data\Id($element));
}
}
catch (\Exception $e){}
}
/**
*
*/
public function save() {
try {
$data = array(
"id" => $this->model->getId()->getId(),
"fullpath" => $this->model->getFullPath(),
"maintype" => $this->model->getId()->getType(),
"type" => $this->model->getType(),
"subtype" => $this->model->getSubtype(),
"published" => $this->model->isPublished(),
"creationdate" => $this->model->getCreationDate(),
"modificationdate" => $this->model->getmodificationDate(),
"userowner" => $this->model->getUserOwner(),
"usermodification" => $this->model->getUserModification(),
"data" => $this->model->getData(),
"properties" => $this->model->getProperties()
);
$this->db->insertOrUpdate("search_backend_data", $data);
} catch (\Exception $e) {
\Logger::error($e);
}
}
/**
* Deletes from database
*
* @return void
*/
public function delete() {
if($this->model->getId() instanceof Model\Search\Backend\Data\Id ){
$this->db->delete("search_backend_data", "id='" . $this->model->getId()->getId() . "' AND maintype ='" .$this->model->getId()->getType() . "'");
} else {
\Logger::alert("Cannot delete Search\\Backend\\Data, ID is empty");
}
}
}