<commit_before><?php
/**
* TOOL_DIFFUSION
* Export current section data to mysql database with defined 'difission' options
*
*/
class tool_diffusion {


	public $section_tipo;
	public $section_id;
	public $modo;
	public $options;
	public static $debug_response;



	/**
	* __CONSTRUCT
	*/
	public function __construct( $section_tipo=null, $modo='button' ) {

		if (empty($section_tipo)) {
			throw new Exception("Error Processing Request. Var section_tipo is empty", 1);
		}
		$this->section_tipo = $section_tipo;
		$this->modo 		= $modo;
	}//end __construct



	/** 
	* GET_HTML
	* @return string
	*/
	public function get_html() {
		ob_start();
		include ( DEDALO_LIB_BASE_PATH .'/tools/'.get_called_class().'/'.get_called_class().'.php' );
		return  ob_get_clean();
	}//end get_html



	/**
	* GET_AR_THESAURUS_TABLES
	* @return array Formated array as prefix => name
	*/
	public function get_ar_thesaurus_tables() {
	
		$ar_tables = (array)$this->options->ar_tables;
			#dump($ar_tables, ' ar_tables ++ '.to_string());
		
		$ar_thesaurus_tables = array();
		$i=0;foreach ($ar_tables['prefijo'] as $key => $prefix) {

			if (isset($ar_tables['tipo'][$i-1]) && $ar_tables['tipo'][$i] != $ar_tables['tipo'][$i-1]) { // separator
				$ar_thesaurus_tables[$prefix.'_'.$ar_tables['tipo'][$i]] = 'separator';				
			}
			
			# Do not include langs never
			if ($prefix!='lg') {
				$ar_thesaurus_tables[$prefix] = $ar_tables['nombre'][$i];
			}
			
		$i++;}
		#dump($ar_thesaurus_tables, ' ar_thesaurus_tables ++ '.to_string());

		return $ar_thesaurus_tables;
	}//end get_ar_thesaurus_tables



