Jump to content

hellomoto

Members
  • Posts

    333
  • Joined

Everything posted by hellomoto

  1. I have a fieldsettab I want to populate with two collapsable fields that are for display not input. One will display data directly from an extra MySQL table (corresponding with PW pages) and the other will list certain PW pages. How do I go about this? I wanted to lay them out using Dynatable, one per each field. Thanks.
  2. I have this installed on PW3 and my supposed pages2pdf link simply loads the page with the get variable specified ={page.id}, not as a PDF. What could be the matter?
  3. Search URL looks like http://localhost/site/en/listings/?make=&hulls=&mobility=&price_min=&price_max=&currency=%24&length_min=&length_max=&sort=-boat_date_list but then next page of results goes http://localhost/site/en/listings/page2
  4. I have this $selector = 'template=boat_vessel, sort=-boat_date_list, limit=3, '; $selected = [ "make" => "", "hulls" => "", "mobility" => "", //"make/model" => "", "year" => "", "price" => "", "length" => "", "location" => "", //"keywords" => "", ]; if($input->get->make) { $selected["make"] = $sanitizer->text($input->get->make); $selector .= "boat_model|boat_manufacturer*=" . $selected["make"]; } if($input->get->hulls) { $p = $pages->get('name=hulls, parent.name=options')->child('name=' . $sanitizer->pageName($input->get->hulls)); if($p->id) { $selector .= "boat_model.mamo_hulls=$p, "; $selected["hulls"] = $p->title; $input->whitelist("hulls", $p->name); } } if($input->get->mobility) { $p = $pages->get('name=mobility, parent.name=options')->child('name=' . $sanitizer->pageName($input->get->mobility)); if($p->id) { $selector .= "boat_model.mamo_mobility=$p, "; $selected["mobility"] = $p->title; $input->whitelist("mobility", $p->name); } } if($input->get->price_min || $input->get->price_max) { $selector .= "boat_price_list>={$input->get->price_min}, boat_price_list<={$input->get->price_max}, "; $selected["price"] = "{$input->get->currency} {$input->get->price_min} - {$input->get->price_max}"; } if($input->get->length_min || $input->get->length_max) { $selector .= "boat_model.mamo_length_ft>={$input->get->length_min}, boat_model.mamo_length_ft<={$input->get->length_max}, "; $selected["length"] = "{$input->get->length_min} - {$input->get->length_max} ft."; } $form = ''; $form .= '<p> <label for="search_make">Manufacturer/Model</label> <input name="make" id="search_make" type="text" value="'.$selected["make"].'"/> </p>'; // manufacturer/model // make $form .= '<p> <label for="search_hulls">Hull Configuration</label> <select name="hulls" id="search_hulls"> <option value=""></option>'; foreach($pages->get('name=hulls, parent.name=options')->children() as $i) { if($selected['hulls'] == $i->title) $select = ' selected'; else $select = ''; $form .= '<option value="'.$i->name.'"'.$select.'>'.$i->title.'</option>'; } $form .= '</select> </p>'; $form .= '<p> <label for="search_mobility">Mobility</label> <select name="mobility" id="search_mobility"> <option value=""></option>'; foreach($pages->get('name=mobility, parent.name=options')->children() as $i) { if($selected['mobility'] == $i->title) $select = ' selected'; else $select = ''; $form .= '<option value="'.$i->name.'"'.$select.'>'.$i->title.'</option>'; } $form .= '</select> </p>'; $form .= '<p> <label>Price</label> <input type="number" name="price_min" id="search_price_min" style="width:80px" placeholder="Minimum" value="'.$input->get->price_min.'"/> <input type="number" name="price_max" id="search_price_max" style="width:80px" placeholder="Maximum" value="'.$input->get->price_max.'"/> <select name="currency" id="search_currency">'; foreach($pages->get('name=currency, parent.name=options')->children() as $i) { $form .= '<option value="'.$i->title.'">'.$i->title.'</option>'; } $form .= '</select> </p>'; $form .= '<p> <label>Length (feet)</label> <input type="number" name="length_min" id="search_length_min" style="width:50px" placeholder="Min." value="'.$input->get->length_min.'"/> <input type="number" name="length_max" id="search_length_max" style="width:50px" placeholder="Max." value="'.$input->get->length_max.'"/> </p>'; $sidebar .= '<form id="boat_search" method="get" action="'.$pages->get("template=listings")->url.'"> <h2>Search Listings</h2>' .$form. '<input type="submit" id="search_submit" value="Search"/> </form>'; // add reset/clear button $sidebar .= '<br>'.implode('<br>', array_filter($selected)); $results = $pages->find($selector); foreach($results as $i) { $content .= '<h3>'.$i->title.'</h3> '; } $content = "<ol>$content</ol>"; $content .= $results->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>", 'itemMarkup' => "<li class='{class}'>{out}</li>", 'linkMarkup' => "<a href='{url}'><span>{out}</span></a>", 'numPageLinks' => 999, )); This produces accurate search results and paginates effectively without searching; but the search results don't paginate. When the search results overflow a single page, and you go to page 2, it just shows the default second page of all the original results, no search filter. How do I paginate the search results?
  5. Huh. I didn't have that originally and it was behaving the same errant way but now it's working without that so thank you!
  6. I have $results = $pages->find('template=boat_vessel, sort=-boat_date_list, start=0, limit=3, '.$selector); $content .= $results->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>", 'itemMarkup' => "<li class='{class}'>{out}</li>", 'linkMarkup' => "<a href='{url}'><span>{out}</span></a>", 'numPageLinks' => 999, )); But I go to /page2 and the same 1st page of results is displayed, and the pagination itself doesn't change, there's no previous link, the page 1 link is still classified as current.
  7. This is true, and is what I have, but it's not working in another custom import script I'm working on currently: function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); # set header keys }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); //echo $parent.' ';//echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; //echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); $p->of(false); foreach($r as $k=>$v) { $v = trim($v); $fieldtype = wire('fields')->get('name='.$k)->type; if($fieldtype = 'FieldtypeImage') { $imgs = explode('|', $v); foreach($imgs as $i) { $p->$k = $i; } } elseif($fieldtype = 'FieldtypeMapMarker') { $p->set($k->address, $v); // $p->$k->address = $v; } else $p->$k = $v; } $p->save(); //echo '<br>'; } } I have tried the way you mention here that's commented out in my code as well, to no avail. Edit: It should be $p->$k->set('address', $v);
  8. Also module isn't working for me in 3.0.42. Upload shows no file (just the field is active but file is a no-show) and if I try pasting CSV in both cases I can go to the next step but no file headers are present to match.
  9. I have an importer function that goes like this so far function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); # set header keys }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); //echo $parent.' ';//echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; //echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); var_dump($r); foreach($r as $k=>$v) { $fieldtype = wire('fields')->get('name='.$k)->type; echo $fieldtype.' '; if($fieldtype->name == 'FieldtypeImage') { $imgs = explode('|', $v); foreach($imgs as $i) { $p->$k = $i; } } elseif($fieldtype->name == 'FieldtypeMapMarker') { echo 'mapmarker'; $p->set($k->address, $v); } else $p->$k = $v; } $p->save(); echo '<br><br>'; } } It reads the field as being a MapMarker but does not input the address data?
  10. I added support for FieldtypeMapMarker (->location) if you want to incorporate into the module master, here
  11. I'm trying to alter some code I used to do something similar (fields for selected template) on another project (here) and so far just this simple direct snippet is not doing anything: public function init() { $this->pages->addHookAfter('render', $this, 'filterModels'); } public function filterModels($event) { $page = $event->arguments('page'); if($page->template != 'boat_vessel') return; $this->message("models filter"); } The module is active... Why no results?
  12. Actually it does, but you have to save the page to get the childpages field options. How can I auto-save the parentpage field on selection change and immediately subsequently auto-refresh the childpage field?
  13. I have a manufacturers page select field and a dependent models one with pages of template `model` which are allowed children of pages with template `manufacturer`. So I have this as the findPagesCode for the models page options field: return $page->manufacturer->children(); However this requires the page be saved in order to display options. This is not ideal. I have a singular autoload module with the following: public function init() { $this->pages->addHookAfter('render', $this, 'filterModels'); } public function filterModels($event) { $page = $event->arguments('page'); if($page->template != 'boat_vessel') return; $this->message("models filter"); } It's doing nothing. I was thinking I could work out something with this example but I would need the above test to be working first anyway... $this->pages->addHookAfter('changed', function(HookEvent $event) { $page = $event->object; $change = $event->arguments(0); if($page->template == 'boat_vessel' && $change == 'manufacturer') { // execute some code } }); But what? How do I refresh the models field? Is there a way to do this in the field settings? I would think in the custom PHP textarea that `return $page->manufacturer->children();` would work but it doesn't.
  14. Sometimes my file uploads get stuck on 100% and do not complete, even if I try with a zipped version. So then I try adding the file to the page files directory and inserting a new record in the field's table. Sometimes this works, sometimes not. When it doesn't, what to do? Is there a way to add the db record via API that'll register in the page? The existence of the record itself should present, I don't understand.
  15. Apparently it comes from line 6 in this file (vessels.csv) <?php namespace ProcessWire; $mmpid = wire('pages')->get('template.name=mamo_makes')->id; importCSV(__DIR__.'/manufacturers.csv', 'mamo_manufacturer', $mmpid); importCSV(__DIR__.'/models.csv', 'mamo_model', 0, $mmpid); importCSV(__DIR__.'/vessels.csv', 'boat_vessel', wire('pages')->get('template.name=boat_index')->id, 0); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); //echo $parent.' ';//echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; //echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; // if MapMarker field set to ADDRESS subfield $p->save(); //echo '<br>'; } } That's odd because this isn't even supposed to be deleting anything, it's imports. How does this happen? This same code was working before, imported the boats just fine, I would just have to refresh the page once to clear that same error, but it would clear itself.
  16. I have a cleanup file running before a file that sets up all the fields and templates, that includes the following: foreach($fields->find('tags*=ccbo') as $f) $fields->delete($f); When I comment it out, the field is created, yet I still get this error halting the script procession: If I comment out the block of code creating it, the same error is displayed for the next field.
  17. mamo_length_ft is not a field. I don't see it anywhere in the database neither. Where could this possibly be stemming from?
  18. Never mind this works the mmpid was 0 had wrong template name. <?php $mmpid = wire('pages')->get('template.name=mamo_makemodel')->id; echo $mmpid.'<br><br>'; // Manufacturers: importCSV(__DIR__.'/manufacturers.csv', 'mamo_manufacturer', $mmpid); // Models: importCSV(__DIR__.'/models.csv', 'mamo_model', 0, $mmpid); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //$parent = wire('pages')->get('title=' . $r['parent']); //echo $parent.' ';// echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); echo $parent.' '; echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; $p->save(); echo '<br>'; } }
  19. I have the following import script being included in the homepage template file: <?php $mmpid = wire('pages')->get('template.name=makes')->id; // Manufacturers: $file = __DIR__.'/manufacturers.csv'; importCSV($file, 'mamo_manufacturer', $mmpid); // Models: $file = __DIR__.'/models.csv'; importCSV($file, 'mamo_model', 0, $mmpid); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //$parent = wire('pages')->get('title=' . $r['parent']); //echo $parent.' ';// echo $r['parent'].' '; echo $grandparent_id.' '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; echo $parent.' '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; $p->save(); echo '<br>'; } } Output = Why is it running the ELSE when the condition for the IF is met? (the first 9 lines) All 14 models (lines past 9) are created under the first manufacturer. I've been messing with it, been able to get them to display the page IDs proper at one point for the models but still there's the standing issue of all of them being created under the first manufacturer nonetheless and also the ELSE running despite not being a condition of ELSE. What's up please...
  20. I have a module that I am using to create an image field like so: $mf[] = [[ 'tags' => $tag, 'name' => $pre.'logo', 'type' => wire('modules')->get('FieldtypeImage'), ],[ 'label' => 'Logo', 'columnWidth' => 50, 'inputfieldClass' => 'InputfieldImage', ]]; Yet upon its creation, initially, when I try creating a page of a template including it, it says that the field must first be configured. Once I go and save the field as-is, everything's honkey dory. It's just an annoyance, with every image field. I figured it would be the required inputfieldClass field field, but as you can see, that's included up in there, and it's still not good to go off the bat.
  21. It's shorthand for creating new fields, templates, fieldgroups, and pages via the API. See bb for example usage.
×
×
  • Create New...