expression engine orderby issue - sql-order-by

Hi I’m trying to order entries by a field called surname but it just doesn’t seem to be working. changing orderby and sort to anything gives the same results - latest entry last in list.
Any ideas what I could be doing wrong?
{exp:query sql="SELECT member_id FROM exp_members WHERE group_id = '5'"}
{exp:member:custom_profile_data member_id="{member_id}" orderby="surname" sort="asc"}
<li><img src="{photo_url}" width="138" height="103" alt="{screen_name}" />
<h3 class="name">{firstname} {surname}</h3></li>
{/exp:member:custom_profile_data}
{/exp:query}

To save yourself some energy you might want to think about using Freemember from Exp-resso on your site. https://github.com/expressodev/freemember
This module has super simple syntax to do what you are wanting and might add some additional features to make your ExpressionEngine development easier.

I'll start by pointing out that if you have a lot of members, this nested query could really bog down your server. It would be much more efficient to use the Query module to get all of your member data in one go, then interate through it without the nested custom_profile_data tag. You'd have to account for variables that get manipulated beforehand using custom_profile_data (like image URLs), but it would be worth the effort in performance gains.
Regardless:
The custom_profile_data tag only queries a single member, so orderby and sort won't make any difference. Your sorting needs to take place during your exp:query tag.
{exp:query sql="SELECT m.member_id FROM exp_members m, exp_member_data d WHERE m.group_id = '5' AND d.member_id = m.member_id ORDER BY d.m_field_id_X ASC"}
{exp:member:custom_profile_data member_id="{member_id}"}
<li><img src="{photo_url}" width="138" height="103" alt="{screen_name}" />
<h3 class="name">{firstname} {surname}</h3>
</li>
{/exp:member:custom_profile_data}
{/exp:query}
Replace m_field_id_X with the actual m_field_id of your surname custom member field (which can be found by looking at exp_member_fields in Tools → Data → SQL Manager).

Related

Umbraco 8 - Get Children Of Node Using ContentAtXPath() Method

I've been refactoring an existing Umbraco project to use more performant querying when getting back document data as everything was previously being returned using LINQ. I have been using a combination of Umbraco's querying via XPaths and Examine.
I am currently stumped on trying to get child documents using the Umbraco.ContentAtXPath() method. What I would like to do is get child document based on a path I parse to the method. This is what I have currently:
IEnumerable<IPublishedContent> umbracoPages = Umbraco.ContentAtXPath("//* [#isDoc]/descendant::/About [#isDoc]");
Running this returns a "Object reference not set to an instance of an object." error and unable to see exactly where I'm going wrong (new to this form of querying in Umbraco).
Ideally, I'd like to enhance the querying to also carry out sorting using the non-LINQ approach, as demonstrated here.
Up until Umbraco 8, content was cached in an XML file, which made XPath perfect for querying content efficiently. In v8, however, the so called "NuCache" is not file based nor XML based, so the XPath query support is only there for ... well... Old times sake, I guess? Either way it's probably not going to be super efficient and (I'd advise) not something to "aim for". That said I of course don't know what you are changing from (Linq can be a lot of things) :-/
It certainly depends on how big your dataset is.
As Umbraco has moved away from the XML backed cache, you should look into Linq queries against your content models. Make sure you use ModelsBuilder to generate the models.
On a small dataset Linq will be much quicker than examine. On a large dataset Examine/Lucene will be much more steady on performance.
Querying NuCache is pretty fast in Umbraco 8, only beaten by an Examine search.
Assuming you're using Models Builder, and your About page is a child of Home page, you could use:
var homePage = (HomePage) Model.Root();
var aboutPage = homePage?.Children<AboutPage>().FirstOrDefault();
var umbracoPages = aboutPage.Children();
Where HomePage is your home page Document Type Alias and AboutPage is your About page Document Type alias.

Request data from database after select in a form has been used

I am really sorry that I bother you again with my question, but this time I am asking about a kind of best practice. I found already various articles/posts about the topic and followed this article: https://makitweb.com/auto-populate-dropdown-with-jquery-ajax-in-laravel/ how to fill a second select based on the choice of a first select. As far as I can see, I have to use javascript and create new route.
My question would be is a new route the best idea because I also can also just call it by itself in the URL bar, eg. URL /getEmployees/1
How can I archive that I still get the required information but at the same time avoid that the URL can be used. Do I have to fetch all required data in the controller itself before I return the view and then filter them?
Thanks
Stephan
Update:
Another approach/try,
What is if I pass directly both tables to my view:
return view ('test')->with(compact('stuff_types'))->with(compact('positions'));
By the way, it really does not matter to select all data in the first instance, both tables will only have a couple of rows.
However, is it now possible to put a filter on the second table in the select view?
{{Form::select('position2', $positions, null, ['class'=>'form-control', 'id'=>"positions2"]) }}
I already tried $positions->where(‘id’, ‘1’), searched the internet for other ways but it always filles the select with the complete table information.
Later on I would love to put a filter with a javascript on the second table, based on the result of the first select, but at first it would be really nice just to see a where condition on it.
Update 2
Ok, another update / question:
Instead of using laravel collectives with
{{Form::select('position2', $positions::pluck('name', 'id'), null, ['class'=>'form-control', 'id'=>"positions2"])}}
I can use html and add an if condition, which I guess can be modified through javascript (will check tomorrow)
<select name="categories" id="categories" class="form-control">
#foreach($positions as $sector)
#if ($sector->id == 2)
<option value="{{ $sector->id }}">{{ $sector->name }}</option>
#endif
#endforeach
</select>
But now I am struggling with my controller. Before I was using this:
$ positions = DB::table('positions')->pluck('name','id');
But this does not seem to work with a standard select so I had to change the pluck to get, but now the larabel collective is not working anymore
$positions = DB::table('positions')->get();
Can anyone explain we why get() works with html, but not with laravel collectives, and vice versa?

