Skip to content

Commit

Permalink
Merge branch 'pactols-0204'
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Apr 2, 2019
2 parents 007f709 + 367f4c5 commit d12012b
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 83 deletions.
2 changes: 2 additions & 0 deletions lodel/scripts/genericlogic.php
Expand Up @@ -259,7 +259,9 @@ function_exists('validfield') || include "validfunc.php";
$value[$keys[$i]] = lodel_strip_tags($value[$keys[$i]], $field->allowedtags);
}
} else {
if ($field->type !== 'mltext') {
$value = lodel_strip_tags($value, $field->allowedtags);
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions lodel/scripts/logic/class.entities_edition.php
Expand Up @@ -180,11 +180,20 @@ function loop_entries_in_entities_rec ($context, $funcname, &$votype, &$checkarr
{
global $db;
if(!isset($context['id'])) return;
$screen_name = $db->getRow(lq("SELECT field.name as screen_name, type.class as class_type from #_TP_tablefields field, #_TP_entrytypes type WHERE field.g_name='screen name' AND field.class=type.class AND type.id=".$context['idtype']));
$is_screenname = false;
if (!empty($screen_name)) {
$is_screenname = true;
}
// get the entries
$result = $db->execute(lq("SELECT * FROM #_TP_entries WHERE idtype='". $votype->id. "' AND idparent='". $context['id']. "' AND status>-64 ORDER BY ". $votype->sort)) or trigger_error("SQL ERROR :<br />".$GLOBALS['db']->ErrorMsg(), E_USER_ERROR);

while (!$result->EOF) {
$localcontext = array_merge($context, $result->fields);
if ($is_screenname) {
$sn_value = $db->getRow(lq("SELECT ".$screen_name['screen_name']." as snname FROM ".$screen_name['class_type']." WHERE identry=".$result->fields['id']));
$localcontext['screen_name']=multilingue($sn_value['snname'], $context['sitelang']);
}
$localcontext['root'] = '';
$localcontext['selected'] = $checkarr && in_array($result->fields['g_name'],$checkarr) ? "selected=\"selected\"" : "";
call_user_func("code_do_$funcname", $localcontext);
Expand Down
22 changes: 18 additions & 4 deletions lodel/scripts/logic/class.entries.php
Expand Up @@ -204,6 +204,7 @@ public function listAction (&$context, &$error)
*/
public function editAction (&$context, &$error, $clean=false)
{

if (empty($context['idtype'])) {
trigger_error("ERROR: idtype must be known in EntriesLogic::editAction", E_USER_ERROR);
}
Expand Down Expand Up @@ -253,7 +254,8 @@ public function editAction (&$context, &$error, $clean=false)
$id=$context['id'] = $vo->id;
}

$context['data'][$g_index_key]=$context['g_name'];
if (empty($context['data'][$g_index_key])) {
$context['data'][$g_index_key]=$context['g_name']; }
}

if(empty($context['data'][$g_index_key]))
Expand Down Expand Up @@ -301,17 +303,29 @@ public function editAction (&$context, &$error, $clean=false)
}

// populate the entry table

$vo->idtype=$idtype;
$vo->g_name=$index_key;
$vo->sortkey=makeSortKey($vo->g_name);
if (empty($context['g_name'])) {
$vo->g_name=$index_key;
} else {
$vo->g_name = $context['g_name'];
}
if (empty($context['sortkey'])) {
$sorkey = $vo->g_name;
} else {
$sorkey = $context['sortkey'];
}
$vo->sortkey=makeSortKey($sorkey);
$id=$context['id']=$dao->save($vo);

// save the class table
$gdao=DAO::getGenericDAO($class,"identry");
$gdao->instantiateObject($gvo);
$context['data']['id']=$context['id'];

$this->_populateObject($gvo,$context['data']);
$gvo->identry=$id;

$this->_moveFiles($id,$this->files_to_move,$gvo);
$gdao->save($gvo,$new);
}
Expand Down Expand Up @@ -922,4 +936,4 @@ protected function _deleteRelatedTables($id)
}
}

} // class
} // class
84 changes: 84 additions & 0 deletions lodel/scripts/loops.php
Expand Up @@ -902,6 +902,90 @@ function loop_alphabetSpec($context, $funcname)

