K2_content module rating - php

I've been reconstructing the standard K2 rating in the category_item.php to view ratings from to show as stars to show as number.
What I did was, I replaced this code:
<?php if($this->item->params->get('catItemRating')): ?>
<div id="catItemRatingBlock">
<div class="itemRatingForm">
<ul class="itemRatingList">
<li class="itemCurrentRating" id="itemCurrentRating<?php echo $this->item->id; ?>" style="width:<?php echo $this->item->votingPercentage; ?>%;"></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
<?php endif; ?>
with this code:
<?php if($this->item->params->get('catItemRating')): ?>
<div id="catItemRatingBlock">
<div class="itemRatingForm">
<?php
$rating_sum=0;
$rating_cont=0;
$db =& JFactory::getDBO();
$query='SELECT * FROM #__k2_rating WHERE itemID='. $this->item->id;
$db->setQuery($query);
$votes=$db->loadObject();
$rating_sum = intval($votes->rating_sum);
$rating_count = intval($votes->rating_count);
$evaluate = ($rating_count==0) ? "0" : number_format($rating_sum/$rating_count,1);
$evaluate = str_replace('.0', '', $evaluate);
$output=" Rating: ". $evaluate."/5";
echo $output;
?>
</div>
</div>
<?php endif; ?>
And what I want is for it to work on the K2 module as well. I tried to use the same code that I wrote above here to achieve it in k2 content module but that doesn't work at all.
Anyone know how to pull it off?

Replace
<?php if($this->item->params->get('catItemRating')): ?>
with:
<?php if($params->get('catItemRating')): ?>

Related

how to get the HREF value using POST

I'm making a dynamic menu where each link in my dropdown menu will be directed to a page base on the ID in the HREF link. How can I POST the ID from my link?
Here's my code:
<?php
$lesson_sql = "SELECT * FROM lesson WHERE lessonID = 1";
$lesson_query = mysqli_query($db, $lesson_sql);
$lesson = mysqli_fetch_assoc($lesson_query);
?>
<nav id="navbar">
<ul id="navmenu">
<div class="navmenu">
<li><strong>Catalog</strong><span class="darrow"></span>
<ul class="sub1">
<li>Topic 1
<ul class="sub1_1">
<?php
do {
?>
<li>
<a href="lesson1.1.php?lessonID=<?php echo $lesson['lessonID'];?>">
<?php echo $lesson['lessonName']; ?>
</a>
</li>
<?php
}while ($lesson = mysqli_fetch_assoc($lesson_query));
?>
</ul>
</li>
</ul>
</li>
</div>
</ul>
</nav>
And here is the code from the code above I wanted to get the ID, its beside the href value.
<li><?php echo $lesson['lessonName']; ?></li>
Sorry for my english, I hope you understand me!
in your lesson1.1.php file you can use $_GET to access the id as below.
$id = $_GET["lessonID"];
If you have query string then you use
$_GET['name of control']

How to split Contao variable into several HTML Elements

I´ve got this template from my Contao CMS:
<?php $helper = new \ContaoBootstrap\Navbar\Helper\NavigationHelper($this); ?>
<?php foreach ($this->items as $item) : ?>
<?php
$currentLevelStringParts = explode('_', $this->level);
$currentLevelNumber = $currentLevelStringParts[1];
?>
<?php $itemHelper = $helper->getItemHelper($item); ?>
<li class="<?php echo str_replace(array('_'), array('-'), $itemHelper->getItemClass());
if (!empty($item['subitems'])) {echo ' subnav';} ?>
">
<<?= str_replace(array('strong'), array('a'), $itemHelper->getTag()); ?>
<?= str_replace(array('dropdown-item', 'dropdown-toggle', 'nav-link', 'data-toggle="dropdown"'), array(' ', ' ', ' ', ' '), $itemHelper) ?>>
<?php if ($item['isActive']) : ?>
<?= $item['link']?>
<?php else : ?>
<span itemprop="name"><?= $item['link']?></span>
<?php endif; ?>
</<?= str_replace(array('strong'), array('a'), $itemHelper->getTag()); ?>>
<?php if (!empty($item['subitems'])) { ?>
<span class="subnav-pull-down hidden-lg-up <?php if ($item['isTrail']) : ?>active<?php endif; ?>"></span>
<div class="subnav-container <?php if ($item['isTrail']) : ?>open<?php endif; ?>">
<div class="relative">
<ul class="nav sub-nav level-<?php echo (int)$currentLevelNumber+1 ?>">
<?= $item['subitems'] ?>
<div class="clear"></div>
</ul>
</div>
</div>
<?php } ?>
</li>
<?php endforeach; ?>
My problem is, I need a HTML structure like:
<ul>
<li><a></a></li>
<li><a></a></li>
<li>
<ul>
<li><a></a></li>
</ul>
</ul>
To change link () and description for my navigation. I tried to work the the bootstrap API but I´m kind of new to PHP and Bootstrap.
I hope you guys can help me.

