Jump to content

BillH

Members
  • Posts

    221
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by BillH

  1. I'd suggest you use the core Lazy Cron module to trigger loading the JSON. Note that, as described on https://processwire.com/docs/more/lazy-cron/, Lazy Cron hooks into ProcessPageView::finished() to avoid slow page loads.
  2. My guess would be that it's the line getting a value for $event where things start to go wrong. I'm wondering in particular where you're getting the value of $id from, and whether it's valid? You might want to try var_dump() to check whether $event actually is an object (and if so, if it looks as if it might be a repeater item): var_dump($event);
  3. Using findRaw() you get a normal PHP array (not a PW page array). And the value for select_countries is itself an array. So you can do this: foreach($items as $item) { foreach($item['select_countries'] as $country) { echo $country['title']; } } I'm not sure what findRaw() returns if your page selector field is set to a single page, but you may need to simply use $item['select_countries']['title'] rather than the inner foreach.
  4. It seems that, as @kongondo notes, there's an issue with the findRaw() syntax, at least with the array-type syntax and page-reference fields. However, the dot syntax seems to work. So I think the following will give you what you need: $items = $pages->findRaw("template=template-news, select_region=austria, limit=2, objects=1", ["select_countries.id", "select_countries.title"]); Or slightly simpler, as the keys of the returned array of page references are the page ids: $items = $pages->findRaw("template=template-news, select_region=austria, limit=2, objects=1", ["select_countries.title"]); I've submitted an issue regarding the other syntax: https://github.com/processwire/processwire-issues/issues/1563
  5. If a find() is too slow, use findMany() with a suitable selector: https://processwire.com/api/ref/pages/find-many/. Or if that's still too slow, or if you find them preferable for some other reason, use findJoin() or findRaw(), as described in the blog post at https://processwire.com/blog/posts/find-faster-and-more-efficiently/. Another option would be to try RockFinder3: https://processwire.com/modules/rock-finder3/.
  6. If you want to do something if the page has not yet been created: if(!$page->id) { // Do something here }
  7. I haven't tried, but you may be able to do it by hooking on ProcessPageList::find, as discussed here: Note that the pages would have to be loaded and the sort codes calculated each time the page tree was displayed, so I think the approach I have suggested would be more efficient – something that is discussed in the thread too.
  8. The way I've done things like this is to create a text field, use a hook to add a sort code to that field, then set each relevant parent template to sort its children using that field. The sort code would be whatever you'd normally sort by, but with a prefix that depends on whether the page has children or not. So, I'd use something like the following (not tested) in ready.php, here assuming you'd basically sort on title: $this->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments[0]; if(in_array($page->template, array('template1', 'template2', 'template3'))) { $page->of(false); if($page->numChildren() > 0) { $sortcode = "A-" . $page->title; ) else { $sortcode = "B-" . $page->title; } $page->set('sortcode', $sortcode); } }); Of course, you could use a hook in a module instead. And you can use the same basic technique to get just about any kind of sort order you want.
  9. Perhaps the easiest thing to do would be to make the fields of the user-facing form required, perhaps using JavaScript, or adding the required attribute: <input type="text" id="role" name="role" required> If you want to hook into the module, take a look at https://github.com/ryancramerdesign/LoginRegister. If all else fails, hooking before Inputfield::render (see the example on the page just mentioned) and then replacing strings in the form HTML is an option.
  10. Yes, I noticed that too in the post https://processwire.com/talk/topic/26947-craft-cms-and-processwire-– a-comparison/?do=findComment&comment=222902 (I assume this is the one you mean), although the exact statement is "borderline deprecated". I too was going to comment because language alternate fields are really useful and I make good use them. It's not just image fields, but other non-text field types. For example, there might be a checkbox that can take values specific to each language, or a localized URL for each language, or different attached files (e.g. PDFs in each language). In general, language-alternative fields become really valuable when producing different versions of output for each language, rather than simply having translations of text. Another purpose for which language-alternate fields can be better, even for text fields, is when building interfaces and outputs for translators - for example, if in the admin one needs to display versions of text in different languages side by side, or grouped in fieldsets by language. So from me it's a big vote for keeping language-alternative fields undeprecated!
  11. It occurs to me that with SQL you could write a user-defined function for comparing sets of tags, but this still might run into problems with execution time. I suspect @Robin S's idea is a much better approach!
  12. I could be wrong, but I don't think findRaw(), RockFinder or SQL have any way of returning a result that depends on how many items records have in common. And anyway, to make comparisons between every pair among 20k projects, you'd be looking about 400 million comparisons – which is going to take a while! So, it seems to me that either: you need to think of an algorithm that doesn't involve comparing each project with every other; or you'll need to use a different metric of similarity between projects – or even rank by something other than similarity. Considering the algorithm, I'm wondering if there's an approach that would run in a time dependent on projects * tags (rather than projects * projects), though I don't know if this is possible - and I suspect it'd be really difficult to come up with something. Using a different way of ranking the projects might be much easier, and perhaps equally meaningful - indeed, now that I think about it, I wonder how useful ranking by degree of similarity would be. An alternative, just for example, might be something like ranking the tags by popularity (number of projects they appear in), then give each project a score depending on the ranks of its tags (the mean, or median, or sum of the top three, or something like that).
  13. An interesting problem, but I'm fairly sure there's no solution using PW selectors. As far as I can see you'd need to compare the tags for each project to those every other project, keep track of the results, and then sort by those results. You could get the data you need into an array quickly by using something like: $tagsForAllProjects = $pages->findRaw("template=project", "tags"); However, as you've probably realised, if you have many projects, it could take a long time to work though making the comparisons. Even though you only need to compare each pair of array items once (perhaps using array_intersect()), if I've got this right (which I might not have done!) it'd take n(n-1)/2 operations – so for 100 projects about 50,000 and for 1,000 the best part of half a million. But perhaps someone knows a better way.
  14. Some of your questions will be answered by reading through the articles listed at https://processwire.com/docs/modules/, particularly the first three. Also really helpful are the Hello World example modules described in the blog post https://processwire.com/blog/posts/pw-3.0.181-hello/. And another excellent post is https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/. These will probably give you enough to start building useful modules. And I'd suggest that building a module or two (especially by following examples) would be the best way to get started, working things out as needed.
  15. PDFObject is useful for making the most of browsers' PDF capabilities and for setting up fallbacks – particularly for mobile browsers.
  16. If I understand you correctly, in your final HTML you are getting something like this: <p style="color: white;"> <p> Your text goes here. </p> </p> If what you need is simply to remove the first and last <p> tags from $ber_MDL_riposta, you can use: preg_replace('^<p.*?>|<\/p>$', '', $ber_MDL_risposta) But if it seems tags are being inserted, do you have a TextFormatter applied to the field (Details tab)? When you switched to a textarea field (without CKEditor), did you check that the data in the field does not include tags? Have you used "Page Source" or "View Source" (or similar) to check the HTML?
  17. A ProFields Table field sets up its own database table, so I don't think you'd have any performance issues at all, even with large numbers of columns and rows. But I'm not sure what the UX would be like with very many columns, perhaps most of them empty. I don't know if it'd be possible in your circumstances, but might it reduce the number of empty columns to have various types of product, and a different table field for each type (with subsets of columns), hiding/showing the fields depending on the type selected? Meanwhile, you might find this discussion useful:
  18. Hi Peter, and welcome to the forums! If you want to get the database name, you can use: $databaseName = $config->dbName; Or you could look for $config->dbName in the site's config.php file. To see the database structure, you could use a tool such as phpMyAdmin or Adminer, or install the Tracy Debugger for ProcessWire module (https://adrianbj.github.io/TracyDebugger/#/) which is highly recommended and, among many other things, adds an Adminer page to the Setup menu. However, I note that in a typical ProcessWire installation, you don't need to use SQL queries at all, and they're probably not the best way of going about things. Generally, using PW selectors will do everything you need, and will be much more straightforward: https://processwire.com/docs/selectors/. They're one of the really nice features of PW! Let us know if you need more pointers or suggestions.
  19. This increasingly sounds to me like a cache issue – perhaps some cache on the server, or maybe browser caches aren't clearing as expected. To help find out if caching is the issue, I'd suggest renaming the include file to see if that makes a difference. If it doesn't, try (temporarily) putting the code from the include file into the main file.
  20. Just a thought, but might you have been logged in as different users with different roles/permissions in each browser, and the template have particular access set up?
  21. You have two issues to deal with: Giving users access to their pages, showing them the relevant links, menus choices, etc (and not any others). Preventing users from accessing pages if they happen to find out or guess the URL of those pages. For the first of these, you don't need either of the modules you mention. You present only links to the correct pages (and no other links), and you could achieve this using something along the lines described in my previous post. For the second, you could perhaps use one of the modules, but you could also write your own code at the top of each template, maybe something like this: // Assuming the root page for each user has the template "user-root", // it's below the home page, and is name with the user's name if($page->parent("template=user-root")->name != $user->name) { if($user->name == "guest") { $session->redirect("/"); } else { $session->redirect("/$user->name"); } } Let me know if you need more explanation or examples.
  22. Have you read the page https://processwire.com/docs/multi-language-support/multi-language-fields/ and particularly the section "Multi-language field values"? I think it'll tell you what you need, and the example code is really helpful.
  23. This might be the link that @kongondo is thinking of: https://processwire.com/blog/posts/processwire-3.0.71-adds-new-core-module/
  24. I'd suggest that there are very much easier ways to go about things than using multiple databases. I can think of various possible approaches, but I might go about it something like this... You might have a set up like this, with the user pages below the home page having the users' names (to keep things simple for this example): home |____user1 | |____page1 | |____page2 | |____user2 |____page1 |____page2 To work with the pages for the current user, you could get the pages thus: // Get the user name $userName = $user->name; // e.g. 'user2' // Get all pages belonging to the user $userPages = $pages->find("has_parent=/$userName"); // Get page2 belonging to the user $userPage2 = $userPages->get("name=page2") An important thing to note is that in the above example $userPages is a PW PageArray (https://processwire.com/api/ref/page-array/), and you can work with this instead of with $pages (i.e. all pages). To deal with a superuser, you might do something like this: if($user->isSuperuser()) { $workingPages = $pages; // All pages } else { $userName = $user->name; $workingPages = $pages->find("has_parent=/$userName"); // As in the previous example } I've kept things simple here to illustrate the idea, but I imagine your set-up would be a lot more complex. But I hope this helps as a starting point.
  25. As far as I know, your text_article custom field should work without problems (so long as it's not a CKEditor field, which won't work as a custom image field). The only thing I can think of right now is checking that you haven't got a maximum length set on the field (Input tab). If you need text formatting in your articles (which seems likely with long text) and don't want to use Markdown, you'll need to use some other approach anyway. If there will always be just single images on your page, you could simply add a field to the page. But if there could be more than one image, you could use a Page Reference custom field and store each article in a separate page.
×
×
  • Create New...