	/**
	* EXPORT_RECORD
	* @param string $section_tipo
	* @param int $section_id
	* @param string $diffusion_element_tipo
	* @param bool $resolve_references
	*	default: true
	* @return object $response
	*/
	public static function export_record($section_tipo, $section_id, $diffusion_element_tipo, $resolve_references=true, $ar_records=[]) {

		$start_time = start_time();
		
		$response = new stdClass();
			$response->result = false;
			$response->msg 	  = 'Error on export_record '.$section_tipo;
		

		$ar_diffusion_map_elements = diffusion::get_ar_diffusion_map_elements(DEDALO_DIFFUSION_DOMAIN);
			#dump($ar_diffusion_map_elements, ' ar_diffusion_map_elements ++ '.to_string($diffusion_element_tipo)); die();	

			if (!isset($ar_diffusion_map_elements[$diffusion_element_tipo])) {
				debug_log(__METHOD__." Skipped diffusion_element $diffusion_element_tipo not found in ar_diffusion_map ".to_string($ar_diffusion_map_elements), logger::ERROR);
				$response->msg .= "Error. Skipped diffusion_element $diffusion_element_tipo not found in ar_diffusion_map";
				return $response;
			}

		$obj_diffusion_element = $ar_diffusion_map_elements[$diffusion_element_tipo];
			#dump($obj_diffusion_element, ' obj_diffusion_element ++ '.to_string($diffusion_element_tipo)); die();

		#
		# DIFFSUION CLASS
		# Each diffusion element is managed with their own class that extends the main diffusion class
		$diffusion_class_name = $obj_diffusion_element->class_name;

		require_once(DEDALO_LIB_BASE_PATH . '/diffusion/class.'.$diffusion_class_name.'.php');
			#dump($diffusion_class_name, '$diffusion_class_name ++ '.to_string()); die();		
		
		$options = new stdClass();
			$options->section_tipo 			= (string)$section_tipo;
			$options->section_id   			= (int)$section_id;
			$options->diffusion_element_tipo= (string)$diffusion_element_tipo;

		#
		# UPDATE_RECORD
		$diffusion 				= new $diffusion_class_name;
		$diffusion->ar_records 	= $ar_records;
		$update_record_result 	= $diffusion->update_record( $options, $resolve_references );
			#dump($update_record_result, " update_record_result ".to_string() ); die();

		if ($update_record_result && $update_record_result->result) {
			$response->result = true;
			$response->msg = sprintf("<span class=\"ok\">Ok. Published record ID %s successfully</span>",$section_id);			
		}else{
			$response->result = false;
			$response->msg = "Error. Error on publish record $section_id";
			
		}

		// Add especific msg		
			if (isset($update_record_result->msg)) {
				$response->msg .= ' - ' . is_array($update_record_result->msg) ? implode(" | ", $update_record_result->msg) : $update_record_result->msg;
			}

		if(SHOW_DEBUG===true) {<commit_msg>Fix comparation error on msg output tool_diffusion export_record<commit_after><?php
/**
* TOOL_DIFFUSION
* Export current section data to mysql database with defined 'difission' options
*
*/
class tool_diffusion {


	public $section_tipo;
	public $section_id;
	public $modo;
	public $options;
	public static $debug_response;



	/**
	* __CONSTRUCT
	*/
	public function __construct( $section_tipo=null, $modo='button' ) {

		if (empty($section_tipo)) {
			throw new Exception("Error Processing Request. Var section_tipo is empty", 1);
		}
		$this->section_tipo = $section_tipo;
		$this->modo 		= $modo;
	}//end __construct



	/** 
	* GET_HTML
	* @return string
	*/
	public function get_html() {
		ob_start();
		include ( DEDALO_LIB_BASE_PATH .'/tools/'.get_called_class().'/'.get_called_class().'.php' );
		return  ob_get_clean();
	}//end get_html



	/**
	* GET_AR_THESAURUS_TABLES
	* @return array Formated array as prefix => name
	*/
	public function get_ar_thesaurus_tables() {
	
		$ar_tables = (array)$this->options->ar_tables;
			#dump($ar_tables, ' ar_tables ++ '.to_string());
		
		$ar_thesaurus_tables = array();
		$i=0;foreach ($ar_tables['prefijo'] as $key => $prefix) {

			if (isset($ar_tables['tipo'][$i-1]) && $ar_tables['tipo'][$i] != $ar_tables['tipo'][$i-1]) { // separator
				$ar_thesaurus_tables[$prefix.'_'.$ar_tables['tipo'][$i]] = 'separator';				
			}
			
			# Do not include langs never
			if ($prefix!='lg') {
				$ar_thesaurus_tables[$prefix] = $ar_tables['nombre'][$i];
			}
			
		$i++;}
		#dump($ar_thesaurus_tables, ' ar_thesaurus_tables ++ '.to_string());

		return $ar_thesaurus_tables;
	}//end get_ar_thesaurus_tables



	/**
	* EXPORT_RECORD
	* @param string $section_tipo
	* @param int $section_id
	* @param string $diffusion_element_tipo
	* @param bool $resolve_references
	*	default: true
	* @return object $response
	*/
	public static function export_record($section_tipo, $section_id, $diffusion_element_tipo, $resolve_references=true, $ar_records=[]) {

		$start_time = start_time();
		
		$response = new stdClass();
			$response->result = false;
			$response->msg 	  = 'Error on export_record '.$section_tipo;
		

		$ar_diffusion_map_elements = diffusion::get_ar_diffusion_map_elements(DEDALO_DIFFUSION_DOMAIN);
			#dump($ar_diffusion_map_elements, ' ar_diffusion_map_elements ++ '.to_string($diffusion_element_tipo)); die();	

			if (!isset($ar_diffusion_map_elements[$diffusion_element_tipo])) {
				debug_log(__METHOD__." Skipped diffusion_element $diffusion_element_tipo not found in ar_diffusion_map ".to_string($ar_diffusion_map_elements), logger::ERROR);
				$response->msg .= "Error. Skipped diffusion_element $diffusion_element_tipo not found in ar_diffusion_map";
				return $response;
			}

		$obj_diffusion_element = $ar_diffusion_map_elements[$diffusion_element_tipo];
			#dump($obj_diffusion_element, ' obj_diffusion_element ++ '.to_string($diffusion_element_tipo)); die();

		#
		# DIFFSUION CLASS
		# Each diffusion element is managed with their own class that extends the main diffusion class
		$diffusion_class_name = $obj_diffusion_element->class_name;

		require_once(DEDALO_LIB_BASE_PATH . '/diffusion/class.'.$diffusion_class_name.'.php');
			#dump($diffusion_class_name, '$diffusion_class_name ++ '.to_string()); die();		
		
		$options = new stdClass();
			$options->section_tipo 			= (string)$section_tipo;
			$options->section_id   			= (int)$section_id;
			$options->diffusion_element_tipo= (string)$diffusion_element_tipo;

		#
		# UPDATE_RECORD
		$diffusion 				= new $diffusion_class_name;
		$diffusion->ar_records 	= $ar_records;
		$update_record_result 	= $diffusion->update_record( $options, $resolve_references );
			#dump($update_record_result, " update_record_result ".to_string() ); die();

		if ($update_record_result && $update_record_result->result) {
			$response->result = true;
			$response->msg = sprintf("<span class=\"ok\">Ok. Published record ID %s successfully</span>",$section_id);			
		}else{
			$response->result = false;
			$response->msg = "Error. Error on publish record $section_id";
			
		}

		// Add especific msg		
			if (isset($update_record_result->msg)) {
				$response->msg .= ' - ' . is_array($update_record_result->msg)===true ? implode(" | ", $update_record_result->msg) : $update_record_result->msg;
			}

		if(SHOW_DEBUG===true) {
{'fraction_non_alphanumeric': 0.14632165235553493, 'fraction_numerical': 0.0009282896263634254, 'mean_word_length': 4.8394308943089435, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033799', 'n_tokens_mistral': 3324, 'n_tokens_neox': 2999, 'n_words': 539}