Merge remote-tracking branch 'upstream/master' into feature/controller-as-service

This commit is contained in:
Benoît Burnichon
2015-06-18 17:18:06 +02:00
16 changed files with 784 additions and 767 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -66,6 +66,7 @@ class Xmlhttp implements ControllerProviderInterface
$sbas_id = $request->get('sbid');
try {
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$connbas = $databox->get_connection();
@@ -125,22 +126,6 @@ class Xmlhttp implements ControllerProviderInterface
printf("newid=%s<br/>\n", $te->getAttribute("id"));
}
$soldid = str_replace(".", "d", $oldid) . "d";
$snewid = str_replace(".", "d", $pid) . "d";
$l = strlen($soldid) + 1;
$sql = "UPDATE thit
SET value=CONCAT('$snewid', SUBSTRING(value FROM $l))
WHERE value LIKE :like";
if ($request->get("debug")) {
printf("soldid=%s ; snewid=%s<br/>\nsql=%s<br/>\n", $soldid, $snewid, $sql);
} else {
$stmt = $connbas->prepare($sql);
$stmt->execute([':like' => $soldid . '%']);
$stmt->closeCursor();
}
$refreshid = $parentnode->getAttribute('id');
$refresh['T' . $refreshid] = [
'type' => 'T',
@@ -185,22 +170,6 @@ class Xmlhttp implements ControllerProviderInterface
printf("newid=%s<br/>\n", $te->getAttribute("id"));
}
$soldid = str_replace(".", "d", $oldid) . "d";
$snewid = str_replace(".", "d", $pid) . "d";
$l = strlen($soldid) + 1;
$sql = "UPDATE thit
SET value = CONCAT('$snewid', SUBSTRING(value FROM $l))
WHERE value LIKE :like";
if ($request->get("debug")) {
printf("soldid=%s ; snewid=%s<br/>\nsql=%s<br/>\n", $soldid, $snewid, $sql);
} else {
$stmt = $connbas->prepare($sql);
$stmt->execute([':like' => $soldid . '%']);
$stmt->closeCursor();
}
$thchanged = true;
}
@@ -237,7 +206,7 @@ class Xmlhttp implements ControllerProviderInterface
return $app->json($ret);
}
private function renumerate($lang, $node, $id, &$chgids, $depth = 0)
private function renumerate($lang, \DOMElement $node, $id, &$chgids, $depth = 0)
{
$node->setAttribute("id", $id);
@@ -265,6 +234,7 @@ class Xmlhttp implements ControllerProviderInterface
return $app->json($json);
}
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$dom_thesau = $databox->get_dom_thesaurus();
@@ -442,7 +412,7 @@ class Xmlhttp implements ControllerProviderInterface
], true)));
if (null !== $request->get('bid')) {
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid'));
$dom = $databox->get_dom_thesaurus();
@@ -468,7 +438,7 @@ class Xmlhttp implements ControllerProviderInterface
if (null === $request->get("bid")) {
return new Response('Missing bid parameter', 400);
}
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $request->get("bid"));
$dom = $databox->get_dom_thesaurus();
@@ -614,6 +584,7 @@ class Xmlhttp implements ControllerProviderInterface
return new Response('Missing bid parameter', 400);
}
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid'));
$dom = $databox->get_dom_thesaurus();
if (!$dom) {
@@ -770,6 +741,7 @@ class Xmlhttp implements ControllerProviderInterface
$thid = implode('.', $tids);
try {
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox($sbid);
$connbas = $databox->get_connection();
$dbname = \phrasea::sbas_labels($sbid, $app);
@@ -872,6 +844,7 @@ class Xmlhttp implements ControllerProviderInterface
$tts = array_reverse($tts);
}
/** @var \DOMElement[] $ts */
foreach ($tts as $ts) {
$class = '';
if ($ts['nts'] > 0) {
@@ -926,7 +899,7 @@ class Xmlhttp implements ControllerProviderInterface
], 'html' => $html]);
}
private function buildBranchLabel($dbname, $language, $n, &$key0, &$nts0)
private function buildBranchLabel($dbname, $language, \DOMElement $n, &$key0, &$nts0)
{
$key0 = null; // key of the sy in the current language
// (or key of the first sy if we can't find good lng)
@@ -987,6 +960,7 @@ class Xmlhttp implements ControllerProviderInterface
$html = '';
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$dom = $databox->get_dom_thesaurus();
@@ -1055,7 +1029,7 @@ class Xmlhttp implements ControllerProviderInterface
return [$term, $context];
}
private function getBranchesHTML($bid, $srcnode, &$html, $depth)
private function getBranchesHTML($bid, \DOMElement $srcnode, &$html, $depth)
{
$tid = $srcnode->getAttribute('id');
$class = 'h';
@@ -1138,8 +1112,8 @@ class Xmlhttp implements ControllerProviderInterface
return json_encode($ret);
}
$databox = $app['phraseanet.appbox']->get_databox((int) $bid);
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$dom = $databox->get_dom_thesaurus();
if (!$dom) {
@@ -1216,6 +1190,7 @@ class Xmlhttp implements ControllerProviderInterface
return new Response('Missing bid parameter', 400);
}
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox((int) $bid);
$dom = $databox->get_dom_thesaurus();
@@ -1226,6 +1201,7 @@ class Xmlhttp implements ControllerProviderInterface
$xpath = $databox->get_xpath_thesaurus();
$q = '/thesaurus';
$zhtml = '';
if (($znode = $xpath->query($q)->item(0))) {
$q2 = '//sy';
if ($request->get('t')) {
@@ -1244,10 +1220,8 @@ class Xmlhttp implements ControllerProviderInterface
}
}
$zhtml = '';
$this->getBrancheXML($bid, $znode, $zhtml, 0);
} else {
$zhtml = '';
for ($i = 0; $i < $nodes->length; $i++) {
$n = $nodes->item($i);
$t = $n->getAttribute('v');
@@ -1264,7 +1238,7 @@ class Xmlhttp implements ControllerProviderInterface
return new Response($zhtml, 200, array('Content-Type' => 'text/xml'));
}
private function getBrancheJson($bid, $srcnode, &$ret, $depth)
private function getBrancheJson($bid, \DOMElement $srcnode, &$ret, $depth)
{
$tid = $srcnode->getAttribute('id');
$nts = 0;
@@ -1301,7 +1275,7 @@ class Xmlhttp implements ControllerProviderInterface
return $nret;
}
private function getBrancheXML($bid, $srcnode, &$html, $depth)
private function getBrancheXML($bid, \DOMElement $srcnode, &$html, $depth)
{
$tid = $srcnode->getAttribute('id');
$class = 'h';
@@ -1424,9 +1398,9 @@ class Xmlhttp implements ControllerProviderInterface
$tsbas[$ksbas]['lid'] = "'" . implode("','", $lids) . "'";
// count records
$sql = 'SELECT DISTINCT record_id AS r
FROM thit WHERE value IN (:lids)
ORDER BY record_id';
$sql = 'SELECT DISTINCT record_id AS r'
. ' FROM thit WHERE value IN (:lids)'
. ' ORDER BY record_id';
$stmt = $connbas->prepare($sql);
$stmt->execute(['lids' => $lids]);
$tsbas[$ksbas]['trids'] = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
@@ -1441,7 +1415,6 @@ class Xmlhttp implements ControllerProviderInterface
/* @var $databox databox */
try {
$databox = $appbox->get_databox($sbas['sbas_id']);
$connbas = $databox->get_connection();
} catch (\Exception $e) {
continue;
}
@@ -1471,6 +1444,7 @@ class Xmlhttp implements ControllerProviderInterface
foreach ($field->get_values() as $v) {
$keep = true;
$vtxt = $app['unicode']->remove_indexer_chars($v->getValue());
/** @var \DOMElement $sy */
foreach ($sbas['tvals'][$fname] as $sy) {
if ($sy->getAttribute('w') == $vtxt) {
$keep = false;
@@ -1539,6 +1513,7 @@ class Xmlhttp implements ControllerProviderInterface
$sbid = (int) $request->get('sbid');
try {
/** @var \databox $databox */
$databox = $app['phraseanet.appbox']->get_databox($sbid);
$html = "" . '<LI id="TX_P.' . $sbid . '.T" class="expandable">' . "\n";
@@ -1546,6 +1521,7 @@ class Xmlhttp implements ControllerProviderInterface
$html .= "\t" . '<span>' . \phrasea::sbas_labels($sbid, $app) . '</span>' . "\n";
if ($request->get('t')) {
$dom_struct = null;
if ($request->get('field') != '') {
$domth = $databox->get_dom_thesaurus();
$dom_struct = $databox->get_dom_structure();
@@ -1607,7 +1583,7 @@ class Xmlhttp implements ControllerProviderInterface
], 'html' => $html]);
}
private function buildTermLabel($language, $n, &$key0, &$nts0)
private function buildTermLabel($language, \DOMElement $n, &$key0, &$nts0)
{
$lngfound = false; // true when wet met a first synonym in the current language
$key0 = null; // key of the sy in the current language (or key of the first sy if we can't find good lng)
@@ -1649,7 +1625,7 @@ class Xmlhttp implements ControllerProviderInterface
return $label;
}
private function getHTMLTerm($sbid, $lng, $srcnode, &$html, $depth = 0)
private function getHTMLTerm($sbid, $lng, \DOMElement $srcnode, &$html, $depth = 0)
{
$tid = $srcnode->getAttribute('id');
@@ -1691,6 +1667,7 @@ class Xmlhttp implements ControllerProviderInterface
} else {
$html .= $tab . '<UL>' . "\n";
// dump every ts
/** @var \DOMElement[] $ts */
foreach ($tts as $ts) {
$class = '';
if ($ts['nts'] > 0) {

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class CandidateAccepted extends ThesaurusEvent
{
private $new_id;
public function __construct(\databox $databox, $new_id)
{
parent::__construct($databox);
$this->new_id = $new_id;
}
public function getID()
{
return $this->new_id;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class ConceptDeleted extends ThesaurusEvent
{
private $parent_id; // the former parent
private $deleted_synonyms; // the former synonyms (deleted)
public function __construct(\databox $databox, $parent_id, array $deleted_synonyms)
{
parent::__construct($databox);
$this->parent_id = $parent_id;
$this->deleted_synonyms = $deleted_synonyms;
}
public function getParentID()
{
return $this->parent_id;
}
public function getSynonyms()
{
return $this->deleted_synonyms;
}
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class FieldLinked extends ThesaurusEvent
{
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class Imported extends ThesaurusEvent
{
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class ItemAdded extends ThesaurusEvent
{
private $new_id; // the new id
public function __construct(\databox $databox, $new_id)
{
parent::__construct($databox);
$this->new_id = $new_id;
}
public function getID()
{
return $this->new_id;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class ItemTrashed extends ThesaurusEvent
{
private $parent_id; // the former parent
private $trash_id; // the new id in cterms
public function __construct(\databox $databox, $parent_id, $trash_id)
{
parent::__construct($databox);
$this->parent_id = $parent_id;
$this->trash_id = $trash_id;
}
public function getParentID()
{
return $this->parent_id;
}
public function getNewID()
{
return $this->trash_id;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class SynonymLngChanged extends ThesaurusEvent
{
private $synonym_id;
public function __construct(\databox $databox, $synonym_id)
{
parent::__construct($databox);
$this->synonym_id = $synonym_id;
}
public function getID()
{
return $this->synonym_id;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
/**
* Class SynonymParm
* @package Alchemy\Phrasea\Core\Event\Thesaurus
*
* a small object passed as parameter to thesaurus events.
* usefull when the synonym does not exists anymore in the thesaurus (after deletion)
*/
class SynonymParm
{
private $value; // as the <sy> 'v' attribute in xml
private $lng; // the 'lng' attribute
public function __construct($value, $lng)
{
$this->value = $value;
$this->lng = $lng;
}
/**
* @return \string
*/
public function getValue()
{
return $this->value;
}
/**
* @return \string
*/
public function getLng()
{
return $this->lng;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
class SynonymPositionChanged extends ThesaurusEvent
{
private $synonym_id;
public function __construct(\databox $databox, $synonym_id)
{
parent::__construct($databox);
$this->synonym_id = $synonym_id;
}
public function getID()
{
return $this->synonym_id;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Thesaurus;
use Symfony\Component\EventDispatcher\Event;
abstract class ThesaurusEvent extends Event
{
private $databox;
public function __construct(\databox $databox)
{
$this->databox = $databox;
}
/**
* @return \databox
*/
public function getDatabox()
{
return $this->databox;
}
}

View File

@@ -50,4 +50,16 @@ final class PhraseaEvents
const RECORD_EDIT = 'record.edit';
const RECORD_UPLOAD = 'record.upload';
const THESAURUS_IMPORTED = 'thesaurus.imported';
const THESAURUS_FIELD_LINKED = 'thesaurus.field-linked';
const THESAURUS_CANDIDATE_ACCEPTED_AS_CONCEPT = 'thesaurus.candidate-accepted-as-concept';
const THESAURUS_CANDIDATE_ACCEPTED_AS_SYNONYM = 'thesaurus.candidate-accepted-as-synonym';
const THESAURUS_SYNONYM_LNG_CHANGED = 'thesaurus.synonym-lng-changed';
const THESAURUS_SYNONYM_POSITION_CHANGED = 'thesaurus.synonym-position-changed';
const THESAURUS_SYNONYM_TRASHED = 'thesaurus.synonym-trashed';
const THESAURUS_CONCEPT_TRASHED = 'thesaurus.concept-trashed';
const THESAURUS_CONCEPT_DELETED = 'thesaurus.concept-deleted';
const THESAURUS_SYNONYM_ADDED = 'thesaurus.synonym-added';
const THESAURUS_CONCEPT_ADDED = 'thesaurus.concept-added';
}

View File

@@ -57,11 +57,7 @@
{% else %}
{% if nb_candidates_bad > 0 %}
// present dans les candidats, mais aucun champ acceptable : on informe
{% if nb_candidates_bad == 1 %}
{% set prop_label = 'thesaurus:: est candidat en provenance des champs mais ne peut etre accepte a cet emplacement du thesaurus' | trans %}
{% else %}
{% set prop_label = 'thesaurus:: est candidat en provenance des champs mais ne peut etre accepte a cet emplacement du thesaurus' | trans %}
{% endif %}
{% set prop_label = 'thesaurus:: est candidat en provenance des champs mais ne peut etre accepte a cet emplacement du thesaurus' | trans %}
{% else %}
// pas present dans les candidats
{% set prop_label = 'thesaurus:: n\'est pas present dans les candidats' | trans %}

View File

@@ -165,7 +165,6 @@
// gui callback du menu des synonymes
function cbME_synonym(action, cbParm, menuelem_id)
{
if(action == "INIT")
{
if(nsy <= 1)

View File

@@ -160,7 +160,6 @@
<a href="javascript:void(0)" class="disabled" id="kcterm_accept">{{ 'thesaurus::menu: accepter' | trans }}</a>
<div class="line"></div>
<a href="javascript:void(0)" class="" id="kcterm_delete">{{ 'thesaurus::menu: supprimer' | trans }}</a>
<a href="javascript:void(0)" class="" id="kcterm_delete0hits">{{ 'thesaurus::menu: supprimer les candidats a 0 hits' | trans }}</a>
<div class="line"></div>
<a href="javascript:void(0)" class="" id="kcterm_search">{{ 'thesaurus::menu: chercher' | trans }}</a>
<a href="javascript:void(0)" class="" id="kcterm_export">{{ 'thesaurus::menu: exporter' | trans }}</a>
@@ -375,18 +374,6 @@
{
case "TCE_": // racine (STOCK) ou premier niveau (champ ou [trash])
// alert(o.id);
if(o.id == "TCE_C")
{
// racine
if(om=document.getElementById("kcterm_delete0hits"))
om.className = "disabled";
}
else
{
// premier niveau
if(om=document.getElementById("kcterm_delete0hits"))
om.className = "";
}
if(om=document.getElementById("kcterm_reject"))
om.className = "disabled";
if(om=document.getElementById("kcterm_accept"))
@@ -402,8 +389,6 @@
break;
case "THE_": // terme candidat
// alert("id: "+o.id+" ; p: "+o.parentNode.id);
if(om=document.getElementById("kcterm_delete0hits"))
om.className = "disabled";
if(o.id.substr(4, 1)=="R")
{
if(om=document.getElementById("kcterm_reject"))
@@ -511,37 +496,6 @@
}
}
break;
case "kcterm_delete0hits":
url = "xmlhttp/searchnohits.x.php";
url += "?bid={{ bid }}";
url += "&id=" + o.id.substr(4);
url += "&typ=CT";
ret = loadXMLDoc(url, null, true);
// alert(ret);
n_nohits = ret.documentElement.getAttribute("n_nohits");
if(n_nohits==0)
{
alert("{{ 'thesaurus:: Tous les termes ont des hits' | trans | e('js') }}");
return;
}
else
{
if(confirm("{{ 'thesaurus:: Des termes de cette branche ne renvoient pas de hits. Les supprimer ?' | trans | e('js') }}"));
{
url = "xmlhttp/deletenohits.x.php";
url += "?bid={{ bid }}";
url += "&id=" + o.id.substr(4);
url += "&typ=CT";
ret = loadXMLDoc(url, null, true);
reloadCtermsBranch(o.id.substr(4));
}
}
break;
case "kcterm_reject":
var myObj = { "win":window };
@@ -1434,52 +1388,6 @@
}
}
function reloadbranch2(thb, thid, typ)
{
new_thb = null;
url = "xmlhttp/gethtmlbranch.x.php";
parms = "bid={{ bid }}";
parms += "&id=" + thid;
parms += "&typ=" + typ;
alert(url + "?" + parms);
ret = loadXMLDoc(url, parms, true);
alert(ret);
ts = ret.getElementsByTagName("html");
if(ts.length==1)
{
/*
thb.innerHTML = ts.item(0).firstChild.nodeValue;
*/
if(document.importNode) // safari ?
{
thb.innerHTML = "";
for(n=ts.item(0).firstChild; n; n=n.nextSibling)
docImport(n, thb);
}
else
{
t = "";
for(n=ts.item(0).firstChild; n; n=n.nextSibling)
t += n.xml; // marche pas sous safari...
// IE fails to recognize <tag/> as a closed tag when using innerHTML, so replace it with <tag></tag>
// except for br, img, and hr elements.
var expr = new RegExp("<(?:(?!br|img|hr)([a-zA-Z]+))([^>]*)/>", "ig");
t = t.replace(expr, "<$1$2></$1>");
// alert(t);
thb.innerHTML = t;
}
}
}
myGUI.setClickable("T0", cbDD_T0);
myGUI.setDraggable("T0", cbDD_T0);