Skip to content
Snippets Groups Projects
AdminVar.php 9.00 KiB
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
 * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
 * AFI-OPAC 2.0 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 * along with AFI-OPAC 2.0; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
 */
//////////////////////////////////////////////////////////////////////////////////////////
// OPAC3 - Variables globales admin
//////////////////////////////////////////////////////////////////////////////////////////

class Class_AdminVar extends Storm_Model_Abstract {
	protected $_table_name = 'bib_admin_var';
	protected $_table_primary = 'CLEF';

	/** @var array */
	protected static $_knownVars = array(
		'AVIS_MAX_SAISIE',
		'AVIS_MIN_SAISIE',
		'BLOG_MAX_NB_CARAC',
		'NB_AFFICH_AVIS_PAR_AUTEUR',
		'CLEF_GOOGLE_MAP',
		'MODO_AVIS',
		'MODO_AVIS_BIBLIO',
		'AVIS_BIB_SEULEMENT',
		'MODO_BLOG',
		'REGISTER_OK',
		'RESA_CONDITION',
		'SITE_OK',
		'ID_BIBLIOSURF',
		'GOOGLE_ANALYTICS',
		'ID_READ_SPEAKER',
		'BLUGA_API_KEY',
		'AIDE_FICHE_ABONNE',
		'INTERDIRE_ENREG_UTIL',
		'LANGUES',
		'CACHE_ACTIF',
		'WORKFLOW',
		'WORKFLOW_TEXT_MAIL_ARTICLE_PENDING',
		'WORKFLOW_TEXT_MAIL_ARTICLE_REFUSED',
		'BIBNUM',
		'FORMATIONS',
		'VODECLIC_KEY',
		'VODECLIC_ID',
		'VODECLIC_BIB_ID',
		'CVS_BMKEY',
		'CVS_BMID',
		'CVS_SOURCENAME',
		'CVS_SOURCEID',
		'CVS_SOURCEKEY',
		'CVS_SOURCEPASSWORD',
		'CVS_LOGINTEST',
		'NUMILOG_URL',
		'NUMILOG_OAI_URL',
		'NUMILOG_OAI_IDBIB',
		'OAI_SERVER',
		'PACK_MOBILE',
		'ARTE_VOD_LOGIN',
		'ARTE_VOD_KEY',
		'ARTE_VOD_SSO_KEY',
		'BABELTHEQUE_JS',
		'MULTIMEDIA_KEY',
		'WEBKIOSK_KEY',
		'WEBKIOSK_RESERVATION_URL',
		'CSS_EDITOR',
		'CMS_FORMULAIRES',
		'MENU_BOITE',
		'INTERDIRE_MODIF_FICHE_ABONNE',
		'ROOT_URL_ECOUTE',
		'URL_TYPO3',
		'CHAMPS_FICHE_UTILISATEUR',
		'FACETTE_PCDM4_LIBELLE',
		'FACETTE_DEWEY_LIBELLE',
		'FACETTE_TYPE_DOC_LIBELLE',
		'FACETTE_LANGUE_LIBELLE',
		'FACETTE_GENRE_LIBELLE',
		'FACETTE_SITE_LIBELLE',
		'FACETTE_SECTION_LIBELLE',
		'FACETTE_BIBLIOTHEQUE_LIBELLE',
		'FACETTE_AUTEUR_LIBELLE',
		'FACETTE_INTERET_LIBELLE',
		'FACETTE_MATIERE_LIBELLE',
		'FACETTE_TAG_LIBELLE',
		'AFFICHER_DISPONIBILITE_SUR_RECHERCHE',
		'NOM_DOMAINE',
		'TOUTAPPRENDRE_BIB_ID',
		'TOUTAPPRENDRE_KEY',
		'MUSICME_URL',
		'MUSICME_BIB_ID',
		'DATE_LAST_FULL_INTEGRATION_USERS',
		'BOITE_PANIER_AUTO'
	);


	/**
	 * @param string $name
	 * @return mixed
	 */
	public static function get($name) {

		$var = static::getLoader()->find($name);
		if ($var == null)
			return null;
		return $var->getValeur();
	}


	/**
	 * @param string $name
	 * @param mixed $value
	 */
	public static function set($name, $value) {
		if (null === ($instance = self::getLoader()->find($name))) {
			$instance = self::getLoader()->newInstance()->setClef($name);
		}

		$instance
			->setValeur($value)
			->save();

		// très particulier à cette table qui n'a pas de primary autoincrément
		// si on vient de la créer, last insertid est vide
		// donc ici on reprend le champ clef
		$instance->setId($instance->getClef());

		return $instance;
	}

	public static function getDefaultLanguage() {
		return 'fr';
	}

	public static function getLangues() {
		if (!$langues_value = self::get('LANGUES'))
			return array();

		$langues = array(self::getDefaultLanguage());

		foreach(explode(';', strtolower($langues_value)) as $langue)
			$langues []= trim($langue);
		return array_unique(array_filter($langues));
	}


	public static function getLanguesWithoutDefault() {
		return array_diff(self::getLangues(), array(self::getDefaultLanguage()));
	}

	/**
	 * @return bool
	 */
	public static function isTranslationEnabled() {
		return count(self::getLangues()) > 1;
	}


	/**
	 * @return bool
	 */
	public static function isModuleEnabled($name) {
		if (!$value = self::get($name)) {
			return false;
		}

		return (1 == (int)$value);
	}


	/**
	 * @return bool
	 */
	public static function isWorkflowEnabled() {
		return self::isModuleEnabled('WORKFLOW');
	}


	/**
	 * @return bool
	 */
	public static function isBibNumEnabled() {
		return self::isModuleEnabled('BIBNUM');
	}


