Jump to content

hellomoto

Members
  • Posts

    333
  • Joined

Posts posted by hellomoto

  1. 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?

  2. 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?

  3. 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. 

  4. On 7/23/2015 at 4:26 PM, theoretic said:

    Reading docs may really help sometimes...

    Quote from the @hellomoto's code:

    elseif($field->type instanceof FieldtypeMapMarker) {
     
    $value = trim($value);
    $page->set($name->address, $value);
     
    }

    And now some code from Map Marker docs ( https://processwire.com/talk/topic/9711-map-marker-map/ ):

    $page->marker->address = 'Disney Land';

    Now it's obvious that Hellomoto's code should be like this:

    elseif($field->type instanceof FieldtypeMapMarker) {
     
    $value = trim($value);
    $page->$name->address = $value;
     
    }

    Tried this, works like a charm. Lat and Lng subfields are generated automagically if the address is more or less correct.

    Thanks @Hellomoto for a great mod! @Ryan, maybe it's time to add this to Your original module?

    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);

  5. 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?

  6. 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?

  7. 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. 

  8. 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.

  9. 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.

  10. 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:

    Quote

    Error: Exception: Field may not be named 'mamo_length_ft' because it is already used by another field (in /Applications/AMPPS/www/CC/wire/core/Field.php line 540)

    #0 /Applications/AMPPS/www/CC/wire/core/Field.php(227): ProcessWire\Field->setName('mamo_length_ft')
    #1 /Applications/AMPPS/www/CC/wire/core/WireData.php(141): ProcessWire\Field->set('name', 'mamo_length_ft')
    #2 /Applications/AMPPS/www/CC/site/modules/ImportShorthand.module(31): ProcessWire\WireData->__set('name', 'mamo_length_ft')
    #3 /Applications/AMPPS/www/CC/site/setup/1_makes.inc(253): ProcessWire\ImportShorthand::newField(Array)
    #4 /Applications/AMPPS/www/CC/site/setup/1_makes.inc(274): ProcessWire\makeModel()
    #5 /Applications/AMPPS/www/CC/site/setup/setup.php(6): include('/Applications/A...')
    #6 /Applications/AMPPS/www/CC/site/templates/home.php(5): include('/Applications/A...')
    #7 /Applications/AMPPS/www/CC/wire/core/TemplateFile.php(268): require('/Applications/A...')
    #8 [internal function]: ProcessWire\TemplateFile-

    If I comment out the block of code creating it, the same error is displayed for the next field.

  11. Quote

    Error: Exception: Unable to delete from 'field_mamo_length_ft' for field that doesn't exist in fields table (in /Applications/AMPPS/www/CC/wire/core/Fieldtype.php line 1133)

    #0 [internal function]: ProcessWire\Fieldtype->___deletePageField(Object(ProcessWire\Page), Object(ProcessWire\Field))
    #1 /Applications/AMPPS/www/CC/wire/core/Wire.php(374): call_user_func_array(Array, Array)
    #2 /Applications/AMPPS/www/CC/wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___deletePageFi...', Array)
    #3 /Applications/AMPPS/www/CC/wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\FieldtypeInteger), 'deletePageField', Array)
    #4 /Applications/AMPPS/www/CC/wire/core/PagesEditor.php(1011): ProcessWire\Wire->__call('deletePageField', Array)
    #5 /Applications/AMPPS/www/CC/wire/core/PagesEditor.php(1011): ProcessWire\FieldtypeInteger->deletePageField(Object(ProcessWire\Page), Object(ProcessWire\Field))
    #6 /Applications/AMPPS/www/CC/wire/core/Pages.php(490): ProcessWire\PagesEditor->delete(Object(Proces

    mamo_length_ft is not a field. I don't see it anywhere in the database neither. Where could this possibly be stemming from?

  12. 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>';
      }
    }

     

  13. 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 =

    Quote

    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    gp 0p 
    Gemini Catamarans 0gp 0p 
    Gemini Catamarans 0gp 0p 
    Gemini Catamarans 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Lagoon 0gp 0p 
    Robertson & Caine 0gp 0p 
    Robertson & Caine 0gp 0p 
    Robertson & Caine 0gp 0p 

    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...

  14. 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.

×
×
  • Create New...