Jump to content

psy

Members
  • Posts

    741
  • Joined

  • Last visited

  • Days Won

    12

Posts posted by psy

  1. Grateful for all your suggestions and you gave me an idea. Didn't get a chance to test today but will try tomorrow. It's a conglomeration of your suggestions.

    1. in _init.php prepended to all pages (or maybe refined to only the pages on which it's needed ?), collect all bookings for the day, regardless of individual item ids and cache it. Historical bookings won't change and without the repeater stuff, will be quick;
    2. instead of going back to the db for all calls, run the individual item queries on the cached page array - at most 20 items

    Will report back ? 

  2. @dragan

    No question you ask is ever dumb! I should have made it clearer.

    Each item is a page, a product page. The qty is an integer field and refers to how many units of that product are owned by the client. The $limit is set to that number.

    The query searches through other bookings for that item on the nominated day, and on each match, subtracts the booking_qty from the item qty, to return how many are left for hire on that date. When all are booked out, the front-end customer cannot add it to their cart to prevent over-booking.

    A count wont do it as other bookings may have booked 2 or more units of the same item on that day.

  3. @BillH Thanks,

    7 hours ago, BillH said:

    Might RockFinder speed things up sufficiently?

    I tried RockFinder3 a while ago. It's certainly a great module however I couldn't figure out how to get it working with Repeater fields. It's perfect with direct relation fields, eg PageReference but Repeaters are different beasts. Not sure if RF3 handles '.' separated fields in the selector, eg "booking_items.booking_item.id" either?

  4. I have a $pages selector that works great in giving me the requested info. However it's incredibly slow. Added to this, the request may be called up to 15 times on a particular page for 15 different listed items.

    <?php
    	// in my custom module...
    	// retrieves qty of items already hired on a particular day to determine availability for new bookings
    	// booking_items is a repeater field and booking_item are repeater pages
    	// I already have the $item and the $eventDate
    	// Query is searching through 5K+ bookings and at least 3x that many booking_item repeater pages
    
            $limit = $item->qty;
            $selector = "template=booking, booking_items.booking_item.id=$item, booking_date=$eventDate, booking_status!=pending|cancelled, limit=$limit";
            $pp = $this->wire()->pages;
            $otherBookings = $pp->find($selector);

    Each item query can take between 2 to 8 seconds ?

    What can I do to speed up this query?

    TIA

    psy

  5. Had an extreme example to deal with recently. Multiple field replacements for various fieldtypes. May not be the best approach but worked for me. Private function is in a custom module function.

    <?php
    
        /**
         * Takes a page field, eg 'body' as a template and replaces tags eg {age} with the same field value
         * from the supplied data page
         * @param $tplPage
         * @param $tplField
         * @param $dataPage
         * @param string $startTag
         * @param string $endTag
         * @param array $other
         * @return string|string[]
         * @throws WireException
         * @throws WirePermissionException
         */
        private function _compileFieldTags ($tplPage, $tplField, $dataPage, $startTag = '{', $endTag = '}', $formatDate = false, $other = []) {
    
            $allowedFieldtypes = [
                'FieldtypeText',
                'FieldtypeTextarea',
                'FieldtypeInteger',
                'FieldtypeFloat',
                'FieldtypeDatetime',
                'FieldtypeToggle',
                'FieldtypeCheckbox',
                'FieldtypePage'
            ];
            $replacementNames = [];
            $replacementValues = [];
    
            // Sort out what to do with each inputfield type
            foreach ($dataPage->fieldgroup as $replacement) {
                if (!in_array($replacement->type, $allowedFieldtypes)) continue;
    
                switch ($replacement->type) {
                    case 'FieldtypeDatetime':
                        $fldData = $formatDate == false ? $dataPage->$replacement : $dataPage->getFormatted($replacement);
                        break;
                    case 'FieldtypePage':
                        $fldData = $dataPage->$replacement->title;
                        break;
                    case 'FieldtypeCheckbox':
                        $fldData = $dataPage->$replacement == true ? "Yes" : "No";
                        break;
                    default:
                        $fldData = $dataPage->$replacement;
                        break;
                }
                $replacementNames[] = $replacement->name;
                $replacementValues[] = $fldData;
            }
            // Prepare replacement arrays
            foreach ($dataPage as $k => $v) {
                $replacementNames[] = $startTag . $k . $endTag;
                $replacementValues[] = $v;
            }
    
            $replacementNames['url'] = $startTag . 'url' . $endTag;
            $replacementValues[] = $dataPage->httpUrl;
    
            $result = str_ireplace($replacementNames, $replacementValues, $tplPage->$tplField);
            return $result;
        }

     

    • Like 2
  6. Trying to upgrade TD to the latest version and I get this:

    Fatal Error: Uncaught WireException: No download URL specified in wire/modules/Process/ProcessModule/ProcessModule.module:1072

    Happens both on the Modules->New and Settings->Upgrades with the upgrade module. I could upload the zip but that's not the issue.

    Reason for upgrade was another error message:

    Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in [no active file]:0
    Stack trace:
    #0 {main}
      thrown in [no active file] on line 0

    which auto-magically began appearing. I'm not serializing any data and the error disappears when I turn off TD.

    Any ideas on what's happening here?

  7. @MoritzLost True, however (unless I missed something), ProDrafts doesn't work for Repeater Matrix whereas my suggestion will work for template development.

    As I understand it, ProDrafts is more for checking/comparing content before committing changes. 

    I guess it's what @Knubbi is trying to do

  8. You could use site/config .php settings, eg:

    <?php
    
    if ($user->hasRole('dev') { // or whatever role you assign 
    // development templates directory
    $config->urls->templates = $config->urls->site . 'templates-dev/';
    $config->paths->templates = $config->paths->site . 'templates-dev/';
    
    $config->urls->fieldTemplates = $config->urls->templates . 'fields/';
    $config->paths->fieldTemplates = $config->paths->templates . 'fields/';
    
    } 
    
    // other users, including the public, will see the default $config->templates & $config->paths (same for fields) 

     

    • Like 1
    • Thanks 1
  9. Some things to check which tripped me up when taking over from a previous developer:

    • In site/config.php ensure that the template url & path are pointing to YOUR templates url & path. The default is 'template' however is customisable
    • In Set Up ->Templates -> [your template] -> Files tab, that your template file name is not being overridden in the Alternate File Name field by something the original dev entered

    HTH

    • Like 1
  10. @AndZyk great work. ?

    Only other feedback I have is that the buttons "What do I see?", "What do I hear" & "How does the hustle & bustle affect me?" don't go anywhere/show anything. My cursor changed from normal arrow to an 'edit' icon, not pointer on hover. Is this supposed to happen?

    I'm using Chrome on an iMac

    • Like 1
  11. Thanks @SIERRA

    Oops! Just re-read my code and noticed a mistake. Should be:

    <?php
    
    if (!empty($input->get->id) { // PW way of accessing $_GET
    	$id = $sanitizer->int($input->get->id); // Clean it up to ensure it's an integer
               
    	$alertspage = $pages->get($id); // You can also do $pages->get("id=$id")
    	if (!$alertspage instance of NullPage) { // ensure the page exists
    		echo $alertspage->title;
    	} else {
    	echo "There was a problem retrieving the page with ID $id";
    	}
    }

    Missed the curly braces surrounding the first and last lines 

  12. 10 hours ago, SIERRA said:

    $alertspage=$pages->get(id); //var_dump($alertspage) is working

    Think the issue may be in this line - no $ in front of id. Try:

    <?php
    
    if (!empty($input->get->id) // PW way of accessing $_GET
    	$id = $sanitizer->int($input->get->id); // Clean it up to ensure it's an integer
               
    $alertspage = $pages->get($id); // You can also do $pages->get("id=$id")
    if (!$alertspage instance of NullPage) { // ensure the page exists
    	echo $alertspage->title;
    } else {
    	echo "There was a problem retrieving the page with ID $id";
    }

     

    • Like 3
  13. @Robin S

    Brilliant! Not quite what I needed but a great starting point. My scenario was:

    • Didn't know the repeater item id
    • Did know the id of a particular (page) field inside the repeater page

    And wanted any repeater item with that field id to be locked for editing by all, including super users. Here's what worked for me:

    <?php
    $wire->addHookAfter('Field::getInputfield', function(HookEvent $event) {
        $page = $event->arguments(0);
        if (!$page instanceof RepeaterPage) return;
        $inputfield = $event->return;
        // Only for a particular Repeater page field (fieldtype page) ID
        if($page->my-page-field->id !== 4486) return;
        // Set collapsed to Inputfield::collapsedNoLocked or Inputfield::collapsedHidden as suits
        $inputfield->collapsed = Inputfield::collapsedNoLocked;
    });

     

    • Like 1
  14. I know that headless cms has been a hot topic for a while. I've experimented with several frontend frameworks (Angular, React, Vue, etc) and I just don't get it. Maybe for huge corporations with multiple dev teams and big budgets, OK. For 95+% of use cases however, I find headless cms/js frontend to be a major pain with no discernible benefits. From a frontend web UX, they're often slower than a well built PW site with caching (eg ProCache).

    For native apps, something like api calls to/from PW/Dart via json would do the job.

    Am I missing something other than a desire for JS devs to earn extra $$$?

    • Like 4
  15. @bernhard Grateful for the offer to help, however on a tight schedule and managed to get the solution to my query using a normal PW selector with the very helpful and hard to find gem "repeater_field.owner.field_name'. It enabled me to get the repeater field, it's originating page and the individual repeater item data.

    The selector returns a WireArray of repeater fields which are then manipulated into a flat array for RockTabulator.

    From what I could see in the SQL statement from RF3, the field table aliases are getting mixed up when both the first and main RF3 queries have the same field name, eg 'title' - some have the unique id twice and then the LEFT JOIN 'title' gets the wrong one which then fails.

     

    • Like 1
×
×
  • Create New...