Jump to content

gebeer

Members
  • Posts

    1,391
  • Joined

  • Last visited

  • Days Won

    39

Community Answers

  1. gebeer's post in Sorting Child Pages by field was marked as the answer   
    Where did you read that?
    The limit selector is specifically designed for $page->find calls so I would not know why it shouldn't work.
    Your best bet is to give it a try and see what happens
    $items = $pages->find("template=item, sort=-created, limit=x"); ...
  2. gebeer's post in Getting field name in the loop was marked as the answer   
    In the field settings for your computer page field, is this field set to hold multiple pages or a single page?

  3. gebeer's post in Get database query for $pages->find() operation was marked as the answer   
    Thank you all for your help on this one.
    @szabesz
    I would rather not like to install Trasy Debugger if there was a simpler method through the API
    @LostKobrakai
    the suggested code returned null. But this version (with parentheses appended to the getQuery method) works:
    wire('pages')->getPageFinder()->find(new Selectors($selector), array('returnQuery' => true))->getQuery(); It returned exactly the query I was looking for
    SQL_CALC_FOUND_ROWS pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_id_gc AS field_id_gc ON field_id_gc.pages_id=pages.id AND (((field_id_gc.data='16800' ) )) JOIN field_timestamp AS field_timestamp ON field_timestamp.pages_id=pages.id AND (((field_timestamp.data>='2016-01-28 15:00:42' ) )) JOIN field_timestamp AS field_timestamp1 ON field_timestamp1.pages_id=pages.id AND (((field_timestamp1.data<='2016-02-16 00:19:53' ) )) LEFT JOIN field_timestamp AS _sort_timestamp ON _sort_timestamp.pages_id=pages.id WHERE (pages.templates_id=44) AND (pages.status<1024) GROUP BY pages.id ORDER BY _sort_timestamp.data LIMIT 0,100 @kongondo
    $queries = $database->getQueryLog(); returns an array of queries with a lot more info than LostKobrakai's code and the specific query is not included. The querie here look somewhat like the output of Debog Mode Tools in backend.
  4. gebeer's post in Full text site search function was marked as the answer   
    Hi,
    you can find some basic search logic in the search.php of the default site profile: https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/templates/search.php
    In https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/templates/_main.php#L61 you find the code for the search form.
    This should get you started.
    EDIT: If you should later decide to use AJAX, there is Soma's module: https://github.com/somatonic/AjaxSearch
  5. gebeer's post in PageArray: has or = was marked as the answer   
    Don't know about performance, but with this code you would set the value of $my_page_array to 1234 which most likely would throw an error.
    For comparison use
    $my_page_array === 1234 If you have the $page object that you are searching for already, you can also pass that directly into the has() method like
    $my_page_array->has($page) instead of $my_page_array->has("id=1234")
  6. gebeer's post in find page by date was marked as the answer   
    You have a $searchdate of format January-2016 and the date that is saved in your page in field date is 12-January-2016?
    PHP doesn't know by default that 12-January-2016 is a day within the month January of year 2016.
    So you need to do some date calculations with PHP.
    Try this to find out if "12-January-2016" lies within January 2016
    // example code // convert the saved date of the page to a timestamp // $date = strtotime($page->date); // I assume the date is saved on the page in field date $date = strtotime("12-January-2016"); // convert the $searchdate to a timestamp $searchdate = strtotime("January-2016") + 1000; // get first and last timestamp of the given month and year $getdate = getdate($searchdate); // get the month number (e.g. 1 for January) $month = $getdate["mon"]; // get the year (e.g. 2016 $year = $getdate["year"]; // get first timestamp of that month in that year $first = mktime(0,0,0,$month,1,$year); // echo date('r', $first); // get last timestamp of that month in that year $last = mktime(23,59,00,$month+1,0,$year); // echo date('r', $last); // now check if $date is in the range between $first and $last function check_in_range($first, $last, $date) { // returns true if $date is in month January of year 2016 - else returns false return (($date >= $first) && ($date <= $last)); } var_dump(check_in_range($first, $last, $date)); // either true or false Now you can use check_in_range($first, $last, $date) in your if - elaseif statements.
    Try the code live here.
    PS: I don't know what it is, I just like to fiddle around with date calculations...
  7. gebeer's post in Frontend form single image field save problem was marked as the answer   
    @Mats
    thank you, but that does not quite apply to my situation.
    But I just found the solution:
    In the single image field settings in Details tab, I needed to switch from
    "Single item (null if empty)"
    to
    "Array of items"
    Now I can use the single image min my frontend form
    Somehow the processInput method can only handle arrays for file fields
  8. gebeer's post in Performance issues with only 2000 pages was marked as the answer   
    Update on performance:
    I copied the install to my local vagrant development box where it is working smoothly. No long page loads and Lister Pro is fast even with 5000 logs.
    So the performance issues are related to the godaddy server - who would have thought that
  9. gebeer's post in Leave page confirmation in page edit form always shows was marked as the answer   
    SOLVED
    This was related to the module FieldtypeFontIconPicker. Author ukyo has just released an update that fixes the problem.
  10. gebeer's post in Events management/modules was marked as the answer   
    I' m not quite sure what you mean by reports.
    I am using Lister Pro to show all the signup pages that were stored for the events. They can then be filtered and sorted by event, by signup date etc. Possibilities are almost endless and depend on your specific scenario. It is definitely worth reading up on what Lister Pro can do. In particular interesting are the lister pro actions. You can export lists to CSV and more. This might sound like I am advertising the module here. And, hell yeah, I do because I find lister pro really useful and well worth the money
  11. gebeer's post in $page->render() for list of child pages in delegate template approach was marked as the answer   
    I need to revisit this thread because the problem has given me a headache agein today.
    It seemed like $page->render($options) cannot be used with the delegate approach where you assign your content to a variable in your template file and _main.php gets included and renders that variable.
    Here my setup to test this behaviour:
    basic_page.php
    <?php $gallery = $page->children()->first(); content = $gallery->render(array("useMain" => false)); $gallery has template gallery.php
    <?php if (isset($options['useMain'])) $useMain = $options['useMain']; $content = "<h2 class='page-header'>{$page->title}</h2> {$page->bodycopy}"; With this setup "$gallery->render(array("useMain" => false));" returns an empty string.
    if I change gallery.php to
    <?php if (isset($options['useMain'])) $useMain = $options['useMain']; // NOTE THE echo instead of $content = echo "<h2 class='page-header'>gbr{$page->title}</h2> {$page->bodycopy}"; Then I get the string that I would expect from  "$gallery->render(array("useMain" => false));" 
    So the culprit seems to be the $page->render($options) method not returning my $content variable from the gallery.php template.
    The solution is dead simple, though. gallery.php:
    <?php if (isset($options['useMain'])) $useMain = $options['useMain']; $content = "<h2 class='page-header'>{$page->title}</h2> {$page->bodycopy}"; if (!$useMain) echo $content;
  12. gebeer's post in Set an image as background for a div with text was marked as the answer   
    In your inline style you are missing the url() part. And the api call to the image is also not correct. Is the image field storing only 1 ore multiple images?
    If it is multiple, you need to do something like
    <div class="thumbnail"> <a href="..."> (Link to my gallery) <div class="flex-item6" style="background-image: url(<?php echo $page->images->first()->url; ?>)"> <span class="overlay">stuff</span> </a> </div>
  13. gebeer's post in Manipulating images array - strange results was marked as the answer   
    Yeah, stupid me
    Forgot that $images will be altered after removing.
    When I do
    $images = $page->images; echo count($images) . " images<br>"; foreach ($images as $img) { echo $img->basename . "<br>"; } $firstimage = $images->eq(0); echo "firstimage<br>"; echo $firstimage->basename . "<br>"; $restimages = $images->remove($firstimage); echo "restimages<br>"; foreach ($restimages as $img) { echo $img->basename . "<br>"; } everything works as expected
  14. gebeer's post in Dependent Selects field type was marked as the answer   
    @Soma
    I am sorry, didn't mean to flood the forum with this. Was just exited about the whole thing and that maybe made me go a bit far...
    Your proposed solution for setup and custom selector to get this working with pages that don't share the same tree is great. Very much appreciated.
    I put something together quickly to have the same functionality in a frontend form with the help of a jQuery plugin.
  15. gebeer's post in 404 error after custom site profile import was marked as the answer   
    SOLVED
    It was a role/permission issue.
    ProcessExportProfile didn't export the permissions correctly for a custom role in my system that got assigned a custom permission.
    After reassigning those, I can finally access the page.
  16. gebeer's post in PWimage plugin insert image in frontend form was marked as the answer   
    Bingo
    My assumption from my previous post was right. The PWimage plugin needs a hidden text input field with the value set to the page id of the page that you want to grab images from.
    I added a hidden input field to my form with
    $imgPageID = $pages->get("template=media, created_users_id=$uID")->id; $field = $modules->get("InputfieldText"); $field->label = " "; $field->attr("id+name","Inputfield_id"); $field->attr("value",$imgPageID); $field->attr("type","hidden"); $adform->append($field); Now I can choose images from the user's images page
    And there is no custom module with hook to ProcessPageEditImageSelect required.
    EDIT: This only works for PW 2.5. For 2.6.x some adjustments are needed. You'll find more info here
  17. gebeer's post in Save date / time in user timezone was marked as the answer   
    I can set the user timezone with date_default_timezone_set.
    It is important to set it before my form gets rendered, submitted and processed, not just before I save values.
    The current time in my date field gets calculated based on the set time zone.
    Example:
    set timezone Europe/Berlin, current date

    set timezone America/New_York, current date

    When PW saves publishing timestamps, I get timestamps for 2014-10-24 03:00
    Europe/Berlin: 1414112400
    America/New_York: 1414134000
    Which is 21600 seconds or 6 hours off. Which is correct.
    So I think I'm on the right track now handling different timezones.
  18. gebeer's post in Check for template name... was marked as the answer   
    try
    $hassidebar = array('home','project','projects','posts','partners'); if (in_array($page->template->name, $hassidebar) { //... } EDIT: adrian was quicker. Either of it should work.
  19. gebeer's post in How do you update a page with all its field via front-end? was marked as the answer   
    Take a look at Soma's gist.
    It loops through all the fields of your page and displays a form.
    Then on Submit of the form it again loops through each field and saves the value.
    It also includes all styles and scripts that you need for your form to work on the frontend.
    This is working great for my frontend form.
    If you need help implementing it, let us know.
  20. gebeer's post in Find most efficient solution for storing multiple values in a field was marked as the answer   
    OK, this is solved now.
    The most efficient and performant method for storing multiple (even thousands) of timestamps with a page definitely is a custom input field type that stores values in an extra table in the DB which makes it really fast.
    Thanks to all who contributed, especially kongondo who was so kind to supply a customized input field Timestamps module derived from the input field events module.
    I can now save about 3000 timestamps for a page within 2 seconds which is really fast compared to other methods that I have tried.
    Also searching through those timestamps is pretty fast, even when it comes to hundreds of pages that need to be searched for a timestamp value.
    PW really is great tool and the detailed help and instructions here in the forum is absolutely awesome. I also learned a lot about PHP and the inner workings of PW during the process.
    Thanks again!
  21. gebeer's post in Page does not get deleted was marked as the answer   
    Thank you Soma, now I got you.
    I moved
    $serverads = $pages->find("template=advertisement, ad_server={$serverId}"); before
    $serverpage->delete() And now everything is working
  22. gebeer's post in Access repeater field values in form processing was marked as the answer   
    Thanks for that link kongondo. It really helped.
    When I do print_r($GLOBALS), I get:
    [_POST] => Array ( [name] => Test [uname] => test1 [regemail] => my@email.net [pass] => [_pass] => [sort_repeater1708] => 0 [publish_repeater1708] => 0 [_disable_repeater1708] => 1708 [servername_repeater1708] => [sort_repeater1709] => 1 [publish_repeater1709] => 0 [_disable_repeater1709] => 1709 [servername_repeater1709] => [sort_repeater1710] => 2 [publish_repeater1710] => 0 [_disable_repeater1710] => 1710 [servername_repeater1710] => [sort_repeater1711] => 3 [publish_repeater1711] => 0 [_disable_repeater1711] => 1711 [servername_repeater1711] => [sort_repeater1712] => 4 [publish_repeater1712] => 0 [_disable_repeater1712] => 1712 [servername_repeater1712] => [_reg_servers_add_items] => 0 [timezone] => Europe/Berlin [submitregistration] => Register Account [TOKEN609710988X1412858909] => VehDxck9zIEvN191SQ5G.1HKmG0EeQG41 ) Now I process $_POST with the function from the linked post.
    $servers = getMultiDimensional($_POST, "servername_repeater"); And get back my array
    Array ( [1798] => A Server [1799] => Another Server [1800] => And one more Server [1801] => [1802] => ) Now I can go on from there and process my values.
  23. gebeer's post in Multiple forms processing on same page was marked as the answer   
    Thanks again. That helped.
    I'm using the API to build my forms. They have different names and ids already.
    When I create the submit button like
    // submit button! $submit = $modules->get("InputfieldSubmit"); $submit->label = " "; $submit->attr("value","Save Changes"); $submit->attr("id+name","submitprofile"); //Notice submitprofile here - that did the trick $submit->attr("class","btn btn-success"); $profileForm->append($submit); and check if data should be processed with
    if ($input->post->submitprofile) { //do processing here } It is working and other form submissions do not interfere anymore
  24. gebeer's post in Show menu item only to users with certain roles was marked as the answer   
    OK, bummer. Blame on me not checking the source and stealing your time. Can I buy you a beer/soda/coffee?
    I'm using same menu code in a different project where no problems with menu rendering appeared so far. Actually I took the code from here.

    Found it: I had commented out a part in the rendering function that prevented displaying pages with children. Slapping myself hard now.
    Credits for solving this go to Soma.
  25. gebeer's post in Unrecognized HTTP host error persistent was marked as the answer   
    The problem happened to be related to old session files that I transferred when moving to the new server.
    Once I deleted all session files in assets/sessions on the new server, PW picks up the $config->httpHosts array and the error message in the backend disappears.
×
×
  • Create New...