Ah, very good. Thank you for catching that. And yes, it makes sense to move $q and $s to the beginning. I made a couple additional small changes, including moving lastmodified to the displayreplace function. That makes it available in all our templates/fmts as well...
Very happy to extend BoltWire's core features. Especially when we can make it smaller and more powerful at the same time. I suspect this might have a mild impact on performance in long complex searches/sorts, but it is probably only minimal. The pro's are definitely significant! Will put it in the next release! Cheers, Dan On Fri, Oct 10, 2014 at 3:21 AM, Tiffany Grenier <[email protected]> wrote: > Hi Dan, > In the function you wrote, $p has no value. It thus cannot work. Also, I'm > not sure about how would the $args array parameter interpreted in the first > two lines, so I suggest you to rewrite the function in the following way > instead: > function BOLTsearchResultsSort($outarray, $args) { > $q = $args['query']; > $s = $args['sort']; > $sortFunc = "BOLTsort$s"; > if (function_exists("BOLTsort$s")) return $sortFunc($outarray); > $sortFunc = 'BOLTsort' . BOLTconfig('language'); > if (function_exists($sortFunc)) return $sortFunc($outarray); > if ($s == 'lastmodified') $s = '{+lastmodified}'; > foreach ($outarray as $p=>$page) { // allows for index.names::{+p} > for example > $ss = str_replace(Array('{+field}', '{+value}', '{+value::'), > Array($page, "$q::$page", "$q::$page::"), $s); > if (strpos($ss, '{+lastmodified}') !== false) { > $lm = BOLTFlastmodified(Array('page' => $page, 'dir' => > $args['dir'])); > $ss = str_replace('{+lastmodified}', $lm, $ss); > } > if (strpos($ss, '{+') !== false) $ss = > preg_replace('/\{\+([0-9]+)\}/e', 'BOLTinfoVar($q, "$page::$1")', $ss); > $sortarray[$page] = BOLTdisplayReplace($ss, $p, $outarray); > } > if ($s == '{+lastmodified}') arsort($sortarray); > else natcasesort($sortarray); > return array_keys($sortarray); > } > Now my birthday calendar only needs to be pimped a bit with templates, > that's great ! > Thank you, again, very much for your great work. It is very nice of you to > extend Boltwire's features just for one requirement. > > Cheers, > Tiffany > > Le jeudi 9 octobre 2014 22:41:18 UTC+2, Dan a écrit : >> >> Hi Tiffany >> >> I got to looking at this and it turns out the BOLTsearchResultsSort >> function in library.php is not smart enough to do this. I got to tinkering, >> and discovered we could get much better functionality in less code by >> swapping the entire function out with the following. Why don't you try it >> and let me know how it goes: >> >> function BOLTsearchResultsSort($outarray, $args) { >> $sortFunc = "BOLTsort$args[sort]"; >> if (function_exists("BOLTsort$args[sort]")) return $sortFunc($outarray); >> $sortFunc = 'BOLTsort' . BOLTconfig('language'); >> if (function_exists($sortFunc)) return $sortFunc($outarray); >> $q = $args['query']; >> $s = $args['sort']; >> if ($s == 'lastmodified') $s = '{+lastmodified}'; >> foreach ($outarray as $page) { // allows for index.names::{+p} for >> example >> $ss = str_replace(Array('{+field}', '{+value}', '{+value::'), >> Array($page, "$q::$page", "$q::$page::"), $s); >> if (strpos($ss, '{+lastmodified}') !== false) { >> $lm = BOLTFlastmodified(Array('page' => $page, 'dir' => $args['dir'])); >> $ss = str_replace('{+lastmodified}', $lm, $ss); >> } >> if (strpos($ss, '{+') !== false) $ss = preg_replace('/\{\+([0-9]+)\}/e', >> 'BOLTinfoVar($q, "$page::$1")', $ss); >> $sortarray[$page] = BOLTdisplayReplace($ss, $p, $outarray); >> } >> if ($s == '{+lastmodified}') arsort($sortarray); >> else natcasesort($sortarray); >> return array_keys($sortarray); >> } >> >> Note, this taps into the displayReplace function so you can get pretty >> much any template variable available there. And {+1} or {+2} tap into the >> infovar function so you can sort on info parts when doing a query. >> >> It's a pretty radical change. Shouldn't disrupt too many existing search >> queries--just adds a lot of new possibilities. Maybe you can help me debug >> a bit and see if I have overlooked anything. If not, we can put this in the >> next release... >> >> Cheers, >> Dan >> >> >> On Thu, Oct 9, 2014 at 1:51 PM, Tiffany Grenier <[email protected]> >> wrote: >> >>> Hi Dan, >>> >>> Thank you for this hint. I've used +p and +title so much that I had >>> forgotten about the +: syntax for data fields. The fi condition now works >>> as expected (and by the way, users are assigning priorities, so a page can >>> have more than one priority, but I just want to now if there is at least >>> one person who gave it priority A, hence the inlist). >>> For the sorting, however, I cannot make it work. Here is another example >>> where I am trying to have a page with users birthdays... I trid to do >>> [(search group=member.* if="set {+:birthdateday} && set {+:birthdatemonth} >>> && set {+:birthdateyear}" >>> sort={+:birthdatemonth},{+:birthdateday},{+:birthdateyear} >>> type=-{zones} fmt="{+:birthdateday}/{+:birthdatemonth} [[{+p}|+]] >>> ({+:birthdateyear})" count=false)] >>> but then the results are: >>> 04/08 Eloise Beranger (1983) >>> 21/12 Lucian Sholva (1993) >>> 14/12 James Faith (1991) >>> 07/07 Wanda Venbi (1997) >>> ... Wanda should come before Eloise and Lucian at the end... >>> >>> I also tried to write sort='{+:birthdatemonth} {+:birthdateday} >>> {+:birthdateyear}' but the result is the same. I can't find anything on >>> Boltwire's website that could solve this issue. Any idea? >>> >>> Thanks in advance, >>> Tiffany >>> >>> >>> Le mercredi 8 octobre 2014 00:19:25 UTC+2, Dan a écrit : >>>> >>>> Tiffany, to retrieve a data variable, you use {:field}. In a template, >>>> it should be {+:field}. In your example {+priority} will return null which >>>> is why the condition fails. >>>> >>>> Data values would need to be stored on each page in the search result >>>> for this to work of course. >>>> >>>> If you had a priority info page, you could store all your priority >>>> values on one page keyed to the page name--and you would use {+::field}. >>>> This speeds up the processing considerably as BoltWire only has to do one >>>> file read. Unless you are using titles or something which requires a file >>>> read anyway. >>>> >>>> I'm curious why you are using inlist. If the priority data value is >>>> something like "A,C,F" and you want to see if 'A' is in the list, your >>>> syntax would be correct. If you wanted to see if the data value was set to >>>> A or C or F, you would use if='equal {+:priority} A'. >>>> >>>> Cheers, >>>> Dan >>>> >>>> >>>> On Tue, Oct 7, 2014 at 1:12 PM, Tiffany Grenier <[email protected]> >>>> wrote: >>>> >>>>> Well, I assigned a priority data field to some pages, and I wanted to >>>>> display only the one with priority A. Somewhere else, I want to show them >>>>> all but sort them per priority. The priority is not part of the page >>>>> hierarchy because I use the hierarchy to reflect something else, like the >>>>> category. >>>>> I tried to do, without success, the following (nothing is returned): >>>>> [(search group={p}.* if='inlist list={+priority} item="A"' count=false >>>>> type=-{zones})] >>>>> I managed to achieve the first part of my result with: >>>>> [(search group={p}.* template=subpageslistA count=false type=-{zones})] >>>>> /* >>>>> [[#subpageslistA]] >>>>> [(template each)][if inlist list={+priority} item="A"]<(breadcrumb >>>>> "{+p}" name=link offset={p0} separator=' >> ')>[if] >>>>> [[#endsubpageslistA]] >>>>> */ >>>>> But the sorting won't work, and I think it processes things similarly >>>>> to the if. >>>>> >>>>> Cheers, >>>>> Tiffany >>>>> >>>>> Le mardi 7 octobre 2014 16:16:22 UTC+2, Dan a écrit : >>>>>> >>>>>> The if parameter works differently in list and search functions, than >>>>>> any other function. In most functions, the value is processed as based on >>>>>> the current page and determines whether or not the process is called. >>>>>> >>>>>> In list and search, the if function is run on each item in the report >>>>>> to determine whether or not it is included in the report. You can use >>>>>> {+field}, {+value}, {+p}, {+p0}, {+title}, etc. Normal vars (like {p} and >>>>>> the rest are processed before the function is ever called and refer to >>>>>> the >>>>>> page you are on. So you can do if='equal {+p2} {p2}' and it will work as >>>>>> expected. >>>>>> >>>>>> In my tests, seems to be working. If something isn't, just let me >>>>>> know--I can look into it a bit more. But as you have already discovered, >>>>>> there's often more than one way to do things in BoltWire. :) >>>>>> >>>>>> Cheers, >>>>>> Dan >>>>>> >>>>>> >>>>>> >>>>>> On Mon, Oct 6, 2014 at 1:04 PM, Tiffany Grenier <[email protected] >>>>>> > wrote: >>>>>> >>>>>>> Perfect :-) >>>>>>> Also, as this may interest someone looking for solutions related to >>>>>>> the pulldown menu, I was trying to do some filtering on the data >>>>>>> variables >>>>>>> of the result, but it seems that they are not replaced in the the if >>>>>>> clause. If I put the if inside the template, however, it works great. >>>>>>> >>>>>>> Cheers, >>>>>>> Tiffany >>>>>>> >>>>>>> Le lundi 6 octobre 2014 14:59:04 UTC+2, Dan a écrit : >>>>>>>> >>>>>>>> I was having a similar problem the other day and finally figured >>>>>>>> out the reason and a workaround. I actually added a couple paragraphs >>>>>>>> to >>>>>>>> the documentation on this issue at >>>>>>>> >>>>>>>> http://www.boltwire.com/index.php?p=docs.handbook.forms.inpu >>>>>>>> t_select >>>>>>>> >>>>>>>> Look for the section on templates. Basically it has to do with the >>>>>>>> order of processing. >>>>>>>> >>>>>>>> This morning I went back and looked at the code to find a better >>>>>>>> solution, and discovered there was something already there--it just >>>>>>>> wasn't >>>>>>>> working right. So I changed lines 326 and 327 in library.php to these >>>>>>>> and >>>>>>>> it now allows fmts to have {+title}: >>>>>>>> >>>>>>>> $out = preg_replace('/\{\+([^:{}+=*]+)\}/e', >>>>>>>> "BOLTvars('$page:$1')", $out); // template replacements $out = >>>>>>>> preg_replace('/\{\+:?([^{}+=*]+)\}/e', "BOLTvars('$page:$1')", >>>>>>>> $out); // nested template replacements >>>>>>>> >>>>>>>> Also a more serious problem. I had commented out line 415 of >>>>>>>> library.php when I was doing some debugging in the last release and >>>>>>>> forgot >>>>>>>> to uncomment it. Please fix that while you are at it, or you will have >>>>>>>> problems on forms where nextpage is not explicitly set. I'm posting an >>>>>>>> emergency patch to 4.17. >>>>>>>> >>>>>>>> Cheers, >>>>>>>> Dan >>>>>>>> >>>>>>>> On Mon, Oct 6, 2014 at 5:01 AM, Tiffany Grenier < >>>>>>>> [email protected]> wrote: >>>>>>>> >>>>>>>>> Hi again :-) >>>>>>>>> >>>>>>>>> This time, I'm trying to create a form where people can select >>>>>>>>> let's say their best friend through a pulldown menu, and I can't make >>>>>>>>> it >>>>>>>>> display the page titles (friend pseudo). >>>>>>>>> I've tried to do the following, without success: [select >>>>>>>>> bestie][(search group=member type=-{zones} fmt='[option "{+p}" >>>>>>>>> "{+title}"]')][select] >>>>>>>>> The following works, but is not what I wanted: [select >>>>>>>>> bestie][(search group=member type=-{zones} fmt='[option "{+p}" >>>>>>>>> "{+page}"]')][select] >>>>>>>>> Could you please tell me what I'm doing wrong? >>>>>>>>> >>>>>>>>> Cheers, >>>>>>>>> Tiffany >>>>>>>>> >>>>>>>>> -- >>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>> Groups "BoltWire" group. >>>>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>>>> send an email to [email protected]. >>>>>>>>> To post to this group, send email to [email protected]. >>>>>>>>> Visit this group at http://groups.google.com/group/boltwire. >>>>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "BoltWire" group. >>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>> send an email to [email protected]. >>>>>>> To post to this group, send email to [email protected]. >>>>>>> Visit this group at http://groups.google.com/group/boltwire. >>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>> >>>>>> >>>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "BoltWire" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To post to this group, send email to [email protected]. >>>>> Visit this group at http://groups.google.com/group/boltwire. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "BoltWire" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/boltwire. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "BoltWire" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/boltwire. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "BoltWire" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/boltwire. For more options, visit https://groups.google.com/d/optout.
