Jump to content

Arcturus

Members
  • Posts

    88
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Arcturus

  1. Thanks Horst, unfortunately that module only adds the same page tree view functionality that's already built into v2.3.
  2. I'm trying to do a pair of seemingly simple things, given how the rest of Processwire works, but can't figure them out. 1) I've added the fields "firstname" and "lastname" to the User template and would like to list those values along with Name, E-Mail Address and Roles in the Admin > Access > Users table. There's a built-in option to do this for the user list in the page tree view... but not the place where you'd be doing your user management. I looked through the admin files and couldn't find where this list was being generated. 2) I'd like to change the label for the system name field from "Name" to "Username" for clarity purposes. Any suggestions?
  3. The link on the homepage says version 2.3.0 and then takes you to a zip file saying 2.2.9. If that isn't an error, it's at least confusing.
  4. Soma, your code works but only collects the tallest peak from each report while ignoring others that could still make a "top" list. Seems everyone's running into the same problem on how to access and sort all of the repeater field values at once. Dumping to an array may not be pretty or super efficient, but it seems to be one way to overcome the issues presented by the nested data. And you were right, I was mixing up page fields with pagearrays earlier.
  5. Thanks for the optimizations Pete! One thing though, similar to MadeMyDay's suggestions your sort only works on individual pages. So if page A has one item, page B three items, and C one item... the three items on B will sort correctly amongst themselves, but the overall list just follows the default page sequence. This is what lead me to the workaround of dumping everything out to an array before performing the sort. Nonetheless, I was still able to cut out a number of lines of code. Soma, if the site were the type where dozens of people would be submitting their experiences about a particular destination, then for sure the pagearray would make sense. But the trips are unique and the mountains are only referenced from their report page and, if the stats are remarkable in some fashion, from the parent page in one of these generated lists. Because of this, the repeater gives me what I need while saving a TON of work on the administrative side. I'm using pagearrays for my activity and geographic region related metadata because they're reused frequently and have allowed me to crank out "category" type pages in mere minutes (very nice!). However, thanks for raising the point about redundancy. On reflection, I have no need for the time and distance in the repeater as those fields should be entered once as part of the report template. I didn't get a chance to work through and test your code examples, but will do so when I get a chance tomorrow. Thanks for the help!
  6. One additional note is that "usort" seems to have some issues with decimal values. One of my lists is distance related and allows a single decimal place for values such as "10.7". The output I was getting was about 95% correct with perplexing errors that seemed to have no particular pattern. After a bunch of experiments I found that using a simple multiplication to eliminate the decimal value for the comparison function resolved the problem. usort($dest, function($a, $b) { $a = $a->distanceKm * 10; // example: 10.7 becomes 107 $b = $b->distanceKm * 10; return $b - $a; });
  7. Eureka! It would be nice if there was a more direct way to do this using PW, and perhaps there is, but I eventually succeeded by dumping the repeater fields I needed into a separate array and then performing a sort on that array. Here's the code with some additional commenting: <?php $peaklist = $pages->find("template=report"); // returns relevant page IDs $dest = array(); foreach($peaklist as $location) { $mountain = $pages->get("id=$location"); // grabs pages to allow access to fields foreach($mountain->mountains as $peak){ if ($peak->stats_mtnName){ // pages create 4 blank repeater "value sets" by default, this is a test to grab only populated ones $maxElevft = number_format(round($peak->stats_maxElev * 3.28084)); // to convert a field value in metres to feet; using number_format() to add thousands separators (ie. 3200 -> 3,200) ++$i; $dest[$i]->url = $mountain->url; // field from page $dest[$i]->name = $peak->stats_mtnName; // field from repeater $dest[$i]->maxElevM = $peak->stats_maxElev; // field from repeater $dest[$i]->maxElevF = $maxElevft; } } } usort($dest, function($a, $b) { return $b->maxElevM - $a->maxElevM; // sorts in descending order, reverse A & B for ascending order }); echo '<ul class="blocklist">'; foreach($dest as $item) { echo '<li><p class="tabular"><a href="'.$item->url.'">'.$item->name.' '.number_format($item->maxElevM).'m / '.$item->maxElevF.' ft.</a></p></li>'; } echo '</ul>'; ?>
  8. The above code (from #7) produced this error: Here's the last functioning code mentioned in #3: <?php $peaklist = $pages->find("template=report"); echo '<ul class="blocklist">'; foreach($peaklist as $location) { $mountain = $pages->get("id=$location"); foreach($mountain->mountains->sort('stats_maxElev') as $peak){ if ($peak->stats_mtnName){ $maxElevft = number_format(round($peak->stats_maxElev * 3.28084)); echo '<li><p class="tabular"><a href="'.$mountain->url.'">'.$peak->stats_mtnName.' '.number_format($peak->stats_maxElev).'m / '.$maxElevft.' ft.</p></li>'; } } } echo '</ul>'; ?> I think that part of the problem is that I can't read any values from a repeater until that second loop. I've come up with a couple of new ideas on how to approach this issue and will see where I get.
  9. Thanks MadeMyDay. I tweaked the above to this... foreach($mountain->mountains->sort('stats_maxElev') as $peak){ and it worked for single instances of the repeater (one page with three mountains sorted itself correctly), but not across multiple pages.
  10. Is it possible to generate a page list based on sorted values from a repeater field? I'm working on an outdoors/travel-related website (and my first using PW) where pages using a "report" template have a repeater field called "mountains" containing metadata such as elevations and other statistics. Given that these reports can profile up to four mountains within a single report, the repeater field type seems to work perfectly for this purpose. The problem for me is that I'm trying to generate "Top X"-type lists on the parent page based on this metadata and, after scouring both this forum and the available documentation for hours, I haven't had any luck in this endeavour. The only reference to sorting a repeater I could find was for sorting a single instance of a repeater from within its originating page. As suggested in the documentation, I tried activating "auto-joining" on the repeater and some of its sub-fields with no effect. The following should provide a bit more context: The following code works to generate an unsorted list... and can be made sortable from the first line by every available field (it seems) except for those in my repeater. >_< <h3>By Maximum Elevation</h3> <?php $peaklist = $pages->find("template=report"); echo '<ul class="blocklist">'; foreach($peaklist as $location) { $mountain = $pages->get("id=$location"); foreach($mountain->mountains as $peak){ if ($peak->stats_mtnName){ $maxElevft = number_format(round($peak->stats_maxElev * 3.28084)); echo '<li><p class="tabular"><a href="'.$mountain->url.'">'.$peak->stats_mtnName.' '.number_format($peak->stats_maxElev).'m / '.$maxElevft.' ft.</p></li>'; } } } echo '</ul>'; ?> Any ideas? I'd really prefer to avoid having to use page fields if at all possible.
  11. Interesting, but too little too late as far as I'm concerned. I was all set to build my first EE site a month ago when they pulled that "license simplification" malarkey overnight, which sent me on a lengthy exploration of various CMS systems and eventually led me here. I can't really think of a reason I'd ever go back.
×
×
  • Create New...