Propel Nested Set in combination with Pagination - pagination

$root = AnimeCommentQuery::create()->findRoot(2);
$html = "<ul>{$root->getComment()}";
foreach ($root->getDescendants() as $post)
{
$html .= '<li style="padding-left: '.$post->getLevel().' em;">';
$html .= $post->getComment();
$html .= ' by '.$post->getIbfMembersRelatedByInsertBy()->getName();
$html .= "</li>";
}
$html .= "</ul>";
echo $html;
I want to paginate the posts but I am not able to do this by:
$root = AnimeCommentQuery::create()->findRoot(2)->paginate(2, 1);
OR
$root = AnimeCommentQuery::create()->paginate(2, 1)->findRoot(2);
Can it be done with standard Pagination from propel? And how?

Don't know if this is too late....
First off, you can't use the paginate and find in the same query, they're both termination methods.
I think what you need is something like this:
$comments = AnimeCommentQuery::create()->inTree(2)->orderByBranch()->paginate(2,1);
Then foreach your way through that Collection.
Now you'll have to be a bit clever with when to close and open lists, checking current Level etc. And top and bottom of page 2+ will take a bit of consideration too. Good Luck!
The Nested Set API is worth studying further http://www.propelorm.org/behaviors/nested-set.html#complete_api, got a fair bit in.
Also consider using a ->joinWith() to get your getIbfMembersRelatedByInsertBy() prepopulated in the main query.

Related

How to get a list of all user groups in Modx Revolution

Trying to get a list of group names from modx revolution, digging through the API and docs, but not having much luck finding a function that does this.
How can I get a list of groups [names & ids] in a snippet from a modx revolution instance>?
<?php
$where = array();
$userGroups = $modx->getCollection('modUserGroup', $where);
foreach ($userGroups as $userGroup) {
print $userGroup->get('name');
}
You can do it without the loop.
<?php
$q = $modx->newQuery('modUserGroup');
$q->select(['name']);
$q->prepare();
$q->stmt->execute();
$userGroups = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
print_r($userGroups);
<?php
//Group IDs array
print_r($modx->user->getUserGroups());
//Group Names array
print_r($modx->user->getUserGroupNames());

how to: findByProperty on two fields in typo3 v4.5.30?

I want to search for records which match on two fields with two supplied objects,
for example
$cnt = $this->usedCouponRepository->findByUser($validvip)->toArray() ;
$cnt2 = $this->usedCouponRepository->findByCoupon($validcoupon)->toArray() ;
get interesection, (find how many times validvip pairs up with validcoupon in the usedcoupon table)
a call like this would be it -
$cnt3 = $this->usedCouponRepository->findByUserAndCoupon($validcoupon,$validuser);
is there a magic function to do this or some other efficient way? I'd hate to just loop over the first looking for a match in code.
Thanks
Nope, there is no "extbase magic" doing this job for you. You have to implement it yourself. But lucky you, its not that hard. Just add a method to your repository like this one:
public function findByUserAndCoupon($validcoupon, $validuser) {
$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->equals('user', $validuser),
$query->equals('coupon', validcoupon)
)
);
$result = $query->execute();
return $result;
}
Now you can call this like you tried before. The strings 'user' and 'coupon' in the logicalAnd Statement have to be the fieldnames of the database.

Specify a page for pagination - Laravel 4

I'm trying to "remember" the page the user was on as he browses through records so that when he returns to the list, he is returned to the page where he left off.
How do I change the "current page" value for paginator?
I've tried Input::set('page', $x); but there's no such function.
$_GET['page'] = $x; doesn't work too.
This the code:
$list = Publication::orderBy($this->data['sort_by'], $this->data['order_by']);
foreach ($this->data['filter_data'] AS $field => $value) {
$list->where($field, 'LIKE', "%$value%");
}
$this->data['list'] = $list->paginate(15);
I looked at the API --- turns out this is much easier now in 2014.
All you have to do is set
Paginator::setCurrentPage(2);
any time before you call ->paginate(), I believe, and it should override the page set (or not set) by ?page=.
You can adjust the page of the pagination environment through the DB connection.
DB::getPaginator()->setCurrentPage(2);
Not entirely sure but you might be able to go through your model with something like this.
Publication::getConnection()->setCurrentPage(2);
If the above isn't working (as it seems from your comment), then do it with an instance of Publication.
$publication = new Publication;
$publication->getConnection()->setCurrentPage(2);
$list = $publication->orderBy(...);
Try
$pager->setCurrentPage(2);