usecurrentdb();
}
/**
* Boucle Lodelscript qui affiche la première lettre (distincte) de tous les tuples d'un champ
* Spécifique au cas où le champs de tri est un mltext dans une autre table
* @param array $context le contexte
* @param string $funcname le nom de la fonction
*/
function loop_alphabetSpecEntries($context, $funcname)
{
global $db;
if(empty($context['table']) || empty($context['field']) || empty($context['attributes_table']) || empty($context['idtype']))
trigger_error("ERROR: loop_alphabetSpec requires arguments 'table', 'attributes_table', 'idtype' and 'field'.", E_USER_ERROR);

$whereSelect = $whereCount = '';

if (!empty($context['user']['lang'])) {
$user_lang = $context['lodeluser']['lang'];
} else {
$user_lang = $context['sitelang'];
}

$table = $context['table'];
$whereSelect = "WHERE idtype = '{$context['idtype']}'";
$whereCount = " idtype = '{$context['idtype']}' AND ";

$status = C::get('editor', 'lodeluser') ? ' status > -64 ' : ' status > 0 ';

$sql = lq("SELECT entry.id, attribute.{$context['field']} as sortkey, attribute.{$context['index_key']} as e_name FROM #_TP_{$context['table']} entry, #_TP_{$context['attributes_table']} attribute WHERE entry.id=attribute.identry AND entry.idtype={$context['idtype']} AND ".$status);

$results = $db->getArray(lq($sql));
$fields = array();
$firstletters = array();

foreach ($results as $result) {
$fields[$result['id']] = multilingue($result['sortkey'],$user_lang);
if (empty($fields[$result['id']])) {
$fields[$result['id']] = $result['e_name'];
}
$firstletters[$result['id']] = strtoupper(substr($fields[$result['id']], 0, 1));

}
$count_letters = array_count_values($firstletters);

$lettres = array_unique($firstletters);
if(empty($lettres))
{
if(function_exists('code_alter_'.$funcname))
call_user_func('code_alter_'.$funcname, $context);

usecurrentdb();
return;
}

foreach($lettres as &$lettre) {
if($lettre != '<' && $lettre != '>' && $lettre != ' ')
$lettre = strtoupper(makeSortKey($lettre));
}


for ($l = 'A'; $l != 'AA'; $l++) {
$context['lettre'] = $l;
$context['nbresults'] = $count_letters[$l];
call_user_func("code_do_$funcname", $context);
}

// bug PHP : si on ne passe le tableau en référence, il modifie la derniere valeur du tableau et vire les références !!!
foreach($lettres as &$lettre) {
if($lettre >= '0' && $lettre <= '9') {
$context['lettre'] = $lettre;
$context['nbresults'] = $count_letters[$context['lettre']];
call_user_func("code_do_$funcname", $context);
}
}

foreach($lettres as &$lettre) {
if($lettre == '') continue;
if(!preg_match("/[A-Z]/", $lettre) && !preg_match("/[0-9]/", $lettre)) {
$context['lettre'] = $lettre;
$context['nbresults'] = $count_letters[$context['lettre']];
call_user_func("code_do_$funcname", $context);
}
}

usecurrentdb();
}

