From a4c103fa426eaedb86faec9f9c7e863d5050f3bc Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 23 Jan 2012 18:18:49 +0100 Subject: [PATCH] Moved vocabulary to Alchemy namespace --- lib/classes/caption/Field/Value.class.php | 34 +- lib/classes/databox/field.class.php | 4 +- lib/classes/record/adapter.class.php | 393 ++++++++++++---------- 3 files changed, 238 insertions(+), 193 deletions(-) diff --git a/lib/classes/caption/Field/Value.class.php b/lib/classes/caption/Field/Value.class.php index d29a9903c2..baa0236ef9 100644 --- a/lib/classes/caption/Field/Value.class.php +++ b/lib/classes/caption/Field/Value.class.php @@ -116,6 +116,27 @@ class caption_Field_Value return $this; } + + public function setVocab(\Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary, $vocab_id) + { + + $params = array( + ':VocabType' => $vocabulary->getType() + , ':VocabularyId' => $vocab_id + ); + + $sql_up = 'UPDATE metadatas + SET VocabularyType = :VocabType, VocabularyId = :VocabularyId + WHERE id = :meta_id'; + $stmt_up = $connbas->prepare($sql_up); + $stmt_up->execute($params); + $stmt_up->closeCursor(); + + $this->set_value($vocabulary->getValue($vocab_id)); + + return $this; + } + public function set_value($value) { @@ -206,21 +227,24 @@ class caption_Field_Value return $this; } - public static function create(databox_field &$databox_field, record_Interface $record, $value) + public static function create(databox_field &$databox_field, record_Interface $record, $value, \Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null, $vocabularyId = null) { $sbas_id = $databox_field->get_databox()->get_sbas_id(); $connbas = $databox_field->get_connection(); - $sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value) - VALUES - (null, :record_id, :field, :value)'; + $sql_ins = 'INSERT INTO metadatas + (id, record_id, meta_struct_id, value, VocabularyType, VocabularyId) + VALUES + (null, :record_id, :field, :value, :VocabType, :VocabId)'; $stmt_ins = $connbas->prepare($sql_ins); $stmt_ins->execute( array( ':record_id' => $record->get_record_id(), ':field' => $databox_field->get_id(), - ':value' => $value + ':value' => $value, + ':VocabType' => $vocabulary ? $vocabulary->getType() : null, + ':VocabId' => $vocabulary ? $vocabularyId : null, ) ); $stmt_ins->closeCursor(); diff --git a/lib/classes/databox/field.class.php b/lib/classes/databox/field.class.php index b1ba13ea42..95ddae1f10 100644 --- a/lib/classes/databox/field.class.php +++ b/lib/classes/databox/field.class.php @@ -185,7 +185,7 @@ class databox_field implements cache_cacheableInterface try { - $this->Vocabulary = databox_Field_VocabularyControl::get($row['VocabularyControlType']); + $this->Vocabulary = \Alchemy\Phrasea\Vocabulary\Controller::get($row['VocabularyControlType']); $this->VocabularyRestriction = !!$row['RestrictToVocabularyControl']; } catch (Exception $e) @@ -498,7 +498,7 @@ class databox_field implements cache_cacheableInterface return $this; } - public function setVocabularyControl(databox_Field_VocabularyControl_Interface $vocabulary = null) + public function setVocabularyControl(\Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null) { $this->Vocabulary = $vocabulary; diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index b25ddc08d6..ce29cd39d0 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -132,13 +132,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected $modification_date; - const CACHE_ORIGINAL_NAME = 'originalname'; + const CACHE_ORIGINAL_NAME = 'originalname'; const CACHE_TECHNICAL_DATAS = 'technical_datas'; - const CACHE_MIME = 'mime'; - const CACHE_SHA256 = 'sha256'; - const CACHE_SUBDEFS = 'subdefs'; - const CACHE_GROUPING = 'grouping'; - const CACHE_STATUS = 'status'; + const CACHE_MIME = 'mime'; + const CACHE_SHA256 = 'sha256'; + const CACHE_SUBDEFS = 'subdefs'; + const CACHE_GROUPING = 'grouping'; + const CACHE_STATUS = 'status'; protected static $_regfields; @@ -186,12 +186,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface } $connbas = $this->databox->get_connection(); - $sql = 'SELECT coll_id, record_id,credate , uuid, moddate, parent_record_id + $sql = 'SELECT coll_id, record_id,credate , uuid, moddate, parent_record_id , type, originalname, bitly, sha256, mime FROM record WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row) @@ -210,16 +210,16 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->mime = $row['mime']; $datas = array( - 'mime' => $this->mime - , 'sha256' => $this->sha256 - , 'bitly_link' => $this->bitly_link - , 'original_name' => $this->original_name - , 'type' => $this->type - , 'grouping' => $this->grouping - , 'uuid' => $this->uuid - , 'modification_date' => $this->modification_date - , 'creation_date' => $this->creation_date - , 'base_id' => $this->base_id + 'mime' => $this->mime + , 'sha256' => $this->sha256 + , 'bitly_link' => $this->bitly_link + , 'original_name' => $this->original_name + , 'type' => $this->type + , 'grouping' => $this->grouping + , 'uuid' => $this->uuid + , 'modification_date' => $this->modification_date + , 'creation_date' => $this->creation_date + , 'base_id' => $this->base_id ); $this->set_data_to_cache($datas); @@ -292,9 +292,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; + $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); - $stmt->execute(array(':type' => $type, ':record_id' => $this->get_record_id())); + $stmt->execute(array(':type' => $type, ':record_id' => $this->get_record_id())); $stmt->closeCursor(); if ($old_type !== $type) @@ -371,9 +371,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $dstatus = databox_status::getDisplayStatus(); $sbas_id = $this->get_sbas_id(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(); $session = $appbox->get_session(); - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); + $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $status = ''; @@ -382,24 +382,24 @@ class record_adapter implements record_Interface, cache_cacheableInterface foreach ($dstatus[$sbas_id] as $n => $statbit) { if ($statbit['printable'] == '0' && - !$user->ACL()->has_right_on_base($this->base_id, 'chgstatus')) + !$user->ACL()->has_right_on_base($this->base_id, 'chgstatus')) continue; $x = (substr((strrev($this->get_status())), $n, 1)); $source0 = "/skins/icons/spacer.gif"; - $style0 = "visibility:hidden;display:none;"; + $style0 = "visibility:hidden;display:none;"; $source1 = "/skins/icons/spacer.gif"; - $style1 = "visibility:hidden;display:none;"; + $style1 = "visibility:hidden;display:none;"; if ($statbit["img_on"]) { $source1 = $statbit["img_on"]; - $style1 = "visibility:auto;display:none;"; + $style1 = "visibility:auto;display:none;"; } if ($statbit["img_off"]) { $source0 = $statbit["img_off"]; - $style0 = "visibility:auto;display:none;"; + $style0 = "visibility:auto;display:none;"; } if ($x == '1') { @@ -416,19 +416,19 @@ class record_adapter implements record_Interface, cache_cacheableInterface } } $status .= ''; + 'class="STAT_' . $this->base_id . '_' + . $this->record_id . '_' . $n . '_1" ' . + 'src="' . $source1 . '" title="' . + (isset($statbit["labelon"]) ? + $statbit["labelon"] : + $statbit["lib"]) . '"/>'; $status .= ''; + 'class="STAT_' . $this->base_id . '_' + . $this->record_id . '_' . $n . '_0" ' . + 'src="' . $source0 . '" title="' . + (isset($statbit["labeloff"]) ? + $statbit["labeloff"] : + ("non-" . $statbit["lib"])) . '"/>'; } } @@ -481,8 +481,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface $sql = "UPDATE record SET coll_id = :coll_id WHERE record_id =:record_id"; $params = array( - ':coll_id' => $collection->get_coll_id(), - ':record_id' => $this->get_record_id() + ':coll_id' => $collection->get_coll_id(), + ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); @@ -492,7 +492,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->base_id = $collection->get_base_id(); $appbox->get_session()->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_MOVE, $collection->get_coll_id(), ''); + ->log($this, Session_Logger::EVENT_MOVE, $collection->get_coll_id(), ''); $this->delete_data_from_cache(); @@ -509,7 +509,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface { return null; } - + try { return $this->get_subdef('thumbnailGIF'); @@ -568,18 +568,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface { } - $sql = 'SELECT BIN(status) as status FROM record + $sql = 'SELECT BIN(status) as status FROM record WHERE record_id = :record_id'; $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $row = $stmt->fetch(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row) throw new Exception('status not found'); $status = $row['status']; - $n = strlen($status); + $n = strlen($status); while ($n < 64) { $status = '0' . $status; @@ -599,7 +599,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_subdef($name) { $name = strtolower($name); - + if (!in_array($name, $this->get_available_subdefs())) { throw new Exception_Media_SubdefNotFound (); @@ -660,7 +660,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $subdefs = array('preview', 'thumbnail'); @@ -669,7 +669,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $subdefs[] = $row['name']; } - $subdefs = array_unique($subdefs); + $subdefs = array_unique($subdefs); $this->set_data_to_cache($subdefs, self::CACHE_SUBDEFS); return $subdefs; @@ -702,10 +702,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $this->technical_datas = array(); $connbas = $this->get_databox()->get_connection(); - $sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) @@ -781,7 +781,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $dom_doc->formatOutput = true; $dom_doc->standalone = true; - $record = $dom_doc->createElement('record'); + $record = $dom_doc->createElement('record'); $record->setAttribute('record_id', $this->get_record_id()); $dom_doc->appendChild($record); $description = $dom_doc->createElement('description'); @@ -857,11 +857,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface $value = array_pop($field->get_values()); $this->set_metadatas( - array( - 'meta_struct_id' => $field->get_meta_struct_id() - , 'meta_id' => $value->getId() - , 'value' => $original_name - ) + array( + 'meta_struct_id' => $field->get_meta_struct_id() + , 'meta_id' => $value->getId() + , 'value' => $original_name + ) ); } } @@ -870,8 +870,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface SET originalname = :originalname WHERE record_id = :record_id'; $params = array( - ':originalname' => $original_name - , ':record_id' => $this->get_record_id() + ':originalname' => $original_name + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); @@ -889,7 +889,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ public function get_title($highlight = false, searchEngine_adapter $searchEngine = null) { - $sbas_id = $this->get_sbas_id(); + $sbas_id = $this->get_sbas_id(); $record_id = $this->get_record_id(); if ($this->is_grouping()) @@ -899,8 +899,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $regfield['regname']; } - $title = ''; - $appbox = appbox::get_instance(); + $title = ''; + $appbox = appbox::get_instance(); $session = $appbox->get_session(); $fields = $this->get_databox()->get_meta_structure(); @@ -918,14 +918,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (count($fields_to_retrieve) > 0) { $retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine); - $titles = array(); + $titles = array(); foreach ($retrieved_fields as $key => $value) { if (trim($value['value'] === '')) continue; $titles[] = $value['value']; } - $title = trim(implode(' - ', $titles)); + $title = trim(implode(' - ', $titles)); } if (trim($title) === '') @@ -1012,7 +1012,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected function searchRegFields(databox_descriptionStructure $meta_struct) { - $fields = null; + $fields = null; $fields["regname"] = ""; $fields["regdesc"] = ""; $fields["regdate"] = ""; @@ -1086,11 +1086,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function substitute_subdef($name, system_file $pathfile) { $newfilename = $this->record_id . '_0_' . $name - . '.' . $pathfile->get_extension(); + . '.' . $pathfile->get_extension(); $base_url = ''; - $original_file = $subdef_def = false; + $original_file = $subdef_def = false; if ($name == 'document') { @@ -1140,7 +1140,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - $path = databox::dispatch($subdef_def->get_path()); + $path = databox::dispatch($subdef_def->get_path()); system_file::mkdir($path); $original_file = $path . $newfilename; } @@ -1150,9 +1150,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (trim($subdef_def->get_baseurl()) !== '') { $base_url = str_replace( - array((string) $subdef_def->get_path(), $newfilename) - , array((string) $subdef_def->get_baseurl(), '') - , $path_file_dest + array((string) $subdef_def->get_path(), $newfilename) + , array((string) $subdef_def->get_baseurl(), '') + , $path_file_dest ); } @@ -1169,18 +1169,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface try { - $appbox = \appbox::get_instance(); + $appbox = \appbox::get_instance(); $session = $appbox->get_session(); $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'DELETE FROM subdef WHERE record_id= :record_id AND name=:name'; + $sql = 'DELETE FROM subdef WHERE record_id= :record_id AND name=:name'; $stmt = $connbas->prepare($sql); $stmt->execute( - array( - ':record_id' => $this->record_id - , ':name' => $name - ) + array( + ':record_id' => $this->record_id + , ':name' => $name + ) ); $image_size = $system_file->get_technical_datas(); @@ -1195,18 +1195,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':record_id' => $this->record_id, - ':name' => $name, - ':baseurl' => $base_url, - ':filename' => $system_file->getFilename(), - ':width' => $image_size[system_file::TC_DATAS_WIDTH], - ':height' => $image_size[system_file::TC_DATAS_HEIGHT], - ':mime' => $system_file->get_mime(), - ':path' => $system_file->getPath(), - ':filesize' => $system_file->getSize() + ':record_id' => $this->record_id, + ':name' => $name, + ':baseurl' => $base_url, + ':filename' => $system_file->getFilename(), + ':width' => $image_size[system_file::TC_DATAS_WIDTH], + ':height' => $image_size[system_file::TC_DATAS_HEIGHT], + ':mime' => $system_file->get_mime(), + ':path' => $system_file->getPath(), + ':filesize' => $system_file->getSize() )); - $sql = 'UPDATE record SET moddate=NOW() WHERE record_id=:record_id'; + $sql = 'UPDATE record SET moddate=NOW() WHERE record_id=:record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -1225,7 +1225,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $type = $name == 'document' ? 'HD' : $name; $session->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, ''); + ->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, ''); } catch (Exception $e) { @@ -1243,13 +1243,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface protected function set_xml(DOMDocument $dom_doc) { $connbas = $this->get_databox()->get_connection(); - $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute( - array( - ':xml' => $dom_doc->saveXML(), - ':record_id' => $this->record_id - ) + array( + ':xml' => $dom_doc->saveXML(), + ':record_id' => $this->record_id + ) ); $this->reindex(); @@ -1284,6 +1284,23 @@ class record_adapter implements record_Interface, cache_cacheableInterface $caption_field = new caption_field($databox_field, $this); + $vocab = $vocab_id = null; + + if ($params['vocabularyId'] && $databox_field->getVocabularyControl()) + { + try + { + $vocab = $databox_field->getVocabularyControl(); + $vocab_id = $params['vocabularyId']; + $vocab->validate($vocab_id); + } + catch (\Exception $e) + { + $vocab = $vocab_id = null; + } + } + + if (trim($params['meta_id']) !== '') { $tmp_val = trim($params['value']); @@ -1298,11 +1315,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface else { $caption_field_value->set_value($params['value']); + if($vocab && $vocab_id) + { + $caption_field_value->setVocab($vocab, $vocab_id); + } } } else { - $caption_field_value = caption_Field_Value::create($databox_field, $this, $params['value']); + $caption_field_value = caption_Field_Value::create($databox_field, $this, $params['value'], $vocab, $vocab_id); } $this->caption_record = null; @@ -1348,9 +1369,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function reindex() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET status=(status & ~7 | 4) + $sql = 'UPDATE record SET status=(status & ~7 | 4) WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); $this->delete_data_from_cache(self::CACHE_STATUS); @@ -1364,8 +1385,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function rebuild_subdefs() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); return $this; @@ -1378,10 +1399,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function write_metas() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record + $sql = 'UPDATE record SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . ' WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); return $this; @@ -1397,21 +1418,21 @@ class record_adapter implements record_Interface, cache_cacheableInterface $connbas = connection::getPDOConnection($this->get_sbas_id()); $registry = registry::get_instance(); - $sql = 'UPDATE record SET status = 0b' . $status . ' + $sql = 'UPDATE record SET status = 0b' . $status . ' WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); - $sql = 'REPLACE INTO status (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; + $sql = 'REPLACE INTO status (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; $stmt = $connbas->prepare($sql); $status = strrev($status); - for ($i = 4; $i < strlen($status); $i++) + for ($i = 4; $i < strlen($status); $i++) { $stmt->execute(array( - ':record_id' => $this->get_record_id(), - ':name' => $i, - ':value' => $status[$i] + ':record_id' => $this->get_record_id(), + ':name' => $i, + ':value' => $status[$i] )); } $stmt->closeCursor(); @@ -1421,10 +1442,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface $sphinx = sphinxrt::get_instance($registry); $sbas_params = phrasea::sbas_params(); - $sbas_id = $this->get_sbas_id(); + $sbas_id = $this->get_sbas_id(); if (isset($sbas_params[$sbas_id])) { - $params = $sbas_params[$sbas_id]; + $params = $sbas_params[$sbas_id]; $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname']))); $sphinx->update_status(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_en", "metadatas" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc), $this->get_sbas_id(), $this->get_record_id(), strrev($status)); } @@ -1467,9 +1488,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface } } } - $regname = ''; - if ($sxe = simplexml_load_string($this->get_xml())) - $regname = (string) $sxe->description->$balisename; + $regname = ''; + if ($sxe = simplexml_load_string($this->get_xml())) + $regname = (string) $sxe->description->$balisename; return $regname; } @@ -1488,7 +1509,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface if ($is_grouping) { - $uuid = uuid::generate_v4(); + $uuid = uuid::generate_v4(); $sha256 = null; } else @@ -1496,7 +1517,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $uuid = $system_file->read_uuid(); if (!uuid::is_valid($uuid)) { - $uuid = uuid::generate_v4(); + $uuid = uuid::generate_v4(); } $sha256 = $system_file->get_sha256(); } @@ -1520,32 +1541,32 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':coll_id' => $coll_id - , ':parent_record_id' => ($is_grouping ? 1 : 0) - , ':type' => $type - , ':sha256' => $sha256 - , ':uuid' => $uuid - , ':originalname' => $original_name - , ':mime' => $system_file->get_mime() + ':coll_id' => $coll_id + , ':parent_record_id' => ($is_grouping ? 1 : 0) + , ':type' => $type + , ':sha256' => $sha256 + , ':uuid' => $uuid + , ':originalname' => $original_name + , ':mime' => $system_file->get_mime() )); $record_id = $connbas->lastInsertId(); - $record = new self($sbas_id, $record_id); + $record = new self($sbas_id, $record_id); try { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(); $session = $appbox->get_session(); - $log_id = $session->get_logger($databox)->get_id(); + $log_id = $session->get_logger($databox)->get_id(); - $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) + $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) VALUES (null, :log_id, now(), :record_id, "add", :coll_id,"")'; $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':log_id' => $log_id, - ':record_id' => $record_id, - ':coll_id' => $coll_id + ':log_id' => $log_id, + ':record_id' => $record_id, + ':coll_id' => $coll_id )); $stmt->closeCursor(); } @@ -1574,7 +1595,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $tc_datas = $system_file->get_technical_datas(); - $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) + $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; $stmt = $connbas->prepare($sql); @@ -1584,9 +1605,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface continue; $stmt->execute(array( - ':record_id' => $record_id - , ':name' => $name - , ':value' => $value + ':record_id' => $record_id + , ':name' => $name + , ':value' => $value )); } $stmt->closeCursor(); @@ -1620,14 +1641,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $conn->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $records = array(); foreach ($rs as $row) { - $k = count($records); + $k = count($records); $records[$k] = new record_adapter($sbas_id, $row['record_id']); } @@ -1652,11 +1673,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ public function delete() { - $connbas = $this->get_databox()->get_connection(); - $sbas_id = $this->get_databox()->get_sbas_id(); - $appbox = appbox::get_instance(); + $connbas = $this->get_databox()->get_connection(); + $sbas_id = $this->get_databox()->get_sbas_id(); + $appbox = appbox::get_instance(); $registry = $appbox->get_registry(); - $conn = $appbox->get_connection(); + $conn = $appbox->get_connection(); $ftodel = array(); foreach ($this->get_subdefs() as $subdef) @@ -1664,30 +1685,30 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (!$subdef->is_physically_present()) continue; - $ftodel[] = $subdef->get_pathfile(); + $ftodel[] = $subdef->get_pathfile(); $watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file(); if (file_exists($watermark)) - $ftodel[] = $watermark; - $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file(); + $ftodel[] = $watermark; + $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file(); if (file_exists($stamp)) - $ftodel[] = $stamp; + $ftodel[] = $stamp; } $origcoll = phrasea::collFromBas($this->get_base_id()); $appbox->get_session()->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_DELETE, $origcoll, $this->get_xml()); + ->log($this, Session_Logger::EVENT_DELETE, $origcoll, $this->get_xml()); - $sql = "DELETE FROM record WHERE record_id = :record_id"; + $sql = "DELETE FROM record WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = 'SELECT id FROM metadatas WHERE record_id = :record_id'; + $sql = 'SELECT id FROM metadatas WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(); + $rs = $stmt->fetchAll(); $stmt->closeCursor(); try @@ -1698,7 +1719,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (isset($sbas_params[$sbas_id])) { - $params = $sbas_params[$sbas_id]; + $params = $sbas_params[$sbas_id]; $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname']))); foreach ($rs as $row) { @@ -1712,49 +1733,49 @@ class record_adapter implements record_Interface, cache_cacheableInterface unset($e); } - $sql = "DELETE FROM metadatas WHERE record_id = :record_id"; + $sql = "DELETE FROM metadatas WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM prop WHERE record_id = :record_id"; + $sql = "DELETE FROM prop WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM idx WHERE record_id = :record_id"; + $sql = "DELETE FROM idx WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM permalinks + $sql = "DELETE FROM permalinks WHERE subdef_id IN (SELECT subdef_id FROM subdef WHERE record_id=:record_id)"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM subdef WHERE record_id = :record_id"; + $sql = "DELETE FROM subdef WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM technical_datas WHERE record_id = :record_id"; + $sql = "DELETE FROM technical_datas WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM thit WHERE record_id = :record_id"; + $sql = "DELETE FROM thit WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM regroup WHERE rid_parent = :record_id"; + $sql = "DELETE FROM regroup WHERE rid_parent = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM regroup WHERE rid_child = :record_id"; + $sql = "DELETE FROM regroup WHERE rid_child = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -1814,7 +1835,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface echo 'Aucune sous definition a faire pour ' . $this->get_type() . "\n"; } - $subdef_class = 'databox_subdef' . ucfirst($this->get_type()); + $subdef_class = 'databox_subdef' . ucfirst($this->get_type()); $record_subdefs = $this->get_subdefs(); foreach ($subdefs as $subdef) @@ -1876,7 +1897,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected function generate_subdef(databox_subdefInterface $subdef_class, $pathdest) { - $registry = registry::get_instance(); + $registry = registry::get_instance(); $generated = $subdef_class->generate($this, $pathdest, $registry); return $this; @@ -1928,12 +1949,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface (null, :log_id, now(), :rec, :referrer, :site)'; $params = array( - ':log_id' => $log_id - , ':rec' => $this->get_record_id() - , ':referrer' => $referrer - , ':site' => $gv_sit + ':log_id' => $log_id + , ':rec' => $this->get_record_id() + , ':referrer' => $referrer + , ':site' => $gv_sit ); - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); @@ -1974,7 +1995,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_container_baskets() { $Core = bootstrap::getCore(); - $em = $Core->getEntityManager(); + $em = $Core->getEntityManager(); $repo = $em->getRepository('\Entities\Basket'); @@ -1992,15 +2013,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface public static function get_records_by_originalname(databox $databox, $original_name, $offset_start = 0, $how_many = 10) { $offset_start = (int) ($offset_start < 0 ? 0 : $offset_start); - $how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many); + $how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many); $sql = sprintf('SELECT record_id FROM record WHERE original_name = :original_name LIMIT %d, %d' - , $offset_start, $how_many); + , $offset_start, $how_many); $stmt = $databox->get_connection()->prepare($sql); $stmt->execute(array(':original_name' => $original_name)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $records = array(); @@ -2037,18 +2058,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface ORDER BY g.ord ASC, dateadd ASC, record_id ASC'; $params = array( - ':GV_site' => $appbox->get_registry()->get('GV_sit') - , ':usr_id' => $appbox->get_session()->get_usr_id() - , ':record_id' => $this->get_record_id() + ':GV_site' => $appbox->get_registry()->get('GV_sit') + , ':usr_id' => $appbox->get_session()->get_usr_id() + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $set = new set_selection(); - $i = 1; + $i = 1; foreach ($rs as $row) { $set->add_element(new record_adapter($this->get_sbas_id(), $row['record_id'], $i)); @@ -2081,14 +2102,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface $params = array( - ':GV_site' => $appbox->get_registry()->get('GV_sit') - , ':usr_id' => $appbox->get_session()->get_usr_id() - , ':record_id' => $this->get_record_id() + ':GV_site' => $appbox->get_registry()->get('GV_sit') + , ':usr_id' => $appbox->get_session()->get_usr_id() + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $set = new set_selection(); @@ -2134,9 +2155,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface VALUES (null, :parent_record_id, :record_id, NOW(), :ord)'; $params = array( - ':parent_record_id' => $this->get_record_id() - , ':record_id' => $record->get_record_id() - , ':ord' => $ord + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() + , ':ord' => $ord ); $stmt = $connbas->prepare($sql); @@ -2144,7 +2165,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -2165,15 +2186,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface AND rid_child = :record_id"; $params = array( - ':parent_record_id' => $this->get_record_id() - , ':record_id' => $record->get_record_id() + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() ); $stmt = $connbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor();