Jump to content

Kiwi Chris

Members
  • Posts

    287
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Kiwi Chris

  1. I don't really have anything public to show, as nearly all the work is back-end, but I thought I'd post here anyway as it's a pretty good example of just how powerful Processwire can be. About a year ago, I inherited an incomplete Craft website made by a designer. Apart from the usual company information site, it was supposed to provide a customer portal for clients of a wine bottling company to make bookings for production runs. Data for stock levels of goods like bottles and labels was to come from an inventory management system Unleashed https://www.unleashedsoftware.com/ Unleashed provides a REST API, so I had to integrate with that first by writing an API integration module, and then ended up using Processwire's core lazy cron module to periodically pull data from Unleashed using a custom module. The booking forms have a lot of conditional fields, eg if you are bottling a given wine variety, you should only be able to select labels that match that variety. All this conditional stuff was achieved with a lot of additions to ready.php. I also needed to be able to created a predefined set of pages when a new user is added if they have a 'client' role. Once again, more hooking in ready.php I've used the Admin Restrict Branch module so clients can only see their own records when they're logged in, but staff can see all records. Lister Pro provides the ability to search and view completed production runs. Part way through the project, as the client was happy with the way things were going, I was asked to add in logistics and dispatch which is provided by another company, which also runs Unleashed with a separate set of data, and with some clients who don't bottle wine, but will end up using the same portal, so using the roles and permissions inherent in Processwire, I set up production templates with separate roles to dispatch templates, so I could easily have clients assigned access to just the templates they need. Tracey Debugger got a thorough workout along the way, and the debugger console is an absolute killer tool for making quick changes to data when updating a live site to match changes from the dev site. At the start of this project, I'd used Processwire quite a bit, but never dived into module development or hooking, but I've now ended up with a reasonable idea how they work. @bernhard has produced some excellent tutorials which I found really helpful figuring out how to create modules, and other people like @Robin S have answered questions when I've got stuck. @ryan himself has been helpful when I've been trying to do things that push either the limits of my knowledge or Processwire or both ? . Could I have done this with other tools? Depends. Wordpress would have been as useless as using petrol to fight a fire, however something like ASP.Net COULD have done the job but would have probably made things a lot more complicated. In parallel, I've been working on building a REST API with ASP.Net for another client to integrate with an existing SQL Server database, and I've found that Visual Studio is inclined to break projects quite regularly, with dependencies getting messed up, or even whole configuration files getting corrupted when it has a hissy fit, so working with Processwire is a pleasure in comparison.
  2. LoginRegisterPro sounds great. So I don't go out and duplicate anything, a task I've been thinking for a while of bundling up into a module is the ability on creation of a user with a given role, to create a page and subpages with a predefined template structure. Currently I do this via ready.php and it works fine, but I figured it would be convenient and flexible as a module. (eg. Create login with role "customer", and then automatically create a page with template "customer" and sub-pages "customer-sales", "customer-support-requests", etc.. ) For a tree structure like for example: Customers -Customer 1 -Customer Sales -Customer Support Requests -Customer 2 -Customer Sales -Customer Support Requests ... Using this together with a module like AdminRestrictBranch makes it easy to let customers log in and manage their own content. If LoginRegisterPro won't cover this kind of login creation scenario, and no one else has something similar, I'll go ahead and start building a module.
  3. Sorry, I checked a case outside of a repeater, and you're right. I have dependent selects working, but only after a save. What I had was several page fields outside a repeater that used custom code in ready.php, and a dependent page field inside a repeater, but the containing page was always saved first, so of course the dependent page fields in the repeater worked. Thanks to your help in another thread: I can also get dependent selects working inside a repeater if I save after each field is updated. There doesn't seem to be an option to refresh an individual page field either inside or outside a repeater via an ajax call other than by the selector string option you've mentioned.
  4. @Robin S That seems to partially work, but it seems to have issues if a custom selector returned by a hook in ready.php, rather than a selector configured in the field properties. I'm not sure if there's a way around that?
  5. It's a while since this thread has been updated, so I thought I'd check whether there's been any update on anyone finding a way to make dependent selects work dynamically inside repeaters. I've got dependent selects inside repeaters working ok IF I save each time I make a selection, but that's a bit clunky for an end user. I realise there are issues with the way repeaters generate ids that might make ajax based updates impossible but it would be handy. I originally rejected using pagetables as there are only every going to be a handful of repeater items for each page, and the modal edit method with pagetable fields, rather than inline editing, along with the need to publish each item is not as intuitive as repeaters. A repeater field would be my preference, although I guess I could go back to using pagetables/pagetable extended, but they're not as convenient for end users as a repeater, apart from the issue around dynamic selects.
  6. @Robin SThanks that's what I was looking for. hasPage returns the repeater page. I think I now have the capability to deal with most scenarios for page fields where they have dependencies. I think they still rely on the page being saved, but that's OK for now, although it would be great if I could get them updating via ajax. Inside my hook I now have something like this: if ($event->object->hasField == 'pageBatch') { $inputfield = $event->object; $repeater = $inputfield->hasPage; //Now possible to refer to repeater fields in hook. }
  7. getForPage() doesn't help. if ($event->object->hasField == 'pageBatch') { bd($event->arguments(0), "Trigger Object"); $page = $event->arguments('page'); if ($page instanceof RepeaterPage) { $page = $page->getForPage(); bd($page->dispatchItems, "DispatchItems"); } Here is the segment of of code. the first bd() indicates that $event->arguments(0) is returning the page the repeater field is used on, NOT the page of the current repeater item, even though pageBatch is a field within the repeater. bd() doesn't even get called at the second instance, so even though the field pageBatch is contained within the RepeaterPage, I can't work out how to refer to any of the fields within the repeater.
  8. I have a hook inside ready.php and I'm trying to get one page reference field pageBatch inside the repeater to update based on the value of another page reference field also inside the repeater, but so far haven't been able to get it to work. Is this possible, or is it a limitation of repeaters? Ideally I'd prefer to use a repeater than pagetable, as there will normally only ever be two or three items in the repeater, and the data entry with repeaters is a bit more intuitive for users as they don't have to remember to publish, and the entry is inline, rather than pop-up modals. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { // pageBatch is a page reference field in a repeater if ($event->object->hasField == 'pageBatch') { $page = $event->arguments('page'); //returns the page that the repeater field is in, not the current repeater item $repeater = $page->repeaterField; //Want to be able to get the value of $repeater->pageField (a page reference field in the repeater) //Can refer to a page reference field in the page the repeater is in ok though eg $page->pageField works //but not a page reference field inside the repeater $repeater->pageField } });
  9. I've done some further investigation, and on a site without this module, Lister/Lister Pro will show hidden + unpublished as long as the template itself has access control set. It won't work if only the parent has access control set. Access control must be explicitly set on the template in question, as Lister (Pro) doesn't appear to look at access control inheritance. With AdminRestrictBranch installed, even if a template does have explicit access control, and no other modifications to access control, it does seem that the hidden + unpublished option in Lister/Lister Pro doesn't work, although using the include all hook, or doing the equivalent creating the lister via the API, setting allowIncludeAll property to true, and including include=all in initSelector property of the lister does provides provides the expected results.
  10. Yes, I've now also confirmed on a site that doesn't have this module installed. I'll go back to @ryan and ask him about ListerPro. It has an option to include hidden + unpublished but doesn't actually do anything. Thanks for the workaround. If I get ListerPro working as expected without this module without needing a workaround, I'll recheck again with this module to confirm it has no side effects.
  11. Thanks. This provided the result I needed. I actually added it to a custom module that added the hook, but same result.
  12. @adrian I already have that option configured. In lister I get a message: I know this issue has come up before, and Ryan has asked people to check if they have anything that is hooking permissions. With my site structure I have multiple clients who are restricted to what they can edit via this module, however they all have pages they can edit using common templates, so there will be some pages using a given template a user can edit and others they can't. The template in question in my lister definitely is editable for the user, and published pages for the user show up fine. I think AdminRestrictBranch is the only module I have installed that does hook permissions, so I thought it would be worth checking whether other people are using it and Lister/ListerPro together successfully.
  13. I'm not sure whether it's relating to having this module installed or Lister/ListerPro by @ryan but I seem to be having issues displaying unpublished pages in Lister/ListerPro, and Ryan did mention to check on any other modules that modify permissions. Is anyone else using this with custom Listers or ListerPro? If so, are users able to view their own unpublished pages OK?
  14. Oops! I copied and pasted from the example you gave a few posts back. That will teach me for just copying without trying to understand the code. ? I realise RockFinder and RockGrid are still works in progress, and full documentation is coming. ? Another issue I've struck is I get the following error in the RF2 sandbox: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'bottlingco_pw.field_stockCode' doesn't exist (field is added via $rf->addColumns) If I change the field name to all lower case (stockcode), I get no error, but RockTabulator just shows 'Field not found' in the sandbox RockTabulator. It seems as though RockFinder is not translating a Processwire field name with an uppercase character in it into lowercase for the SQL query.
  15. Commenting out: $grid->setData($rf); Got the grid to display in the sandbox.
  16. I'm getting there... The order of installation turns out to be fairly important: RockMarkup2 then RockTabulator then RockFinder2 I've got them all installed ok, but I'm getting the following error: Call to undefined method stdClass::setData() in RockFinder2 on this line: $grid->setData($rf); Also I get a : 1× PHP Warning: Creating default object from empty value in when I save in the sandbox I'm running PHP 7.2
  17. Thanks. I've already used your tutorial on building custom admin pages and found it really helpful. Rockfinder2 + RockTabulator are new to me, but it looks like they'll do what I want.
  18. I have a site with the following structure: User -Orders -Materials User 2 -Orders -Materials ...etc I'm using AdminRestrictBranch module with custom PHP code, so that users when they log in, can only access their records. return ($user->hasRole('client')) ? '/clients/'.strtolower($user->clientCode): '/'; So far so good... Now I've been asked to add a new component in addition to the orders and materials, 'dispatch', however where this gets complicated, is I've been asked to separate this off and show it as a separate tab at the top (ie where Pages, Setup, Modules, Access etc go). I know everything in Processwire is essentially a page, and Modules and Access have their own links as they are sub-pages of Admin, so I can create a new link up here OK. The problem is with the default setup, you give access to one of these features or you don't. What I need is to be able to do is assign all users with role 'client' access to certain functions, but ONLY let them edit, view and create their own records. I can probably store the dispatch data under the user like I've done with Orders and Materials, but if so, I'll need to hide the page tree and create a separate dashboard so that I can have Orders and Materials under one heading, and Dispatch under another. One option I've seen that I wonder whether might be helpful, is Lister Pro. I don't have the module yet, and I can't tell clearly enough from the module documentation whether it will help me achieve what I need. I definitely don't want people with 'client' role being able to change what pages to show in lists themselves, but I do need them to be able to see their own records, edit them, and add new ones. Will Lister Pro help accomplish what I need, or are there other ways to achieve what I need, and importantly, what's likely to be the most efficient approach?
  19. I've tracked down the issue. Thanks @dragan for the example of how to use d function. it turns out one field in the selector had a leading space in the record that's not being returned, however it doesn't show in the editor. By changing the offending field, saving it, then changing it back, it made it have the correct value. I couldn't just save it, as Processwire didn't consider the field changed, even though it stripped out the leading space before displaying it in the editor. ie I had a text field productType that was supposed to be "FG" but was actually " FG" however editing the page displayed it as "FG". The record was orginally imported from CSV, so I either need to get my import to strip leading spaces, or get the editor to display them.
  20. I have a selector that matches on several fields to provide the records for a page reference field, but is behaving strangely with a couple of records. The two records use the same template and have identical field values for all fields but for the title and another field pageDescription which are not included in the filter. Both pages are visible and published, but only one page is returned, although if I do a search directly for the title of the page the selector does not return, it shows up. Does anyone have any idea why a selector would not return a matching record? Is there any possibility of database corruption (I'm using InnoDB)
  21. What I had to do was create two websites with webfaction, one using HTTP and one using HTTPS Go to Domains/Websites, then Websites In the HTTPS site, just use the standard Processwire .htaccess and make sure you've got the site set to use HTTPS. Create another site, using static/CGI/PHP template will do with the same domain name, but make sure it is using HTTP (not HTTPS) and in that one add the code you posted to the .htaccess file of the HTTP site.
  22. I've checked what $event->argument(0) is returning, and it actually is the page the repeater is used on, even though that page doesn't directly have the field 'bom' as that is only used in the repeater itself, so even though the repeater item is technically a page in its own right, my hook is picking up the page the repeater is on anyway. My filter seems to be working as expected now. I think the issue arose because previously I was using a pagetable instead of a repeater, but the client didn't like the presentation, and found a repeater more intuitive. The client only needs a few items, sometimes only one, so a repeater makes sense. With the pagetable, I did need to refer to the parent, and with the repeater items technically being pages, I assumed I needed to do the equivalent, but it turns out that with repeaters the page they're used on is the page returned by the hook.
  23. I'm trying to apply a custom filter on a page field within a repeater via ready.php like so: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->hasField == 'bom') { $parent = $event->arguments(0)->page->getForPage(); } // Filter criteria ... } The problem is I get "Call to a member function getForPage() on null" on the line: $parent = $event->arguments(0)->page->getForPage(); Any idea what I'm doing wrong?
  24. I have a role that has page edit, view, and clone permissions on a specific template. If a page using the template is locked by a user in a role with lock/unlock permissions on the template , the only button alongside it in the page tree is view, for users who don't have lock/unlock permissions. If however, I also give the role page-lock permission on the template, they then get additional buttons, edit, copy, and unlock. I don't actually want to give this role unlock permissions, but I do want the copy (clone) button to display alongside the page in the page tree. Elsewhere, I've discussed how I've worked out how to create a hook to unlock the copy, but I want to keep the original page so a user without lock permissions can't unlock from the page tree it to make changes. Question: What method should I hook into to intercept any attempt to change the lock status?
  25. /* * Example of how to clone a locked page, remove the lock on the copy, and clear the value of a field in the copy. * Reset stockCode Field when copying a page using a specific template, also remove locked status. * This code is included in the /site/ready.php file. */ $wire->addHookAfter('Pages::cloned', function($event) { /* * Important: The event arguments include both the copied page and the newly created page. * Don't use $event->arguments('page') as this returns the page that is being cloned rather than the cloned copy. * Instead use $event->arguments(1) which correctly refers to the new copy. */ $currentPage = $event->arguments(1); if ($currentPage->template == 'bom') { $currentPage->stockCode = ''; $currentPage->status = $currentPage->status & ~Page::statusLocked; //probably better to use removeStatus(Page::statusLocked) $currentPage->save(array('quiet' => true)); } }); Here's my documented example of how I got this to work.
×
×
  • Create New...