Can't Link <a href="#"> W/ PHP code

I tried to link $child['id'] but can't do it. Link is removed on line 13. Can anyone tell me correct way to generate category link on click?
<!-- fetch parent categories -->
<?php
while ($parent = mysqli_fetch_assoc($parentquery)) : ?>
<?php
$parent_id=$parent['cat_id'];?>
<!--fetch sub-categories-->
<?php
$sql2 = "SELECT * FROM categories WHERE cat_parent = '$parent_id'";
$child_query = $db->query($sql2); // database object
?>
<div class="col-menu col-md-3">
<h6 class="title"><?php echo $parent['cat_name'] ?></h6>
<div class="content">
<ul class="menu-col">
<?php while($child = mysqli_fetch_assoc($child_query)) : ?>
Now I want to link each category on the below. Loops works fine. I am seeing category names but no link. Please help
<li> <a href='#'>
<?php echo $child['cat_name']; ?></a></li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php endwhile; ?>
You need to pass it in href
<li>
<a href='<?php echo $child['link'];?'>
<?php echo $child['cat_name']; ?>
</a>
</li>
Try this if ur href is empty then you should add
<a href='"<?php echo $child['link'];?>"'> // double quotes
you should pass the id to the href,
<a href='<?=$child['id'];?>'>

Wordpress: Generate a join group button in groups-loop

So this is what I have:
<ul id="popular">
<?php while ( bp_groups() ) : bp_the_group(); ?>
<li <?php bp_group_class(); ?>>
<div class="group-box">
<div class="group-box-image-container">
<a class="group-box-image" href="<?php bp_group_permalink() ?>"><?php bp_group_avatar( 'type=full' ) ?></a>
</div>
<div class="group-box-right">
<div class="group-box-title"><?php $grouptitle = bp_get_group_name(); $getlength = strlen($grouptitle); $thelength = 20; echo mb_substr($grouptitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></div>
<div class="group-box-details">
<div class="gb-a">Active <?php echo bp_get_group_last_active(); ?></div>
<div class="gb-m"><?php bp_group_member_count(); ?></div>
</div>
</div>
</div><!--group-box ends-->
</li>
<?php endwhile; ?>
</ul>
What I need: a link that allow every logged in member to join that group.
How can I do that? I have also the Invite anyone plugin activated...
Okay, I got it:
In the file groups-header.php of the legacy theme I found the code:
do_action( 'bp_group_header_actions' );
The code above did the magic. Funny how wordpress words those actions... Not quite obvious is it?
Anyway, now it works. For the folks who need it, now you know it :)

jQuery Sortable Lists with CodeIgniter

I am attempting to make a sortable list out of list items populated from the database using the jQuery plug in but the effect is only applied to the first item presented:
<?php if(isset($bookmarks)) : foreach($bookmarks as $row) :?>
<div id="makeDrag">
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small">
<?php echo anchor("site/delete/$row->id", "Delete"); ?>
</h4>
</li>
</div>
<?php endforeach; ?>
I can kind of see where this is going wrong but do not know how to fix it. I would obviously like the effect to affect all the populated li not just the first one. Any help would be great. Sorry if I am unclear, I can try and rephrase things if this is confusing.
The cause is likely because you have
$('#makeDrag').sortable();
but you also have a foreach statement that creates multiple #makeDrag elements thus making your HTML invalid.
To fix this:
<?php if(isset($bookmarks)) : ?>
<ul id="makeDrag">
<?php foreach($bookmarks as $row) : ?>
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small"><?php echo anchor("site/delete/$row->id", "Delete"); ?></h4>
</div>
</li>
<? endforeach; ?>
</ul>
<?php endif; ?>
HTH

Categories