<commit_before><?php
/**
 * @date Mon, 08 Sep 2008 06:52:09 +0000
 * @author intessit
 * @package
 */
class markergmaps_PositionService extends f_persistentdocument_DocumentService
{
	/**
	 * @var markergmaps_PositionService
	 */
	private static $instance;
	
	/**
	 * @return markergmaps_PositionService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}
	
	/**
	 * @return markergmaps_persistentdocument_position
	 */
	public function getNewDocumentInstance()
	{
		return $this->getNewDocumentInstanceByModelName('modules_markergmaps/position');
	}
	
	/**
	 * Create a query based on 'modules_markergmaps/position' model
	 * @return f_persistentdocument_criteria_Query
	 */
	public function createQuery()
	{
		return $this->pp->createQuery('modules_markergmaps/position');
	}
	
	/**
	 * @param markergmaps_persistentdocument_position $document
	 * @param Integer $parentNodeId Parent node ID where to save the document (optionnal => can be null !).
	 * @return void
	 */
	protected function preSave($document, $parentNodeId = null)
	{
		if ($document->getColormarker() === null)
		{
			$document->setColormarker(GmapsHelper::getDefaultIconColor());
		}
		if ($document->getZoom() === null)
		{
			$document->setZoom(GmapsHelper::getDefaultZoomLevel());
		}
	}
	
	/**
	 * @param generic_persistentdocument_folder $folder
	 */
	public function getOv2ContentForFolder($folder)
	{
		$positions = $this->createQuery()->add(Restrictions::descendentOf($folder->getId()))->add(Restrictions::published())->find();
		return $this->getOv2ContentForPositions($positions);
	}
	
	/**
	 * @param markergmaps_persistentdocument_position[] $positions
	 */
	public function getOv2ContentForPositions($positions)
	{
		$content = "";
		foreach ($positions as $position)
		{
			$label = $position->getLabel();
			$content .= pack('C', 0x02) . pack('V', mb_strlen($label) + 14) . pack('V', (int)round($position->getLongitude() * 100000.0)) . pack('V', (int)round($position->getLatitude() * 100000.0)) . $label . chr(0x00);
		}
		return $content;
	}
	
	/**
	 * @param generic_persistentdocument_folder $folder
	 */
	public function getGpxContentForFolder($folder)
	{
		$positions = $this->createQuery()->add(Restrictions::descendentOf($folder->getId()))->add(Restrictions::published())->find();
		return $this->getGpxContentForPositions($positions);
	}
	