How to sort an array values in `desc` in computed?

I have an model value, when i do the each iteration it works fine.
<ul>
<li>See here : </li>
{{#each selectedCreditCard.balances.tenures as |balance|}}
<li>Balances is : {{balance}}</li>
{{/each}}
</ul>
But I require to sorted the value by desc way. so I use the computed method to do the desc the array.
sortTenuresBy:['desc'],
sortedTenures: Ember.computed.sort('selectedCreditCard.balances.tenures', 'sortTenuresBy'),
maxTenure:Ember.computed(function(){
return this.get('sortedTenures').get('firstObject');
But getting error as like this:
Assertion Failed: When using #each to observe the array 3,8,12,24, the array must return an object
how to fix this? please help me
If you look at API definition for Ember.computed.sort; it requires a property key (that is selectedCreditCard.balances.tenures in your case) and a sort definition (that is sortTenuresBy in your case). However, if you look at the examples provided; the sort definition must be either a plain property name or a property name followed by sort type such as name:desc or key:asc and so on. In summary; it is not possible to use Ember.computed.sort for plain arrays as in your case. I admit the API documentation is vague.
For your case; you have to either write the computed property as a function; which is what you do not want I suppose; because it is the common way; or you can make use of the following addon. What is great about ember-awesome-macros is you can nest the provided computed macros.
If you look at API for array.sort; it says "combines the functionality of both Array.prototype.sort() and Ember.computed.sort". Hence we can use this one. You want the array to be sorted in descending; I suppose something like the following
sortTenuresBy: array.reverse(array.sort('selectedCreditCard.balances.tenures'))
should work.

Laravel pagination using infinite scroll

Can anyone help me by pointing me in the right direction on how to implement an infinite scroll in Laravel?
I'm familiar with Laravel's pagination tool and I'm also familiar with Javascript.
I just can't figure out what should i send via ajax to my controller?
By that i mean what url parameters and how would that dynamically change on scrolling?
Thanks in advance.
you do not have to send via ajax something special
just grab via JS the id of last post which already have been loaded and perform ajax.get to http://example.com/foo/100500
catch id in routes.php something like this Route::get('foo/{id}', 'BazController#bar'
then perform any logic in your controller as you wish just considering the id
for example select from database where id between id and id+20
UPDATED
considering #ugochimbo 's question
Let's say when we GET our page first time, we obtain something like
<div id="container">
<div id="post-30">Lorem impum dolor</div>
<div id="post-29">Lorem impum dolor</div>
<div id="post-28">Lorem impum dolor</div>
</div>
An event is happened e.g. ( scrollTop is more than some px )
Then we execute something like
Hey, jQuery! Gimme "id" of the last child of the #container //it will
be "post-28"
Considering the id, we perform an ajax query to a server.
I assume that for the simpliest implementation of infinity scrolling, we have to know just the "id" on the client side, nothing else.
Of course, in any real cases there is also a bunch of additional information, such as DESC or ASC or whatever else. It's all up to you.
Let's say we obtained on the server side via ajax query
{lastLoadedPostId: 'post-28', order: 'DESC', postsPerQuery: 3}
Of course, we have to make some preparations e.g. Cut "post-" from "lastLoadedPostId" etc
Then we ask our database
Hey, database! Gimme 3 posts, that have id less than 28, in desc order
If nonIncremental identificators are used in your database, and you obtain on the server side
{lastLoadedPostId: 'qwertyuid', order: 'DESC', postsPerQuery: 3}
In that case you should perform one extra query to database
Hey, database! Tell me when "qwertyuid" was created
Hey, database! Gimme 3 posts that were created earlier than "timestamp
of qwertyuid"
For this purpose you may use commands like LIMIT, OFFSET or whatever your database provided, but it's already other question

How to dynamically change the element definition of a region in content presenter template in Webcenter Portal?

I have been following Yannick Ongena's tutorial http://yonaweb.be/webcenter_tutorial/using_content_presenter_templates
I am looking to alter some code in the content presenter template "training-list-item.jsff" so that the region definition will have a dynamic value.
That is, rather than writing
<af:outputText value="#{node.propertyMap['RD_TRAINING:description'].asTextHtml}"
escape="false" id="ot5"/>
I am looking to write like
<af:outputText value="#{node.propertyMap['xRegionDefinition:description'].asTextHtml}"
escape="false" id="ot5"/>
Unfortunately, this does not work. If I write only "xRegionDefinition" within the propertyMap,it displays the region definition name in the portal, that is "RD_TRAINING". But I am looking to display the value of element definition within the region that is, the "description".
My objective is to display different region definitions at the portal rather than a hard coded fixed region. I have wrote some Java code also to dynamically change the CMIS query to supply a new value for the region definition:
if(news){
query = "SELECT * FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition LIKE \'RD_TRAINING\'";
}
else
query = "SELECT * FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition LIKE \'RD_SWEDISH\'";
Please help. Hope I am clear in explaining the requirement.
Why don't you use ADF Switcher component if you only have 2 options!
Check this video to know how to use it

Resources