function loop_classtypes($context, $funcname)
{
Expand Down
35 changes: 30 additions & 5 deletions lodel/scripts/teiparser.php
Expand Up @@ -526,10 +526,12 @@ private function _parseAfter()
{
$entries = $this->_contents['entries'];
$persons = $this->_contents['persons'];

unset($this->_contents['entries'], $this->_contents['persons']);

// re-order blocks from their ids
// used for inline blocks that are converted to real blocks in the TEI

foreach($this->_tablefields as $name => $obj)
{
if($obj instanceof internalstylesVO || $obj instanceof characterstylesVO || 'entries' === $obj->type || 'persons' === $obj->type) continue;
Expand All @@ -556,12 +558,23 @@ private function _parseAfter()

// validating fields
array_walk($this->_contents, array($this, '_validField'));
// strip tags from entries

// strip tags from entries
foreach($entries as $k => $v)
$entries[$k] = strip_tags(join(',', $v));
foreach($entries as $k => $v) {
$g_name = false;
foreach($v as $ind_v => $val_v) {
if (isset($val_v['g_name'])){
$g_name = true;
break;
}
}
if (!$g_name) {
$entries[$k] = strip_tags(join(',', $v));
}
}

$this->_contents['entries'] = $entries;

foreach($this->_contents['entries'] as $type => $arrType)
{
if(!$this->_entrytypes[$type]->newbyimportallowed)
Expand Down Expand Up @@ -632,7 +645,6 @@ private function _parseAfter()
unset($persons[$personType][$k]['g_name']);
}
}

$this->_contents['persons'] = $persons;
}

Expand Down Expand Up @@ -878,6 +890,7 @@ private function _parseBlocks(SimpleXMLElement $simplexml)
// }

if(empty($block)) continue;


if($obj instanceof tablefieldsVO && ('entries' === $obj->type || 'persons' === $obj->type))
{
Expand All @@ -887,10 +900,22 @@ private function _parseBlocks(SimpleXMLElement $simplexml)
$this->_contents['entries'][$idtype] = array();

$block = array_shift($block);
if(isset($block->list[0]))

if(isset($block->list[0]))
{
foreach($block->list[0]->item as $k => $v)
$this->_contents['entries'][$idtype][] = (string) $v;
} elseif (isset($block->term[0])) {
foreach($block->term as $term) {
$ark = (string) $term->attributes()['ref'];
$mlnoms = array();
foreach ($term->term as $ssterm => $v) {
$lang=$v->attributes("http://www.w3.org/XML/1998/namespace")['lang']->__toString();
$mlnoms[$lang] = $v->__toString();
}
$data = array ('g_name' => $ark, 'data' => array('ark' => $ark, 'mlnom' => $mlnoms));
$this->_contents['entries'][$idtype][] = $data;
}
}
else
{
Expand Down
20 changes: 20 additions & 0 deletions lodel/scripts/textfunc.php
Expand Up @@ -1878,3 +1878,23 @@ function lreg_split($str, $pattern, $limit = -1, $flags = 0)
{
return preg_split($pattern, $str, $limit, $flags);
}

/**
* * Tri d'un tableau de tableau
* *
* * @param array $arr
* * @return $sorted_arr
* */
function msort($arr, $key, $sort_order = SORT_LOCALE_STRING) {
$values = array_column($arr, $key);
array_multisort($values, $sort_order, $arr);
return $arr;
}








1 change: 1 addition & 0 deletions lodel/scripts/validfunc.php
Expand Up @@ -317,6 +317,7 @@ function_exists('mysqldatetime') || include 'date.php';
$text = $str;
}
$text = unicode_to_numeric_entity($text); // mysql utf8 encoding workaround

return true;
case 'list' :
return true;
Expand Down
37 changes: 35 additions & 2 deletions lodel/src/lodel/admin/tpl/entries.html
Expand Up @@ -90,6 +90,23 @@
</LOOP>
</IF>
<div id="entries">
<LOOP NAME="screennameType" TABLE="tablefields" SELECT="type" WHERE="name='[#SCREEN_NAME]'">
<DO>
<LET VAR="TYPESN" GLOBAL="1">[#TYPE]</LET>
</DO>
</LOOP>
<LET VAR="MULTILANG">1</LET>
<IF COND="[%TYPESN] EQ 'mltext'">
<LOOP NAME="verification_multilingue" SELECT="count(*) as count_ind" TABLE="[#TYPE.CLASS] as data, entries as entry" WHERE="[#SCREEN_NAME] != '' AND [#SCREEN_NAME] IS NOT NULL AND entry.id = data.identry AND entry.idtype=[#TYPE.ID]">
<DO>
<LET VAR="count_index" GLOBAL="1">[#COUNT_IND]</LET>
</DO>
</LOOP>
<IF COND="[%COUNT_INDEX] EQ 0"><LET VAR="MULTILANG">0</LET></IF>
<ELSE/>
<LET VAR="MULTILANG">0</LET>
</IF>

<IF COND="[#TYPE.SORT] EQ 'sortkey'">
<IF COND="[#LISTALL]">
<a href="index.php?do=list&amp;lo=entries&amp;idtype=<IF COND="[#EXTERNAL]">[#SITE_EXT].</IF>[#TYPE.ID]"><span style="color:#ED8400;font-weight:bold;">[@ADMIN.LIST_ENTRIES_BY_LETTER]</span></a>&nbsp;|&nbsp;
Expand All @@ -99,12 +116,28 @@
</IF>
<br /><br />
<div id="alphabet">
<FUNC NAME="ALPHABETSPECIFIC" TABLE="entries" FIELD="[#TYPE.SORT]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]">
<IF COND="[#MULTILANG] EQ 1">
<FUNC NAME="ALPHABETSPECIFICENTRIES" TABLE="entries" FIELD="[#SCREEN_NAME]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]" LISTALL="[#LISTALL]">
<ELSE />
<FUNC NAME="ALPHABETSPECIFIC" TABLE="entries" FIELD="[#TYPE.SORT]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]" LISTALL="[#LISTALL]">
</IF>
</div>
</IF>

<FUNC NAME="LIST_ENTRIES" ID="[#ID]" IDTYPE="[#IDTYPE]" SORT="[#TYPE.SORT]" LETTER="[#LETTER|urldecode|strtoupper]" LISTALL="[#LISTALL]" EXTERNAL="[#EXTERNAL]">
<FUNC NAME="LIST_ENTRIES" ID="[#ID]" IDTYPE="[#IDTYPE]" SORT="[#TYPE.SORT]" LETTER="[#LETTER|urldecode|strtoupper]" LISTALL="[#LISTALL]" EXTERNAL="[#EXTERNAL]" MULTILANG="[#MULTILANG]">
</div>
<!--[<MACRO NAME="OK_TOINDEX_ADMIN">]-->

<MACRO NAME="CLOSE_HTML">












0 comments on commit d12012b

Please sign in to comment.