<commit_before><?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 : Classe de gestion des profils
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class ProfilLoader extends Storm_Model_Loader {
	public function findAllByZoneAndBib($id_zone=0,$id_bib=0) {
		$conditions = array('order' => 'libelle');

		$where = '';
		if($id_zone and $id_zone !="ALL") {
			if($id_zone=="PORTAIL")
				$conditions["ID_SITE"] = 0;
			else {
				$conditions["ID_SITE"] = array("select ID_SITE from bib_c_site where ID_ZONE=$id_zone");
			}
		}


		if($id_bib and $id_bib!="ALL") {
			if($id_bib=="PORTAIL")
				$id_bib=0;
			$conditions["ID_SITE"] = $id_bib;
		}

		return	$this->findAllBy($conditions);
	}


	public function getPortail() {
		return $this->find(1);
	}
}


class Class_Profil extends Storm_Model_Abstract {
  const DIV_BANNIERE = 4;
	protected static $_default_translator = null;

  protected $_loader_class = 'ProfilLoader';
  protected $_table_name = 'bib_admin_profil';
  protected $_table_primary = 'ID_PROFIL';

  protected $_belongs_to = array('bib' => array('model' => 'Class_Bib',
                                                'referenced_in' => 'id_site'),
                                  'parent_profil' => array('model' => 'Class_Profil',
                                                           'referenced_in' => 'parent_id'));

  protected $_has_many  = array('sub_profils' => array('model' => 'Class_Profil',
																											  'role' => 'parent',
																											  'dependents' => 'delete'));

  protected static $_current_profil;
  protected static $DEFAULT_VALUES, $CFG_SITE_KEYS, $FORWARDED_ATTRIBUTES;

	/**
	 * liste des bannieres
	 * @var array
	 */
	protected $_all_header_img;

	/**
	 * @var Class_Profil_I18nTranslator
	 */
	protected $_translator;


	public static function getLoader() {
		return self::getLoaderFor(__CLASS__);
	}


	/**
	 * @return Class_Profil
	 */
	public static function getCurrentProfil() {
		if (!isset(self::$_current_profil)) {
			$id_profil = array_isset('id_profil', $_SESSION) ? $_SESSION['id_profil'] : 1;
			self::$_current_profil = self::getLoader()->find($id_profil);
		}
		return self::$_current_profil;
	}


	/**
	 * @param Class_Profil $profil
	 */
	public static function setCurrentProfil($profil) {
		self::$_current_profil = $profil;
	}


	/**
	 * @return array
	 */
	public static function getCfgSiteKeys() {
		if (!isset(self::$CFG_SITE_KEYS))
			self::$CFG_SITE_KEYS = array( 'accessibilite_on',
																		'barre_nav_on',
																		'header_css',
																		'header_img',
																		'header_img_cycle',
																		'largeur_division2',
																		'largeur_division3',
																		'liens_sortants_off',
																		'marge_division1',
																		'marge_division2',
																		'marge_division3',
																		'menu_haut_on',
																		'largeur_division1',
																		'largeur_site',
																		'nb_divisions',
																		'hauteur_banniere',
																		'couleur_lien_bandeau',
																		'couleur_texte_bandeau',
																		'access_level',
																		'favicon',
																		'logo_gauche_img',
																		'logo_gauche_link',
																		'logo_droite_img',
																		'logo_droite_link');
	  return self::$CFG_SITE_KEYS;

	}


	/**
	 * @return array
	 */
	public static function getDefaultValues() {
		if (!isset(self::$DEFAULT_VALUES))
			self::$DEFAULT_VALUES =
				array('cfg_site' => '',
							'cfg_accueil' => ZendAfi_Filters_Serialize::serialize(array("modules" => array())),
							'cfg_menus' => ZendAfi_Filters_Serialize::serialize(
																	 array(
																				'H' => array(
																										 "libelle" => "Menu horizontal",
																										 "picto" => "vide.gif"),
																				'V' => array(
																										 "libelle" => "Menu vertical",
																										 "picto" => "vide.gif"))),
							'cfg_modules' => '',
							'cfg_notice' => ZendAfi_Filters_Serialize::serialize(
																			 array('exemplaires' => array(
																																		'grouper' => 0,
																																		'annexe' => 0,
																																		'bib' => 1,
																																		'section' => 0,
																																		'emplacement' => 0,
																																		'localisation' => 1,
																																		'plan' => 1,
																																		'resa' => 1,
																																		'dispo' => 1,
																																		'date_retour' => 0),
																																		'en_pret' => 'En prêt')),
							'hauteur_banniere' => 100,
							'mail_site' => '',
							'skin' => 'original',
							'largeur_site' => 1000,
							'nb_divisions' => 3,
							'largeur_division1' => 250,
							'marge_division1' => 10,
							'largeur_division2' => 550,
							'marge_division2' => 10,
							'largeur_division3' => 200,
							'marge_division3' => 10,
							'menu_haut_on' => true,
							'barre_nav_on' => true,
							'ref_description' => '',
							'ref_tags' => '',
							'id_site' => 0,
							'sel_section' => '',
							'sel_type_doc' => '',
							'header_css' => null,
							'header_img' => null,
							'header_img_cycle' => false,
							'liens_sortants_off' => false,
							'titre_site' => '',
							'libelle' => '** nouveau profil **',
							'commentaire' => '',
							'browser' => 'opac',
							'accessibilite_on' => true,
							'couleur_lien_bandeau' => '',
							'couleur_texte_bandeau' => '',
							'access_level' => -1,
							'parent_id' => 0, 
							'favicon' => '',
							'logo_gauche_img' => '',
							'logo_gauche_link' => '',
							'logo_droite_img' => '',
							'logo_droite_link' => '');
	  return self::$DEFAULT_VALUES;
  }


	/**
	 * @param translator Class_Profil_I18nTranslator
	 */
	public static function setDefaultTranslator($translator) {
		self::$_default_translator = $translator;
	}


	/**
	 * @return Class_Profil_I18nTranslator
	 */
	public static function getDefaultTranslator() {
		return self::$_default_translator;
	}


	/**
	 * @return array
	 */
	public static function getAttributesForwardedToParent() {
		if (isset(self::$FORWARDED_ATTRIBUTES))
			return self::$FORWARDED_ATTRIBUTES;

		$all_attributes = array_keys(self::getDefaultValues());
		$not_forwarded_attributes = array('id',
																			'parent_id',
																			'parent_profil',
																			'libelle',
																			'cfg_accueil',
																			'sub_profils');
		self::$FORWARDED_ATTRIBUTES = array_diff($all_attributes,
																						 $not_forwarded_attributes);
		return self::$FORWARDED_ATTRIBUTES;
	}

	/**
	 * @param string $field
	 * @return bool
	 */
	public function shouldForwardAttributeToParent($field) {
		return
			in_array($field, self::getAttributesForwardedToParent())
			and $this->hasParentProfil();
	}

	/**
	 * @param Class_I18nTranslator $translator
	 * @return Class_Profil
	 */
	public function setTranslator($translator) {
		$this->_translator = $translator;
		return $this;
	}


	/**
	 * @return String
	 */
	public function getLocale() {
		return Zend_Registry::getInstance()->get('locale')->getLanguage();
	}


	/**
	 * @return Class_Profil_I18nTranslator
	 */
	public function getTranslator() {
		if ((null === $this->_translator) and (null === $this->_translator=self::getDefaultTranslator())){
			$locale = $this->getLocale();
			$this->_translator = Class_Profil_I18nTranslator::newForLocale($locale);
		}

		return $this->_translator;
	}


	/**
	 * @return string
	 */
	public function getPathTheme()	{
		$path='/public/'.$this->getBrowser().'/skins/'.$this->getSkin().'/';
		if(!file_exists(".".$path))
			$path='/public/'.$this->getBrowser().'/original/';
		return $path;
	}


	/**
	 * @return string
	 */
	public function getPathTemplates() {
		return ".".$this->getPathTheme()."templates/boites/";
	}


