Labelize collections

This commit is contained in:
Romain Neutron
2013-05-30 20:00:14 +02:00
parent 55a6469aa4
commit c084f20f85
37 changed files with 301 additions and 61 deletions

View File

@@ -666,7 +666,7 @@ class API_V1_adapter extends API_V1_Abstract
$collection = \collection::get_from_base_id($this->app, $request->get('base_id'));
if (!$app['authentication']->getUser()->ACL()->has_right_on_base($request->get('base_id'), 'canaddrecord')) {
throw new API_V1_exception_forbidden(sprintf('You do not have access to collection %s', $collection->get_name()));
throw new API_V1_exception_forbidden(sprintf('You do not have access to collection %s', $collection->get_label($this->app['locale.I18n'])));
}
$media = $app['mediavorus']->guess($file->getPathname());
@@ -2019,7 +2019,7 @@ class API_V1_adapter extends API_V1_Abstract
$ret = array(
'base_id' => $collection->get_base_id(),
'collection_id' => $collection->get_coll_id(),
'name' => $collection->get_name(),
'name' => $collection->get_label($this->app['locale.I18n']),
'record_amount' => $collection->get_record_amount(),
);

View File

@@ -11,6 +11,8 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
@@ -25,6 +27,7 @@ class collection implements cache_cacheableInterface
protected $name;
protected $prefs;
protected $pub_wm;
protected $labels = array();
private static $_logos = array();
private static $_stamps = array();
private static $_watermarks = array();
@@ -61,6 +64,7 @@ class collection implements cache_cacheableInterface
$this->pub_wm = $datas['pub_wm'];
$this->name = $datas['name'];
$this->prefs = $datas['prefs'];
$this->labels = $datas['labels'];
return $this;
} catch (Exception $e) {
@@ -68,8 +72,10 @@ class collection implements cache_cacheableInterface
}
$connbas = $this->databox->get_connection();
$sql = 'SELECT asciiname, prefs, pub_wm, coll_id
FROM coll WHERE coll_id = :coll_id';
$sql = 'SELECT
asciiname, prefs, pub_wm, coll_id,
label_en, label_fr, label_de, label_nl
FROM coll WHERE coll_id = :coll_id';
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':coll_id' => $this->coll_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -81,6 +87,12 @@ class collection implements cache_cacheableInterface
$this->pub_wm = $row['pub_wm'];
$this->name = $row['asciiname'];
$this->prefs = $row['prefs'];
$this->labels = array(
'fr' => $row['label_fr'],
'en' => $row['label_en'],
'de' => $row['label_de'],
'nl' => $row['label_nl'],
);
$conn = connection::getPDOConnection($this->app);
@@ -108,6 +120,7 @@ class collection implements cache_cacheableInterface
, 'pub_wm' => $this->pub_wm
, 'name' => $this->name
, 'prefs' => $this->prefs
, 'labels' => $this->labels
);
$this->set_data_to_cache($datas);
@@ -225,6 +238,40 @@ class collection implements cache_cacheableInterface
return $this;
}
public function set_label($code, $label)
{
if (!array_key_exists($code, $this->labels)) {
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
}
$sql = "UPDATE coll SET label_$code = :label
WHERE coll_id = :coll_id";
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute(array(':label' => $label, ':coll_id' => $this->get_coll_id()));
$stmt->closeCursor();
$this->labels[$code] = $label;
$this->delete_data_from_cache();
phrasea::reset_baseDatas($this->databox->get_appbox());
return $this;
}
public function get_label($code, $substitute = true)
{
if (!array_key_exists($code, $this->labels)) {
throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
}
if ($substitute) {
return isset($this->labels[$code]) ? $this->labels[$code] : $this->name;
} else {
return $this->labels[$code];
}
}
public function get_record_amount()
{
$sql = "SELECT COUNT(record_id) AS n FROM record WHERE coll_id = :coll_id";
@@ -602,12 +649,12 @@ class collection implements cache_cacheableInterface
if ( ! isset(self::$_logos[$base_id_key])) {
if (is_file($app['phraseanet.registry']->get('GV_RootPath') . 'config/minilogos/' . $base_id)) {
$name = phrasea::bas_names($base_id, $app);
$name = phrasea::bas_labels($base_id, $app);
self::$_logos[$base_id_key] = '<img title="' . $name
. '" src="' . $app['phraseanet.registry']->get('GV_STATIC_URL')
. '/custom/minilogos/' . $base_id . '" />';
} elseif ($printname) {
self::$_logos[$base_id_key] = phrasea::bas_names($base_id, $app);
self::$_logos[$base_id_key] = phrasea::bas_labels($base_id, $app);
}
}

View File

@@ -86,7 +86,7 @@ function giveMeBases(Application $app, $usr = null)
$inscriptions[$sbas_id]['CollsNonactif'] = null;
foreach ($databox->get_collections() as $key => $coll) {
$collname[$key] = $coll->get_name();
$collname[$key] = $coll->get_label($app['locale.I18n']);
$basname[$key] = $coll->get_coll_id();
}
$sbpcgu = '';
@@ -138,7 +138,7 @@ function giveMeBases(Application $app, $usr = null)
$cguSpec = true;
} else {
if ( ! isset($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()]))
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_name();
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_label($app['locale.I18n']);
}
}
}
@@ -158,9 +158,9 @@ function giveMeBases(Application $app, $usr = null)
elseif ($usrerRegis[$databox->get_dbname()][$collection->get_coll_id()] === true)
$inscriptions[$sbas_id]['CollsRegistered'][$collection->get_coll_id()] = $lacgu;
} elseif (! $cguSpec && $collInscript) {//ne va pas.. si l'inscriptio na la coll est explicitement non autorise, je refuse'
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_name();
$inscriptions[$sbas_id]['Colls'][$collection->get_coll_id()] = $collection->get_label($app['locale.I18n']);
} elseif ($cguSpec) {
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['name'] = $collection->get_name();
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['name'] = $collection->get_label($app['locale.I18n']);
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['CGU'] = $cguColl;
$inscriptions[$sbas_id]['CollsCGU'][$collection->get_coll_id()]['CGUrelease'] = $cguCollRelease;
}
@@ -190,7 +190,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsRegistered']) {
foreach ($baseInsc['CollsRegistered'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces authorise sur la collection ') . phrasea::bas_names($base_id, $app);
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces authorise sur la collection ') . phrasea::bas_labels($base_id, $app);
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';
@@ -200,7 +200,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsRefuse']) {
foreach ($baseInsc['CollsRefuse'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces refuse sur la collection ') . phrasea::bas_names($base_id, $app) . '</span>';
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces refuse sur la collection ') . phrasea::bas_labels($base_id, $app) . '</span>';
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';
@@ -210,7 +210,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsWait']) {
foreach ($baseInsc['CollsWait'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:orange;">' . _('login::register: en attente d\'acces sur') . ' ' . phrasea::bas_names($base_id, $app) . '</span>';
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:orange;">' . _('login::register: en attente d\'acces sur') . ' ' . phrasea::bas_labels($base_id, $app) . '</span>';
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';
@@ -220,7 +220,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsIntime']) {
foreach ($baseInsc['CollsIntime'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces temporaire sur') . phrasea::bas_names($base_id, $app) . '</span>';
$out .= '<tr><td colspan="3" style="text-align:center;">' . _('login::register: acces temporaire sur') . phrasea::bas_labels($base_id, $app) . '</span>';
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';
@@ -230,7 +230,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsOuttime']) {
foreach ($baseInsc['CollsOuttime'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces temporaire termine sur ') . phrasea::bas_names($base_id, $app) . '</span>';
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces temporaire termine sur ') . phrasea::bas_labels($base_id, $app) . '</span>';
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';
@@ -240,7 +240,7 @@ function giveMeBaseUsr(Application $app, $usr, $lng)
if ($baseInsc['CollsNonactif']) {
foreach ($baseInsc['CollsNonactif'] as $collId => $isTrue) {
$base_id = phrasea::baseFromColl($sbasId, $collId, $app);
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces supendu sur') . phrasea::bas_names($base_id, $app) . '</span>';
$out .= '<tr><td colspan="3" style="text-align:center;"><span style="color:red;">' . _('login::register: acces supendu sur') . phrasea::bas_labels($base_id, $app) . '</span>';
if (trim($isTrue) != '')
$out .= ' <a class="inscriptlink" href="/include/cguUtils.php?action=PRINT&bas=' . $sbasId . '&col=' . $collId . '">' . _('login::register::CGU: lire les CGU') . '</a>';
$out .= '</td></tr>';

View File

@@ -254,7 +254,7 @@ class module_report_dashboard implements module_report_dashboard_componentInterf
'base_id' => $base_id,
'sbas_id' => $sbas_id,
'coll_id' => $collection->get_base_id(),
'name' => $collection->get_name()
'name' => $collection->get_label($this->app['locale.I18n'])
);
}

View File

@@ -79,7 +79,7 @@ class module_report_download extends module_report
foreach ($rs as $row) {
$value = $row['val'];
if ($field == 'coll_id') {
$caption = phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
$caption = phrasea::bas_labels(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
} elseif ($field == 'ddate')
$caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));
elseif ($field == 'size')
@@ -167,7 +167,7 @@ class module_report_download extends module_report
private function formatCollId($value)
{
return phrasea::bas_names(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
return phrasea::bas_labels(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
}
public static function getNbDl(Application $app, $dmin, $dmax, $sbas_id, $list_coll_id)

View File

@@ -17,13 +17,13 @@ class phrasea
private static $_sbas_names = false;
private static $_coll2bas = false;
private static $_bas2coll = false;
private static $_bas_names = false;
private static $_bas_labels = false;
private static $_sbas_params = false;
const CACHE_BAS_2_SBAS = 'bas_2_sbas';
const CACHE_COLL_2_BAS = 'coll_2_bas';
const CACHE_BAS_2_COLL = 'bas_2_coll';
const CACHE_BAS_NAMES = 'bas_names';
const CACHE_BAS_LABELS = 'bas_labels';
const CACHE_SBAS_NAMES = 'sbas_names';
const CACHE_SBAS_FROM_BAS = 'sbas_from_bas';
const CACHE_SBAS_PARAMS = 'sbas_params';
@@ -181,12 +181,12 @@ class phrasea
public static function reset_baseDatas(appbox $appbox)
{
self::$_coll2bas = self::$_bas2coll = self::$_bas_names = self::$_bas2sbas = null;
self::$_coll2bas = self::$_bas2coll = self::$_bas_labels = self::$_bas2sbas = null;
$appbox->delete_data_from_cache(
array(
self::CACHE_BAS_2_COLL
, self::CACHE_BAS_2_COLL
, self::CACHE_BAS_NAMES
, self::CACHE_BAS_LABELS
, self::CACHE_SBAS_FROM_BAS
)
);
@@ -249,23 +249,32 @@ class phrasea
return isset(self::$_sbas_names[$sbas_id]) ? self::$_sbas_names[$sbas_id] : 'Unknown base';
}
public static function bas_names($base_id, Application $app)
public static function bas_labels($base_id, Application $app)
{
if (!self::$_bas_names) {
if (!self::$_bas_labels) {
try {
self::$_bas_names = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_BAS_NAMES);
self::$_bas_labels = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_BAS_LABELS);
} catch (Exception $e) {
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
self::$_bas_names[$collection->get_base_id()] = $collection->get_name();
self::$_bas_labels[$collection->get_base_id()] = array(
'fr' => $collection->get_label('fr'),
'en' => $collection->get_label('en'),
'de' => $collection->get_label('de'),
'nl' => $collection->get_label('nl'),
);
}
}
$app['phraseanet.appbox']->set_data_to_cache(self::$_bas_names, self::CACHE_BAS_NAMES);
$app['phraseanet.appbox']->set_data_to_cache(self::$_bas_labels, self::CACHE_BAS_LABELS);
}
}
return isset(self::$_bas_names[$base_id]) ? self::$_bas_names[$base_id] : 'Unknown collection';
if (isset(self::$_bas_labels[$base_id]) && isset(self::$_bas_labels[$base_id][$app['locale.I18n']])) {
return self::$_bas_labels[$base_id][$app['locale.I18n']];
}
return 'Unknown collection';
}
public static function scheduler_key(Application $app, $renew = false)

View File

@@ -354,7 +354,7 @@ class recordutils_image extends recordutils
$builder->getProcess()->run();
} elseif ($app['phraseanet.registry']->get('convert_binary')) {
$collname = phrasea::bas_names($base_id, $app);
$collname = phrasea::bas_labels($base_id, $app);
$tailleimg = @getimagesize($pathIn);
$max = ($tailleimg[0] > $tailleimg[1] ? $tailleimg[0] : $tailleimg[1]);

View File

@@ -219,7 +219,7 @@ class task_period_archive extends task_abstract
<?php
foreach ($this->dependencyContainer['phraseanet.appbox']->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
print("<option value=\"" . $collection->get_base_id() . "\">" . $databox->get_viewname() . " / " . $collection->get_name() . "</option>");
print("<option value=\"" . $collection->get_base_id() . "\">" . $databox->get_viewname() . " / " . $collection->get_label($this->dependencyContainer['locale.I18n']) . "</option>");
}
}
?>

View File

@@ -616,12 +616,12 @@ class task_period_ftp extends task_appboxAbstract
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer)
, phrasea::bas_names($row['base_id'], $this->dependencyContainer), $row['subdef']) . ' : ' . _('Transfert OK') . '</li>';
, phrasea::bas_labels($row['base_id'], $this->dependencyContainer), $row['subdef']) . ' : ' . _('Transfert OK') . '</li>';
} else {
$transferts[] =
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer), phrasea::bas_names($row['base_id'], $this->dependencyContainer)
, phrasea::sbas_names(phrasea::sbasFromBas($this->dependencyContainer, $row["base_id"]), $this->dependencyContainer), phrasea::bas_labels($row['base_id'], $this->dependencyContainer)
, $row['subdef']) . ' : ' . _('Transfert Annule') . '</li>';
$transfert_status = _('task::ftp:Certains documents n\'ont pas pu etre tranferes');
}