	/**
	 * @return bool
	 */
	public static function isFormationEnabled() {
		return self::isModuleEnabled('FORMATIONS');
	}


	/**
	 * @return bool
	 */
	public static function isVodeclicEnabled() {
		return (('' != self::get('VODECLIC_KEY')) && ('' != self::get('VODECLIC_ID')) && ('' != self::get('VODECLIC_BIB_ID')));
	}


	public static function isToutApprendreEnabled() {
		return (('' != self::get('TOUTAPPRENDRE_BIB_ID')) && ('' != self::get('TOUTAPPRENDRE_KEY')));
	}



	/**
	 * @return bool
	 */
	public static function isCVSEnabled() {
		return (('' != self::get('CVS_BMKEY')) && ('' != self::get('CVS_BMID')) && 
						('' != self::get('CVS_SOURCEPASSWORD')) && ('' != self::get('CVS_SOURCEKEY')) && 
						('' != self::get('CVS_SOURCEID')) && ('' != self::get('CVS_SOURCENAME'))
			);
	}


	/**
	 * @return bool
	 */
	public static function isNumilogEnabled() {
		return ('' != self::get('NUMILOG_URL') );
	}


	/**
	 * @return bool
	 */
	public static function isTypo3Enabled() {
		return ('' != self::get('URL_TYPO3'));
	}


	/**
	 * @return bool
	 */
	public static function isOAIServerEnabled() {
		return self::isModuleEnabled('OAI_SERVER');
	}


	/**
	 * @return bool
	 */
	public static function isPackMobileEnabled() {
		return self::isModuleEnabled('PACK_MOBILE');
	}


	/**
	 * @return bool
	 */
	public static function isPlanningOuverturesEnabled() {
		return self::isMultimediaEnabled();
	}


	/**
	 * @return bool
	 */
	public static function isArteVodEnabled() {
		return (('' != self::get('ARTE_VOD_LOGIN')) && ('' != self::get('ARTE_VOD_KEY')) && ('' != self::get('ARTE_VOD_SSO_KEY')));
	}	


	/**
	 * @return bool
	 */
	public static function isMusicMeEnabled() {
		return ('' != self::get('MUSICME_URL'));
	}	


	/**
	 * @return bool
	 */
	public static function isMultimediaEnabled() {
		return ('' != self::get('MULTIMEDIA_KEY'));
	}

	/**
	 * @return bool
	 */
	public static function isWebkioskEnabled() {
		return ('' != self::get('WEBKIOSK_KEY'));
	}

	 /**
	 * @return bool
	 */
	public static function isBeforeDateLastFullIntegrationUsers($date) {
		if ('' == self::get('DATE_LAST_FULL_INTEGRATION_USERS'))	return true;
		return $date >= self::get('DATE_LAST_FULL_INTEGRATION_USERS');
	}


	public static function isBoitePanierAutoEnabled() {
		return self::isModuleEnabled('BOITE_PANIER_AUTO');
	}


	/**
	 * @return array
	 */
	public static function getKnownVars() {
		return self::$_knownVars;
	}


	/** @return bool */
	public static function isCacheEnabled() {
		return self::isModuleEnabled('CACHE_ACTIF');
	}


	/** @return bool */
	public static function isCmsFormulairesEnabled() {
		return self::isModuleEnabled('CMS_FORMULAIRES');
	}


	/** @return bool */ 
	public static function getGoogleAnalyticsId() {
		$script = static::get('GOOGLE_ANALYTICS');
		preg_match_all("/setAccount[\', \n\t]+\'([^\']+)\'/i", $script, $matches);
		return isset($matches[1][0]) ? $matches[1][0] : '';
	}


	/** @return string */
	public static function getNomDomaine() {
		$domaine = trim(static::get('NOM_DOMAINE'));
		return $domaine ? $domaine : $_SERVER['SERVER_NAME'];
	}


	/**
	 * @return bool
	 */
	public static function isEnregUtilAllowed() {
		return !self::isModuleEnabled('INTERDIRE_ENREG_UTIL');
	}


	/**
	 * @return bool
	 */
	public static function isMenuBoiteEnabled() {
		return self::isModuleEnabled('MENU_BOITE');
	}

	
	public static function isAfficherDispoSurRechercheEnabled() {
		return self::isModuleEnabled('AFFICHER_DISPONIBILITE_SUR_RECHERCHE');
	}


	public function getValeur() {
		return stripslashes($this->_get('valeur'));
	}


	public static function getBabelthequeId() {
		$mathes = [];
		if (preg_match('/bw_([^\.]+)\.js/', (string)self::get('BABELTHEQUE_JS'), $matches))
			return (int)$matches[1];
	}



	public static function getChampsFicheUtilisateur() {
		return array_filter(explode(';', trim(self::get('CHAMPS_FICHE_UTILISATEUR'))));
	}



	public static function getWorkflowTextMailArticlePending() {
		if(!static::get('WORKFLOW_TEXT_MAIL_ARTICLE_PENDING'))
			static::set('WORKFLOW_TEXT_MAIL_ARTICLE_PENDING',
									'Un nouvel article est à valider. TITRE_ARTICLE URL_ARTICLE' );

		return static::get('WORKFLOW_TEXT_MAIL_ARTICLE_PENDING');
	}


	public static function getWorkflowTextMailArticleRefused() {
		if(!static::get('WORKFLOW_TEXT_MAIL_ARTICLE_REFUSED'))
			static::set('WORKFLOW_TEXT_MAIL_ARTICLE_REFUSED',
									'L\'article a été refusé.');

		return static::get('WORKFLOW_TEXT_MAIL_ARTICLE_REFUSED');
	}
}

?>