Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Maps für Einsatzorte #114

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 42 additions & 3 deletions src/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public function enqueueStyleAndScripts()
Core::VERSION
);
wp_add_inline_style('einsatzverwaltung-frontend', ReportList::getDynamicCss());

if ($this->options->isGMapActivate()) {
wp_enqueue_script('einsatzvw_GoogleMap');
wp_enqueue_script(
'einsatzverwaltung-gmap',
$this->core->scriptUrl . 'einsatzverwaltung-gmaps.js'
);
}
}

/**
Expand Down Expand Up @@ -126,6 +134,33 @@ public function getEinsatzberichtHeader($post, $mayContainLinks = true, $showArc
return "";
}

/**
* Erzeugt eine Google Map des Einsatzortes
*
* @return string Code zum Erzeugen der Google-Map mit Markierten einsatzort
*/
public function getEinsatzberichtMap($post)
{
$report = new IncidentReport($post);
$location = $report->getGmapsLocation();
if ($this->options->isGMapActivate() && $location) {
$latLon = explode(",", $location);

$mapstring = "<style>#map-canvas {height: 300px; position: relative; overflow: hidden;";
$mapstring .= " transform: translateZ(0px); background-color: rgb(229, 227, 223);}</style>";
$mapstring .= "<div class='einsatzliste-map'>";
$mapstring .= "<div id='map-canvas'></div>";
$mapstring .= "</div>";
$mapstring .= "<div style='clear:both'></div>";
$mapstring .= "<script>";
$mapstring .= "google.maps.event.addDomListener(window, 'load', initializeMap(";
$mapstring .= $latLon[0] . ", " . $latLon[1] . "));";
$mapstring .= "addMarker( " . $latLon[0] . ", " . $latLon[1] . ", '" . $report->getLocation() . "', true )";
$mapstring .= "</script>";

return "<p>$mapstring</p>";
}
}

/**
* Erzeugt eine Zeile für die Einsatzdetails
Expand Down Expand Up @@ -168,7 +203,7 @@ public function renderContent($content)
if (empty($template)) {
return $content;
}

$templateWithData = $this->formatter->formatIncidentData($template, array(), $post, 'post');
$templateWithContent = str_replace('%content%', $content, $templateWithData);
return stripslashes(wp_filter_post_kses(addslashes($templateWithContent)));
Expand All @@ -181,8 +216,12 @@ public function renderContent($content)
// Fallback auf das klassische Layout
$header = $this->getEinsatzberichtHeader($post, true, true);
$content = $this->prepareContent($content);
$map = "";
if ($this->options->isGMapActivate()) {
$map = $this->getEinsatzberichtMap($post);
}

return $header . '<hr>' . $content;
return $header . $map . '<hr>' . $content;
}

/**
Expand Down Expand Up @@ -287,7 +326,7 @@ public function addReportsToQuery($query)
} else {
$postTypes = array('post');
}

// Einsatzberichte nur zusammen mit Beiträgen abfragen
if (!in_array('post', $postTypes)) {
return;
Expand Down
13 changes: 13 additions & 0 deletions src/Model/IncidentReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static function getMetaFields()
'einsatz_einsatzort' => array(
'label' => 'Einsatzort'
),
'einsatz_location' => array(
'label' => 'Google Maps Position'
),
'einsatz_einsatzleiter' => array(
'label' => 'Einsatzleiter'
),
Expand Down Expand Up @@ -215,6 +218,16 @@ public function getLocation()
return $this->getPostMeta('einsatz_einsatzort');
}

/**
* Gibt den eingetragenen Einsatzort als googlemaps koordinate zurück
*
* @return string
*/
public function getGmapsLocation()
{
return $this->getPostMeta('einsatz_location');
}

/**
* Gibt die Einsatznummer zurück
*
Expand Down
82 changes: 82 additions & 0 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Options
'einsatzvw_category' => false,
'einsatzvw_loop_only_special' => false,
'einsatzverwaltung_incidentnumbers_auto' => false,
'einsatzvw_gmap' => false,
'einsatzvw_gmap_api' => '',
'einsatzvw_gmap_default_pos' => '53.523463,9.482329',
'einsatzverwaltung_use_excerpttemplate' => false,
);

Expand Down Expand Up @@ -75,6 +78,85 @@ public function getEinsatzberichteCategory()
return (false === $categoryId ? -1 : intval($categoryId));
}

/**
* Gibt die aktiven Spalten für die Einsatzliste zurück
*
* @return array Spalten-IDs der aktiven Spalten, geprüft auf Existenz. Bei Problemen die Standardspalten.
*/
public function getEinsatzlisteEnabledColumns()
{
$enabledColumns = $this->getOption('einsatzvw_list_columns');
$enabledColumns = $this->utilities->sanitizeColumns($enabledColumns);
return explode(',', $enabledColumns);
}

/**
* @return int
*/
public function getEinsatznummerStellen()
{
$option = $this->getOption('einsatzvw_einsatznummer_stellen');
return $this->utilities->sanitizeEinsatznummerStellen($option);
}

/**
* @return string
*/
public function getExcerptType()
{
$option = $this->getOption('einsatzvw_excerpt_type');
return $this->utilities->sanitizeExcerptType($option);
}

/**
* @return string
*/
public function getExcerptTypeFeed()
{
$option = $this->getOption('einsatzvw_excerpt_type_feed');
return $this->utilities->sanitizeExcerptType($option);
}

/**
* @return string
*/
public function getGMapAPI()
{
$option = $this->getOption('einsatzvw_gmap_api');
return $option;
}

/**
* @return string
*/
public function getGMapDefaultPos()
{
$option = $this->getOption('einsatzvw_gmap_default_pos');
return $option;
}

/**
* @return bool
*/
public function isGMapActivate()
{
$option = $this->getOption('einsatzvw_gmap');
return $this->toBoolean($option);
}

/**
* Gibt die Basis für die URL zu Einsatzberichten zurück
*
* @since 1.0.0
*
* @return string
*/
public function getRewriteSlug()
{
$option = $this->getOption('einsatzvw_rewrite_slug');
return sanitize_title($option, $this->defaults['einsatzvw_rewrite_slug']);
}

/**
* @return mixed
*/
Expand Down
Loading