Jump to content

jds43

Members
  • Posts

    96
  • Joined

  • Last visited

Everything posted by jds43

  1. I prefer your approach @netcarver It appears to be working quite well. Thank you for that option.
  2. Comparing the array_keys wasn't working, so I changed to the following. Seems to be working. // Generate associative array of repeater items by title $usgs_repeater = $usgs_data->explode('title'); // Flip keys and values $usgs_repeater = array_flip($usgs_repeater); // Returns an associative array containing all the entries which have keys that are present in all arguments $usgs_count = array_intersect_key($usgs_repeater, $sessions); // Count the entries $usgs_count = count($usgs_count); if($usgs_count !== count($usgs_repeater)) { // Do the thing }
  3. Thanks @netcarver I tried a variety of approaches from array_intersect to array_diff. I think the following has worked. Not really sure how to confirm aside from clearing session data, but I'm not seeing any errors in Tracy. if(array_keys($usgs_repeater) === array_keys($sessions))
  4. Hello, I need to run a script when specific sessions aren't active, but my code doesn't seem to be working. Are there any glaring errors // Generate associative array of repeater items by title $usgs_repeater = $usgs_data->explode('title'); // Get all session variables in an associative array $sessions = $session->getAll(); // Check if titles of USGS Repeater items are active sessions to execute WireHttp for location data if(!in_array($usgs_repeater, $sessions)) { // Do the thing here } Or should I check the array like this: if(in_array($usgs_repeater, $sessions)) { return; } else { // Do the thing here }
  5. ? looks like that did the trick! Thanks @Ivan Gretsky!
  6. Thanks @Ivan Gretsky So, how would I set that value when I keep getting /events/page2 instead of /events/page2/?publish_until=2020-12-31 when I select the next paginated page for date filtered results?
  7. Hello, I'm trying to paginate results that may have Url Segments and I want to modify the Base Url. How do I accomplish this within renderPager? I found docs here: https://processwire.com/api/ref/markup-pager-nav/render/, but it hasn't pointed me in the right direction. $pager->setBaseUrl(string $url); echo "<div id='pagination' class='uk-container uk-container-medium uk-margin-large-top'>"; echo $matches->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'currrentItemClass' => "uk-active", 'listMarkup' => "<ul class='row uk-flex-right'>{out}</ul>", 'itemMarkup' => "<li class='{class}'>{out}</li>", 'linkMarkup' => "<a href='{url}' class='uk-button uk-background-secondary'><span class=''>{out}</span></a>", )); echo "</div>"; Or, does anyone know of a better option?
  8. Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages. Things to Do (would only display three, six, seven, nine in select) -thing one (-category three, -category nine) -thing two (-category six, -category seven) Lodging (would only display one, two, three, four in select) -lodging one (-category one, -category two) -lodging two (-category three, -category four) Dining (would only display five, six, seven, eight in select) -dining one (-category five, -category six) -dining two (-category seven, -category eight) Categories(hidden page) -category one -category two -category there -category four -category five -category six -category seven -category eight -category nine -category ten $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this. https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references
  9. Okay, I'm also using the code below that comes after the foreach: // did we find any matches? if(count($input->get)) { // Find pages that match the selector $results = $pages->find($selector); if(count($results) > 0) { $message .= "<h3 class='uk-h5'>There are <strong>".count($results)."</strong> House Plans</h3>"; } else { $message .= "<h3 class='uk-h5'>Sorry, no results</h3>"; } } else { $results = $page->children(); } I tried checking the three parameters in a conditional like: if($input->get('beds') == 0 || ($input->get('bathrooms') == 0 || ($input->get('size') == 0 || ). But couldn't really make it work. I ended up modifying the code above to: // did we find any matches? if(count($input->get)) { // Find pages that match the selector $results = $pages->find($selector); if(count($results) === 0) { $results = $pages->find('template=house-plan'); } } else { $results = $page->children(); } echo "<h3 class='uk-h5'>There are <strong>".count($results)."</strong> House Plans</h3>"; So, the result is a query string (/?beds=0&bathrooms=0&size=0&submit=1) with all select options set to 'Any' directly after a search has been performed. I suppose this is acceptable, but wish I could remove it. Thank you @dragan for the help.
  10. Thanks @dragan 'Any' has no value at this point. I just need it as a default selection that would allow all to display. <form class="uk-form uk-padding-large" method="get" action="<?= $page->url; ?>"> <h4 class="uk-h3">Filter Results:</h4> <a class='uk-text-uppercase' href='<?= $page->url; ?>'>Reset Filter</a> <div class="uk-grid uk-grid-small uk-flex-bottom uk-margin-top uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-4@m"> <div class=""> <label class="uk-form-label" for="search-bedrooms">Bedrooms</label> <div class="uk-form-controls"> <select id="search-bedrooms" name="beds" class="uk-select uk-form-width-large" tabindex="1"> <option value="">Any</option> <?php // generate a range of bedrooms, checking our whitelist to see if any are already selected foreach(array('2', '3', '4') as $range) { $selected = $range == $input->beds ? " selected='selected'" : ''; echo "<option$selected value='$range'>$range</option>"; } ?> </select> </div> </div> <div class=""> <label class="uk-form-label" for="search-baths">Bathrooms</label> <div class="uk-form-controls"> <select id="search-baths" name="bathrooms" class="uk-select uk-form-width-large" tabindex="2"> <option value="">Any</option> <?php // generate a range of bathrooms, checking our whitelist to see if any are already selected foreach(array('1.5', '2.0', '2.5', '3.0') as $amount) { $selected = $amount == $input->bathrooms ? " selected='selected'" : ''; echo "<option$selected value='$amount'>$amount</option>"; } ?> </select> </div> </div> <div class=""> <label class="uk-form-label" for="search-size">Square Footage</label> <div class="uk-form-controls"> <select id="search-size" name="size" class="uk-select uk-form-width-large" tabindex="3"> <option value="">Any</option> <?php // generate a range of sq ft, checking our whitelist to see if any are already selected foreach(array('1,000-1,250', '1,251-1,500', '1,501-1,750', '1,751-2,000', '2,000+') as $range) { $selected = str_replace(',', '', $range) == str_replace(',', '', $input->size) ? " selected='selected'" : ''; echo "<option$selected value='".str_replace(',', '', $range)."'>$range</option>"; } ?> </select> </div> </div> <div id="view-sibling" class="uk-visible@s"> <?php $not_this = $page->siblings("limit=1", false); foreach($not_this as $not) { echo "<a href='$not->url' class='uk-button grey-button uk-width-expand'>View $not->title Collection&nbsp;<i class='fa fa-chevron-right'></i></a>"; } ?> </div> </div> <div class="uk-grid uk-grid-small uk-flex-bottom uk-margin-top uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-4@m"> <div class=""> <button type="submit" id="search-submit" class="uk-button gold-button uk-width-expand" name="submit" tabindex="4">Search</button> </div> </div> </form> foreach(array('beds', 'bathrooms', 'size') as $key) { if(!$value = $input->get($key)) continue; // see if the value is given as a range (i.e. two numbers separated by a dash) if(strpos($value, '-') !== false) { list($min, $max) = explode('-', $value); $min = (int) $min; $max = (int) $max; $selector .= "$key>=$min, $key<=$max, "; //$summary[$key] = (substr($max, 0, 3) == '999') ? "$min and above" : "$min to $max"; $input->whitelist($key, "$min-$max"); // see if the value is given as a float (i.e. decimal, this is specific to bathrooms) } else if(strpos($value, '.') !== false) { $value = $sanitizer->selectorValue($input->get->bathrooms); $selector .= "bathrooms%=$value, "; $input->whitelist($selector, $value); // see if the value ends with a +, which we used to indicate 'greater than or equal to' } else if(substr($value, -1) == '+') { $value = (int) $value; $selector .= "$key>=$value, "; //$summary[$key] = "$value and above"; $input->whitelist($key, "$value+"); } else { $value = (int) $value; $selector .= "$key=$value, "; //$summary[$key] = $value; $input->whitelist($key, $value); } }
  11. Hello, I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results. I hope this isn't too vague.
  12. Thank you @Robin S Allow me to look further at this.
  13. Here's what I have so far, but I'm getting inconsistent results. // Sanitize user input $zipcode = (int) $input->get->zipcode; // Set url for API with sanitized zipcode $link = "https://webapi.test.com/WebAPI/api/v1/test/" . $zipcode; function url_get_contents ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('APIKey:************')); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close($ch); return $output; } $jsondata = url_get_contents($link); $location = json_decode($jsondata, true); // Set value of the Nearest Location ID (returned via API based on zipcode input) to session variable named "nearest" $session->nearest = $location['NearestLocationID']; $nearest = $session->nearest; // Let's match the zipcode entered by the user to nearest_location_id field to return the appropriate page $nearest_page = $pages->get('nearest_location_id=[session.nearest]'); echo "<hr>"; if(isset($nearest)) { echo "<h1>$nearest</h1>"; echo "<h2>".$nearest_page->title."</h2>"; } else { echo "<h2>None Selected</h2>"; }
  14. Thanks @Robin S I've been trying to cobble resources together to make this work. Just not quite sure of how to convert the json data to a session variable yet.
  15. Hello, I need to find a way to store a json value returned via REST API and use as a session variable, or something of the like. The user is to input their zip code to provide the closest store location, which is an ID that is returned by a get request (this ID is associated with a page). So this closest store location would now be selected to provide unique information to the user.
  16. Hello, Does anyone have experience with migrating content from Django to Processwire? Or are there any suggestions for achieving this?
  17. $main = $promoted->next(); echo "<h5>$main->title</h5>"; This is more concise ??
  18. $main = ""; $promoted = ""; $promoted = $homepage->promote; $main = $pages->find('template=main')->remove($promoted); foreach($main as $ma) { echo "<h5>$ma->title</h5>"; } This appears to have worked ??
  19. Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site. Does anyone know how I could accomplish this? Would I use something like remove() or not()?
  20. This is good to know, but I'm not getting anything from the selector.
  21. I had to keep parent=1018 because I don't want to include staff-pages that aren't doctors. The $page selector below is drawing errors. $doctors = $pages->find('template=staff-page,locations=$page') This is working though. foreach($doctors as $doc) { foreach($doc->locations as $loc) { if($loc->title == $page->title) { echo "<h4>$doc->title</h4>"; echo "<h5>$loc->title</h5>"; } } }
×
×
  • Create New...