Lucene Search for SiteCore get Field content from result

Hy. I have run into a small problem. I am using Lucene Search and I am trying to get the content from a field in the returned result. I have got so far until the ID's of the field. Right now i get the field's ID' like that.
foreach (var i in hit.Template.InnerItem.InnerData.Fields)
{
hitParagraph = hitParagraph + i.ToString();
}
This gives me the ID's of the field inside that template like this
[{25BED78C-4957-4165-998A-CA1B52F67497}, 20130307T051813][{5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}, vh\branea1][{8CDC337E-A112-42FB-BBB4-4143751E123F}, 51885b42-bf8b-4f26-8259-125d352457f3][{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}, .....
Please some help.
Thank You
I'm not entirely sure what you're after. If it's the content of a specific field, you could just use hit["fieldname"] (assuming hit is a Sitecore item). Or hit.Template.InnerItem["fieldname"] would work, I think.
I think you don't need the InnerData bit - if you want a foreach loop I think you could do it like so:
foreach (Field i in hit.Template.InnerItem.Fields)
{
hitParagraph += i.Value.ToString();
}
From what I understand from your code, the hit is a Sitecore Item class instance. To get all the fields from it, use:
hit.Fields.ReadAll();
foreach (Field field in hit.Fields)
{
hitParagraph = hitParagraph + field.Key + ": " + item[field.Key] + "\n";
}

Drupal 6 - Passing variable between functions specifically - Passing menu name to phptemplate_menu_item

I'm quite new to Drupal 6 and theming it. My theme required the main menu to pump out quite extensive html/css for my reasonably involved styling. To achieve this I pieced together this code 'function phptemplate_menu_item' (see bottom) which sits in my template.php and produces different html depending on the whether the menu item has children or not and uses the contents of the link to generate a css class.
My problem is that this code is also being applied to my other menus. I would like make the menu_item generate different html depending on whether it is in the primary-menu or not. I would have thought that the easiest way to do this is with an if statement in the function phptemplate_menu_item, for example:
function phptemplate_menu_item (...){
if ($menu_name == 'primary-links')
{DO ABC}
else
{DO XYZ}
}
However I believe I need to know how to pass the menu name to the phptemplate_menu_item function. Any help with this would be really appreciated as I have been banging my head against the wall trying to solve this for some time now.
Thanks!
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'no_wrap' : ($has_children ? 'collapsed' : 'li_wrap'));
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
if ($in_active_trail) {
$class .= ' active-trail';
}
if (!empty($link)) {
/* The following section gives the list items unique classes based on their link text - note how spaces and sepcial chars are removed */
// remove all HTML tags and make everything lowercase
$css_id = strtolower(strip_tags($link));
// remove colons and anything past colons
if (strpos($css_id, ':')) $css_id = substr ($css_id, 0, strpos($css_id, ':'));
// Preserve alphanumerics, everything else goes away
$pattern = '/[^a-z]+/ ';
$css_id = preg_replace($pattern, '', $css_id);
$class .= ' '. $css_id;
}
// the following code returns the menu item formatted in a different fashion depending on the class of the item. The first one is for items with a class of none - ie the space li at end of menu
if (strstr($class, 'none')) {
return '<li class="'. $class . ' main"></span></span></li>';
}
if (strstr($class, 'li_wrap')) {
return '<li class="'. $class .' main"><span class="wrapped">'. $link . $menu ."<span class='indicator'></span></li>\n";
}
if (strstr($class, 'no_wrap')) {
return '<li class="'. $class . ' main">'. $link ."<span class='indicator'></span><span class='menu_box'><span class='menu_box_inner'>". $menu ."</span></span></li>\n";
}
}
Well I think the solution found here it's the best so I'm not going to take credit for it. Instead of overwriting theme_menu_item you should define your custom function theme_primary_links starting from theme_links.You can choose whatever name you think it's best for your custom theme (but make sure that it's not already used).
Bottom line: sometimes it's easier to define your custom theme than overwriting the default ones. That way you know that you can strictly apply the custom theme according to your needs (e.g. applied only to the primary menu links). Overwriting is best used when you want your changes to be global (e.g. applied to all menu links).

Resources