File: /var/www/html/wp-content/plugins/bsx/inc/cass-single.php
<?php
function render_cassandra() {
$id = get_queried_object_id();
global $wpdb;
$stx = bsx_rest_get("styx",['cid'=>$id])[0];
$stars = ['★','☆'];
$intrate = round(floatval($stx['rating']));
$rate = str_repeat($stars[0], $intrate) . str_repeat($stars[1], 5 - $intrate);
$desc = get_field("description", $id);
$cs_name = get_field("company_name", $id);
$logo_cass = get_the_post_thumbnail_url(get_post($id), 'medium');
$unique_id = 'desc-' . $id;
ob_start()
?>
<div class="cassandra-container">
<div class="cassandra-header">
<div class="cassandra-name"><?php echo esc_html($cs_name); ?></div>
</div>
<div class="cassandra-main">
<div class="cassandra-left">
<img class="cassandra-img" src="<?php echo esc_url($logo_cass); ?>" alt="<?php echo esc_attr($cs_name); ?>">
</div>
<div class="cassandra-right">
<div class="cassandra-infoblock">
<div class="cassandra-metric">
<span class="metric-label">Number publications </span>
<span class="metric-value"><?php echo esc_html($stx['nbrCampaigns']); ?></span>
</div>
<div class="cassandra-metric">
<span class="metric-label">..thereof completed </span>
<span class="metric-value"><?php echo esc_html($stx['nbrCompleted']); ?></span>
</div>
<div class="cassandra-metric">
<span class="metric-label">Short-term impact </span>
<span class="metric-value"><?php echo esc_html(sprintf("% 6.2f %%", 100* floatval($stx['shorttermImpact']))); ?></span>
</div>
<div class="cassandra-metric">
<span class="metric-label">Mid-term return </span>
<span class="metric-value"><?php echo esc_html(sprintf("% 6.2f %%", 100* floatval($stx['investmentImpact']))); ?></span>
</div>
</div>
<div class="cassandra-infoblock">
<div class="cassandra-metric">
<span class="metric-label">PnL high </span>
<span class="metric-value"><?php echo esc_html(sprintf("% 6.2f %%", 100 * floatval($stx['pnlHigh']))); ?></span>
</div>
<div class="cassandra-metric">
<span class="metric-label">Days until PnL high </span>
<span class="metric-value"><?php echo sprintf("% 6.2f days",floatval($stx['days2high'])); ?></span>
</div>
<div class="cassandra-metric">
<span class="metric-label">Average Holding time </span>
<span class="metric-value"><?php echo sprintf("% 6.2f days",floatval($stx['daysHold'])); ?></span>
</div>
<div class="star-rating"><?php echo $rate; ?></div>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode('single-cassandra','render_cassandra');
function cass_desc($args) {
$id = get_queried_object_id();
$desc = get_field("description", $id);
return $desc;
}
add_shortcode('cass-desc', 'cass_desc');
function single_cassandra_enqueue (){
// single cassandra
// -------------------------------------------------------------------------------------------
wp_enqueue_style(
'single-cassandra',
BSX_PLUGIN_URL . 'ass/css/single-cassandra.css',
array(),
'2.0.0'
);
}
add_action('wp_enqueue_scripts', 'single_cassandra_enqueue', 999);