	/**
	 * @param int $id_module
	 * @param string $type_module
	 * @return array<commit_msg>Corrections suite a reorganisation CE<commit_after><?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 : Classe de gestion des profils
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class ProfilLoader extends Storm_Model_Loader {
	public function findAllByZoneAndBib($id_zone=0,$id_bib=0) {
		$conditions = array('order' => 'libelle');

		$where = '';
		if($id_zone and $id_zone !="ALL") {
			if($id_zone=="PORTAIL")
				$conditions["ID_SITE"] = 0;
			else {
				$conditions["ID_SITE"] = array("select ID_SITE from bib_c_site where ID_ZONE=$id_zone");
			}
		}


		if($id_bib and $id_bib!="ALL") {
			if($id_bib=="PORTAIL")
				$id_bib=0;
			$conditions["ID_SITE"] = $id_bib;
		}

		return	$this->findAllBy($conditions);
	}


	public function getPortail() {
		return $this->find(1);
	}
}


class Class_Profil extends Storm_Model_Abstract {
  const DIV_BANNIERE = 4;
	protected static $_default_translator = null;

  protected $_loader_class = 'ProfilLoader';
  protected $_table_name = 'bib_admin_profil';
  protected $_table_primary = 'ID_PROFIL';

  protected $_belongs_to = array('bib' => array('model' => 'Class_Bib',
                                                'referenced_in' => 'id_site'),
                                  'parent_profil' => array('model' => 'Class_Profil',
                                                           'referenced_in' => 'parent_id'));

  protected $_has_many  = array('sub_profils' => array('model' => 'Class_Profil',
																											  'role' => 'parent',
																											  'dependents' => 'delete'));

  protected static $_current_profil;
  protected static $DEFAULT_VALUES, $CFG_SITE_KEYS, $FORWARDED_ATTRIBUTES;

	/**
	 * liste des bannieres
	 * @var array
	 */
	protected $_all_header_img;

	/**
	 * @var Class_Profil_I18nTranslator
	 */
	protected $_translator;


	public static function getLoader() {
		return self::getLoaderFor(__CLASS__);
	}


	/**
	 * @return Class_Profil
	 */
	public static function getCurrentProfil() {
		if (!isset(self::$_current_profil)) {
			$id_profil = array_isset('id_profil', $_SESSION) ? $_SESSION['id_profil'] : 1;
			self::$_current_profil = self::getLoader()->find($id_profil);
		}
		return self::$_current_profil;
	}


	/**
	 * @param Class_Profil $profil
	 */
	public static function setCurrentProfil($profil) {
		self::$_current_profil = $profil;
	}


	/**
	 * @return array
	 */
	public static function getCfgSiteKeys() {
		if (!isset(self::$CFG_SITE_KEYS))
			self::$CFG_SITE_KEYS = array( 'accessibilite_on',
																		'barre_nav_on',
																		'header_css',
																		'header_img',
																		'header_img_cycle',
																		'largeur_division2',
																		'largeur_division3',
																		'liens_sortants_off',
																		'marge_division1',
																		'marge_division2',
																		'marge_division3',
																		'menu_haut_on',
																		'largeur_division1',
																		'largeur_site',
																		'nb_divisions',
																		'hauteur_banniere',
																		'couleur_lien_bandeau',
																		'couleur_texte_bandeau',
																		'access_level',
																		'favicon',
																		'logo_gauche_img',
																		'logo_gauche_link',
																		'logo_droite_img',
																		'logo_droite_link');
	  return self::$CFG_SITE_KEYS;

	}