	/**
	 * @param markergmaps_persistentdocument_position[] $positions
	 */
	public function getGpxContentForPositions($positions)
	{
		$xmlWriter = new XMLWriter();
		$xmlWriter->openMemory();
		$xmlWriter->startDocument("1.0", "UTF-8");
		if (Framework::isDebugEnabled())
		{
			$xmlWriter->setIndent(true);
		}
		$xmlWriter->startElement("gpx");
		$xmlWriter->writeAttribute('xmlns', "http://www.topografix.com/GPX/1/1");
		$xmlWriter->writeAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
		$xmlWriter->writeAttribute('xsi:schemaLocation', "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
		$xmlWriter->writeAttribute("version", "1.1");
		$xmlWriter->writeAttribute("creator", "RBS Change");
		foreach ($positions as $position)
		{
			$xmlWriter->startElement("wpt");
			$xmlWriter->writeAttribute('lon', strval($position->getLongitude()));
			$xmlWriter->writeAttribute('lat', strval($position->getLatitude()));
			$xmlWriter->writeElement("name", $position->getLabel());
			$xmlWriter->endElement();
		}
		$xmlWriter->endElement();
		return $xmlWriter->flush();
	}
	

	/**
	 * @see f_persistentdocument_DocumentService::getResume()
	 *
	 * @param markergmaps_persistentdocument_position $document
	 * @param string $forModuleName
	 * @param unknown_type $allowedSections
	 * @return array
	 */
	public function getResume($document, $forModuleName, $allowedSections)
	{
		$data = parent::getResume($document, $forModuleName, $allowedSections);
		$data['properties']['latitude'] = $document->getLatitude();<commit_msg>[FIX] Homogénéisation des méthodes getNewDocumentInstance et getResume<commit_after><?php
/**
 * @date Mon, 08 Sep 2008 06:52:09 +0000
 * @author intessit
 * @package
 */
class markergmaps_PositionService extends f_persistentdocument_DocumentService
{
	/**
	 * @var markergmaps_PositionService
	 */
	private static $instance;
	
	/**
	 * @return markergmaps_PositionService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}
	
	/**
	 * @return markergmaps_persistentdocument_position
	 */
	public function getNewDocumentInstance()
	{
		return $this->getNewDocumentInstanceByModelName('modules_markergmaps/position');
	}
	
	/**
	 * Create a query based on 'modules_markergmaps/position' model
	 * @return f_persistentdocument_criteria_Query
	 */
	public function createQuery()
	{
		return $this->pp->createQuery('modules_markergmaps/position');
	}
	
	/**
	 * @param markergmaps_persistentdocument_position $document
	 * @param Integer $parentNodeId Parent node ID where to save the document (optionnal => can be null !).
	 * @return void
	 */
	protected function preSave($document, $parentNodeId = null)
	{
		if ($document->getColormarker() === null)
		{
			$document->setColormarker(GmapsHelper::getDefaultIconColor());
		}
		if ($document->getZoom() === null)
		{
			$document->setZoom(GmapsHelper::getDefaultZoomLevel());
		}
	}
	
	/**
	 * @param generic_persistentdocument_folder $folder
	 */
	public function getOv2ContentForFolder($folder)
	{
		$positions = $this->createQuery()->add(Restrictions::descendentOf($folder->getId()))->add(Restrictions::published())->find();
		return $this->getOv2ContentForPositions($positions);
	}
	
	/**
	 * @param markergmaps_persistentdocument_position[] $positions
	 */
	public function getOv2ContentForPositions($positions)
	{
		$content = "";
		foreach ($positions as $position)
		{
			$label = $position->getLabel();
			$content .= pack('C', 0x02) . pack('V', mb_strlen($label) + 14) . pack('V', (int)round($position->getLongitude() * 100000.0)) . pack('V', (int)round($position->getLatitude() * 100000.0)) . $label . chr(0x00);
		}
		return $content;
	}
	
	/**
	 * @param generic_persistentdocument_folder $folder
	 */
	public function getGpxContentForFolder($folder)
	{
		$positions = $this->createQuery()->add(Restrictions::descendentOf($folder->getId()))->add(Restrictions::published())->find();
		return $this->getGpxContentForPositions($positions);
	}
	
	/**
	 * @param markergmaps_persistentdocument_position[] $positions
	 */
	public function getGpxContentForPositions($positions)
	{
		$xmlWriter = new XMLWriter();
		$xmlWriter->openMemory();
		$xmlWriter->startDocument("1.0", "UTF-8");
		if (Framework::isDebugEnabled())
		{
			$xmlWriter->setIndent(true);
		}
		$xmlWriter->startElement("gpx");
		$xmlWriter->writeAttribute('xmlns', "http://www.topografix.com/GPX/1/1");
		$xmlWriter->writeAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
		$xmlWriter->writeAttribute('xsi:schemaLocation', "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
		$xmlWriter->writeAttribute("version", "1.1");
		$xmlWriter->writeAttribute("creator", "RBS Change");
		foreach ($positions as $position)
		{
			$xmlWriter->startElement("wpt");
			$xmlWriter->writeAttribute('lon', strval($position->getLongitude()));
			$xmlWriter->writeAttribute('lat', strval($position->getLatitude()));
			$xmlWriter->writeElement("name", $position->getLabel());
			$xmlWriter->endElement();
		}
		$xmlWriter->endElement();
		return $xmlWriter->flush();
	}
	

	/**
	 * @see f_persistentdocument_DocumentService::getResume()
	 *
	 * @param markergmaps_persistentdocument_position $document
	 * @param string $forModuleName
	 * @param array $allowedSections
	 * @return array
	 */
	public function getResume($document, $forModuleName, $allowedSections = null)
	{
		$data = parent::getResume($document, $forModuleName, $allowedSections);
		$data['properties']['latitude'] = $document->getLatitude();
{'fraction_non_alphanumeric': 0.1660716484057614, 'fraction_numerical': 0.014034223808937584, 'mean_word_length': 5.332034294621979, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 38}, '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': '7135136', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2567, 'n_words': 412}