Jump to content

Torsten Baldes

  • Content Count

  • Joined

  • Last visited

Community Reputation

48 Excellent

About Torsten Baldes

  • Rank
    Sr. Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

10,990 profile views
  1. The sorting of these queries is not really important. The important thing for me is, that the results from $find1 are in front of $find2. It's like a lazy weighted search, where I first search the titles of the pages for a keyword/phrase ($find1) and then search the other fields (body etc.) for the same keyword (excluding the ids from $find1). The logic here is, that pages, which have the keyword in their title, are more relevant/important than the other results and should come first.
  2. @dragan @bernhard Yes adding works to get a "unified" PageArray with the right order, but the pagination for this remains empty. $unifiedMatches = $find1->add($find2)->find("limit=$limit"); $unifiedMatches->renderPager() returns nothing.
  3. Thanks, but I'm afraid this doesn't work with pagination. At first I created a new wirearray and added the others. This worked regarding maintaining the order, but got me problems with the pagination. Your approach would possibly work too, but I would have the same pagination trouble. 😕
  4. Hi, I have multiple $pages->find() operations which result in multiple page ids. e.g.: $find1: 8044|10045|3702|11067 $find2: 2004|5421|9392 Next i'm searching these ids to get a new WireArray, which i can limit and paginate: $unifiedMatches = $pages->find("id=$find1|$find2, limit=$limit"); This works all as intended. The problem is, that this new collection of pages doesn't maintain the order of the ids in the selector. They are sorted by their id. $unifiedMatches: 2004|3702|5421|8044|9392|10045|11067 Is there a way to get the pages in the $unifiedMatches result in the order of the selector input? $unifiedMatches: 8044|10045|3702|11067|2004|5421|9392 Thanks!
  5. Thanks for your help! For now I ended up with something like this: wire('user')->setTrackChanges(Wire::trackChangesOn | Wire::trackChangesValues); wire()->addHookAfter("Pages::saved", null, function($event){ $user = $event->arguments(0); if($user->template->name == 'user'){ $userfields = $user->template->fieldgroup; $excludeFields = ['pass', 'roles', 'language', 'admin_theme', 'schedulerSkip', 'cpf_added']; $changes = $event->arguments(1); // check if there are any changes, if it's not an InputfieldFileAjax (also triggers the hook), the user changed his own profile, if the changed user is not a superuser (could be any other role to exclude) if(count($changes) && !wire('input')->get->InputfieldFileAjax && wire('user')->id == $user->id && !$user->hasRole('superuser')){ $userfieldsArray = array(); foreach($userfields as $userfield){ $userfieldsArray[] = $userfield->name; } //remove unwanted fields $changes = array_diff($changes, $excludeFields); // order changed fields like template $changesSorted = array(); foreach ($userfieldsArray as $item) { if(in_array($item, $changes)){ $changesSorted[] = $changes[$item]; } } $changes = $changesSorted; unset($changesSorted); // probably not necessary // get the changes in a string $changedFields = ''; foreach($changes as $change){ $changedFields .= $userfields->get($change)->label . "\r\n"; } // compose the mail $subject = "Änderung im Nutzerprofil von »".$user->u_fullname."«"; $message = "Hallo,\r\n\r\n das Nutzerprofil von ".$user->u_fullname." wurde aktualisiert.\r\nFolgende Felder haben sich geändert:\r\n\r\n" ; $message .= $changedFields; $message .= "\r\n\r\n" ; $message .= "Klicken Sie hier, um das Profil zu bearbeiten: ".trim(wire('urls')->httpRoot, '/').$user->editUrl ; $message .= "\r\n\r\n\r\n"; $mailmessage = wire('mail')->new(); $mailmessage->to('mail@domain.tld')->from($user->email); $mailmessage->subject($subject)->body($message); $sent = $mailmessage->send(); } } }); I decided that it's not necessary to send the before and after values within the email. This could even be a privacy and/or security issue. Thanks again for your ideas and help!
  6. Hi, I'm building a site with user profiles, where the users can change and update their profile. For different reasons it's important that the person who oversees these users get's an email, when a user updates his profile. At best with all the values that changed and their value before. I tried to hook into User::changed and this kind of works, but it get's triggered for every field, that's changed. With each trigger the list of fields also get's longer, so that only the last run contains all the changed fields. This would mean, i would send multiple emails for one profile change. Is there a way to prevent this and get all changes at once in only one hook run? This is my code so far (in ready.php): wire('user')->setTrackChanges(Wire::trackChangesOn | Wire::trackChangesValues); wire()->addHookAfter("User::changed", null, function($event){ $user = $event->object; $changes = $user->getChanges(true); // output changes as log entry wire('log')->save('testchangelog', print_r($changes, true) ); // TODO: send mail }); Thanks!
  7. Most of the time other users/editors use this Field to "generate" a selection of posts/pages which are applicable for the topic of the current post. Something like "If you liked this post, then these posts could also be interesting to you".
  8. Hi, I'm using the core module FieldTypeSelector (like Lister) to be able to create custom lists of pages on my pages. e.g. show me pages with template=foo, somevalue=bar and someothervalue=foobar. Is there a way to use OR groups (https://processwire.com/docs/selectors/#or-groups) with FieldTypeSelector? This way I could build a list of pages which have somevalue=bar OR someothervalue=foobar As a selector this would look like this: template=foo, (somevalue=bar), (someothervalue=foobar) Is this possible? I know I could insert this as a _custom selector, but this would kind of defeat the purpose of FieldTypeSelector. Thanks!
  9. Hi bernhart ;-), thanks, that did the trick! Here's my code, if someone also needs to do this: wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) { // skip the whole thing and return, if the user has not the proper role if (!wire('user')->hasRole('superuser') && !wire('user')->hasRole('useradmin')) return; $form = $e->return; $boxes = ['privacy', 'consent']; foreach ($boxes as $box) { $boxfield = $form->getChildByName($box); if($boxfield){ $boxfield->required = false; } } });
  10. Hi, I have a website with some users and admins who create and administrate these users. In their user profile is a checkbox which is set to required. When the admins create or edit an user they have to check this checkbox to be able to publish this user. But this checkbox should only be checked by the user itself. So I want to set this checkbox to "unrequired" when a user with a certain role is editing this profile. I tried to do this with the following hook (check for role not yet included), but I can't get it to work. wire()->addHookBefore('InputfieldCheckbox::render', function (HookEvent $event) { if ($event->object->name != 'consent') return; $field = $event->object; $field->required = false; $field->set('required', 0); }); It catches the right field but it doesn't set the field to unrequired. Is this hook too late in the chain or do I have to do this with another property or method? Thanks!
  11. Whooohaaa! Thanks! That was more then I expected! I will give it a try.
  12. Thanks, but I don't want to / can't use an external service and PW can already do all the resizing and cropping stuff. I just want access to these features outside from the template context.
  13. Hi, I'm building a small REST-API for my ProcessWire website to use the content outside in other apps. There are a lot of images and the apps will run on many different systems (mobile phones, tablets with iOS and android). To have the ability to always request the optimal image for each device width and screen density, I don't want to generate a fixed set of image sizes. Instead, it would be nice to request the resized image on the fly by sending the URL of the image with some parameters (width, height, crop) to the server and get my resized and cached image back. Similar to scripts like Timthumb or phpThumb, but with all the nice additions (e.g. focus point) from ProcessWire. The URL could look like this: https://mydomain.tld/resize/?url=/site/assets/files/1125/profile-image.jpg&width=1200&height=1200&crop=1 The response of this would be the image itself, resized to a square image, 1200x1200px How would I approach this? Is there something like this already available? Thanks!
  14. @thomasaull Thanks for this module! It seems to be a great starting point for building an API. I have 2 questions: 1. How would you approach a multilanguage API? My idea would be to add a query param to the api call (e.g. /api/posts/?lang=fr ) and switch the user language before getting the field values. Is there another/better solution? 2. I don't need it right now, but how would I implement a session authentification when accessing the api? Thanks!
  • Create New...