	/**
	 * @return array
	 */
	public static function getDefaultValues() {
		if (!isset(self::$DEFAULT_VALUES))
			self::$DEFAULT_VALUES =
				array('cfg_site' => '',
							'cfg_accueil' => ZendAfi_Filters_Serialize::serialize(array("modules" => array())),
							'cfg_menus' => ZendAfi_Filters_Serialize::serialize(
																	 array(
																				'H' => array(
																										 "libelle" => "Menu horizontal",
																										 "picto" => "vide.gif"),
																				'V' => array(
																										 "libelle" => "Menu vertical",
																										 "picto" => "vide.gif"))),
							'cfg_modules' => '',
							'cfg_notice' => ZendAfi_Filters_Serialize::serialize(
																			 array('exemplaires' => array(
																																		'grouper' => 0,
																																		'annexe' => 0,
																																		'bib' => 1,
																																		'section' => 0,
																																		'emplacement' => 0,
																																		'localisation' => 1,
																																		'plan' => 1,
																																		'resa' => 1,
																																		'dispo' => 1,
																																		'date_retour' => 0),
																																		'en_pret' => 'En prêt')),
							'hauteur_banniere' => 100,
							'mail_site' => '',
							'skin' => 'original',
							'largeur_site' => 1000,
							'nb_divisions' => 3,
							'largeur_division1' => 250,
							'marge_division1' => 10,
							'largeur_division2' => 550,
							'marge_division2' => 10,
							'largeur_division3' => 200,
							'marge_division3' => 10,
							'menu_haut_on' => true,
							'barre_nav_on' => true,
							'ref_description' => '',
							'ref_tags' => '',
							'id_site' => 0,
							'sel_section' => '',
							'sel_type_doc' => '',
							'header_css' => null,
							'header_img' => null,
							'header_img_cycle' => false,
							'liens_sortants_off' => false,
							'titre_site' => '',
							'libelle' => '** nouveau profil **',
							'commentaire' => '',
							'browser' => 'opac',
							'accessibilite_on' => true,
							'couleur_lien_bandeau' => '',
							'couleur_texte_bandeau' => '',
							'access_level' => -1,
							'parent_id' => 0, 
							'favicon' => '',
							'logo_gauche_img' => '',
							'logo_gauche_link' => '',
							'logo_droite_img' => '',
							'logo_droite_link' => '');
	  return self::$DEFAULT_VALUES;
  }


	/**
	 * @param translator Class_Profil_I18nTranslator
	 */
	public static function setDefaultTranslator($translator) {
		self::$_default_translator = $translator;
	}


	/**
	 * @return Class_Profil_I18nTranslator
	 */
	public static function getDefaultTranslator() {
		return self::$_default_translator;
	}


	/**
	 * @return array
	 */
	public static function getAttributesForwardedToParent() {
		if (isset(self::$FORWARDED_ATTRIBUTES))
			return self::$FORWARDED_ATTRIBUTES;

		$all_attributes = array_keys(self::getDefaultValues());
		$not_forwarded_attributes = array('id',
																			'parent_id',
																			'parent_profil',
																			'libelle',
																			'cfg_accueil',
																			'sub_profils');
		self::$FORWARDED_ATTRIBUTES = array_diff($all_attributes,
																						 $not_forwarded_attributes);
		return self::$FORWARDED_ATTRIBUTES;
	}

	/**
	 * @param string $field
	 * @return bool
	 */
	public function shouldForwardAttributeToParent($field) {
		return
			in_array($field, self::getAttributesForwardedToParent())
			and $this->hasParentProfil();
	}

	/**
	 * @param Class_I18nTranslator $translator
	 * @return Class_Profil
	 */
	public function setTranslator($translator) {
		$this->_translator = $translator;
		return $this;
	}


	/**
	 * @return String
	 */
	public function getLocale() {
		return Zend_Registry::getInstance()->get('locale')->getLanguage();
	}


	/**
	 * @return Class_Profil_I18nTranslator
	 */
	public function getTranslator() {
		if ((null === $this->_translator) and (null === $this->_translator=self::getDefaultTranslator())){
			$locale = $this->getLocale();
			$this->_translator = Class_Profil_I18nTranslator::newForLocale($locale);
		}

		return $this->_translator;
	}


	/**
	 * @return string
	 */
	public function getPathTheme()	{
		$path='/public/'.$this->getBrowser().'/skins/'.$this->getSkin().'/';
		if(!file_exists(".".$path))
			$path='/public/'.$this->getBrowser().'/skins/original/';
		return $path;
	}


	/**
	 * @return string
	 */
	public function getPathTemplates() {
		return ".".$this->getPathTheme()."templates/boites/";
	}


	/**
	 * @param int $id_module
	 * @param string $type_module
	 * @return array
{'fraction_non_alphanumeric': 0.16586982505704662, 'fraction_numerical': 0.009670759534934261, 'mean_word_length': 1.981373501781665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 177, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '738453', 'n_tokens_mistral': 7440, 'n_tokens_neox': 5557, 'n_words': 1091}