Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Orkun

  1. Hi @thomasaull Thank you for this great module! I came across a problem. I need an endpoint where I can search after an user with his e-mail address. So I created a new grouped Route. My Routes.php looks like this: <?php require_once wire('config')->paths->RestApi . "vendor/autoload.php"; require_once wire('config')->paths->RestApi . "RestApiHelper.php"; require_once __DIR__ . "/Example.php"; $routes = [ ['OPTIONS', 'test', RestApiHelper::class, 'preflight', ['auth' => false]], // this is needed for CORS Requests ['GET', 'test', Example::class, 'test'], 'searchuser' => [ ['OPTIONS', '', RestApiHelper::class, 'preflight', ['auth' => false]], // this is needed for CORS Requests ['GET', '{email}', Example::class, 'doesUserWithEmailExist', ['auth' => false]], ], 'users' => [ ['OPTIONS', '', RestApiHelper::class, 'preflight', ['auth' => false]], // this is needed for CORS Requests ['GET', '', Example::class, 'getAllUsers', ["auth" => false]], ['GET', '{id:\d+}', Example::class, 'getUser', ["auth" => false]], // check: https://github.com/nikic/FastRoute ], ]; My Function in Example.php looks like this: public static function doesUserWithEmailExist($data){ echo "<pre>"; echo print_r($data, true); echo "</pre>"; $data = RestApiHelper::checkAndSanitizeRequiredParameters($data, ['email|email']); $response = new \StdClass(); if($data->email != "") { $user = wire('users')->get("template=user, email=$data->email"); if(!$user->id) throw new \Exception('user not found'); $response->test = $data->email; $response->id = $user->id; $response->name = $user->name; $response->email = $user->email; } else { throw new \Exception('Unvalid E-Mail address'); } return $response; } When calling from Browser: The Problem is, that the "@" character in the E-Mail gets stripped away and therefore the email is always wrong. I investigated this and found out, that it is because of the wire('input')->url codepart on line 61 in the Router.php. This is stripping away the "@" character when calling. When I replace the wire('input')->url part with $_SERVER['REQUEST_URI'] it is working. What should I do? KR Orkun
  2. I have solved this now with a second find since it are not much pages (102 since website launch in 2016). // Workaround $specificSpecialitiesFilteredByClinic = $pages->find("template=specialities-clinics, sort=title, choose_sender_2016={$rootParent->choose_sender_2016}"); $ids = ""; foreach($specificSpecialitiesFilteredByClinic as $speciality){ $ids .= $speciality->parent->id."|"; } $ids = rtrim($ids, "|"); $find = $pages->find("id=$ids, sort=title, limit=24"); KR Orkun
  3. Hi Guys I am trying to sort children pages by their parent title field but it looks like this is only possible in the PW 3 Branch. I am using the 2.7.3 Version. This is my selector at the moment, I am also using pagination (limit): template=specialities-clinics, sort=title, choose_sender_2016={$rootParent->choose_sender_2016}, limit=24 When I try "sort=parent.title" I get the following error: Is there any way/workaround to make this work in the PW 2.7.3 Version? KR Orkun
  4. Hi Guys The field dependencies doesn't work for me when the "receiver" field is a "InputfieldRadios" field (the inputfields with the defined "showIf" Attribute are always hidden). It only works when I change the "receiver" field to "InputfieldSelect". // Get repeater Pages as selectable Option if(count($page->rootParent->choose_sender_2016->contactform_receivers) > 1){ $field = $modules->get("InputfieldRadios"); $field->label = _gt("empfaenger"); $field->attr('id+name', "receiver"); foreach ($page->rootParent->choose_sender_2016->contactform_receivers as $option) { $field->addOption($option->id, $option->title); } if($input->get->receiver){ $field->value = $input->get->receiver; } $field->required = 1; $form->append($field); } // triggerMedicalFields is a single page reference field which returns the repeater pages as selectable list (PHP Custom Code) if($page->triggerMedicalFields){ $clinicSpecialities = $pages->find("template=specialities-clinics, choose_sender_2016={$page->rootParent->choose_sender_2016}"); if($clinicSpecialities->count > 0){ $field = $modules->get("InputfieldSelect"); $field->label = _gt("fachgebiet"); $field->attr('id+name', "speciality"); foreach ($clinicSpecialities as $option) { $field->addOption($option->parent->id, $option->parent->title); } $field->required = 1; $field->showIf = "receiver={$page->triggerMedicalFields->id}"; $form->append($field); } $field = $modules->get("InputfieldText"); $field->label = _gt("krankheitsbild"); $field->attr('id+name','disease_pattern'); $field->required = 1; $field->showIf = "receiver={$page->triggerMedicalFields->id}"; $form->append($field); $upload_path = $config->paths->assets . "files/-tmp_uploads/"; $field = $modules->get("InputfieldFile"); $field->label = _gt("medizinische-dokumentation"); $field->required = 1; $field->attr("name+id", 'medical-documentation'); $field->destinationPath = $upload_path; $field->extensions = "jpg jpeg gif png"; $field->maxFiles = 3; $field->maxFilesize = 2*1024*1024; // 2mb $field->showIf = "receiver={$page->triggerMedicalFields->id}"; $form->add($field); } How can I make Inputfield Dependencies work with InputfieldRadios? I am using PW Version 2.7.3. KR Orkun
  5. Hi @Robin S Thank you for the tip! I didn't know about the listable method. I am using now the listable hook to hide pages in the admin tree (and also in PageListSelect Inputfields). About the false child count problem. You are probably right, that this is not worth the trouble so I will leave it as it is, since I didn't heard any complains from the users concerning false child count. What is the benefit from hooking Page::listable() instead of ProcessPageList::find()? KR Orkun
  6. Hi Bernhard, Thank you for refactoring :) KR Orkun
  7. It looks like a hook to ProcessPageList::find is working. Here is the code $this->addHookAfter('ProcessPageList::find', function(HookEvent $event) { // Get the object the event occurred on, if needed $ProcessPageList = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $selectorString = $event->arguments(0); $page = $event->arguments(1); $excludePagesByTemplate = array( "newsletter-clinic", "sender_2016", "sender_2016_collab", "inside-news-folder", "basic-page", "event-clinic", "domain_root", "brandportal-index", "key-figures", "jobs", "news", "media-mirror", "worker", "xmlexport", "weekly-menu", "intranet_domain_root", "weekly-menu-index", "daily-menu", "daily-menu-index", "benefit", "benefits-index", "pdiatres-de-garde-index", "xml-feed-index", "courses-index", "help-doc", "stocks-index", "dictionary", "iPad-PDF-Index", "pkb-pikettdienst-index", "heisser-stuhl-index", "heisser-stuhl" ); if($return instanceof PageArray){ foreach($return as $p){ if(in_array($p->template->name, $excludePagesByTemplate)){ if(!$p->editable() && !$p->addable()) { $return->remove($p); } } } } $event->return = $return; }); KR Orkun
  8. Hi @dragan Wouldn't be there problems when using a css or js solution, because of the ajax loading and pagination? I mean there is also still the problem of false child count (also with the current code). KR Orkun
  9. Hi Guys A long time ago (2-3 years ago) I had written the following hook (based on this gist https://gist.github.com/somatonic/5595081): public function init() { $this->addHookAfter('ProcessPageList::execute', $this, 'hidePages'); } public function hidePages(HookEvent $event){ if($this->wire('config')->ajax){ $excludePages = new PageArray(); $the_pages = $this->wire('pages')->find("template=newsletter-clinic|sender_2016|sender_2016_collab|inside-news-folder|basic-page|event-clinic|domain_root|brandportal-index|key-figures|jobs|news|media-mirror|worker|xmlexport|weekly-menu|intranet_domain_root|weekly-menu-index|daily-menu|daily-menu-index|benefit|benefits-index|pdiatres-de-garde-index|xml-feed-index|courses-index|help-doc|stocks-index|dictionary|iPad-PDF-Index|pkb-pikettdienst-index|heisser-stuhl-index|heisser-stuhl"); foreach ($the_pages as $the_page) { if(!$the_page->editable() && !$the_page->addable()) { $excludePages->add($the_page); } } foreach ($this->wire('pages')->find("template=specialties") as $sp) { if($sp->numChildren > 0){ $editableFound = 0; foreach ($sp->children() as $spc) { if($spc->editable()){ $editableFound++; }else{ $excludePages->add($spc); } } if($editableFound == 0){ $excludePages->add($sp); } }else{ $excludePages->add($sp); } } $hidden = explode('|', $excludePages); $json = json_decode($event->return, true); foreach($json['children'] as $key => $child){ if(in_array($child['id'],$hidden)) unset($json['children'][$key]); } $json['children'] = array_values($json['children']); $event->return = json_encode($json); } } It hides all the uneditable and unaddable (can't add children to page) pages for non-superusers. But this code slows down the page tree view heavily. Because of this I wanted to ask if there is better way (possibly a new added hook in PW3?) to hide uneditable/unaddable pages for non-superusers. KR Orkun
  10. Nevermind. There was a repeater inside the template which also had a pagefield with custom code in it. :D
  11. Hi Guys After upgrading from 2.7.3 to 3.0.141 I am getting following errors when editing pages that have a page reference field with php custom code option enabled. On the corresponding page/template I have these two fields/custom code: I have tried to solve it by adding namespace ProcessWire; at the top of the custom code (for both pagefields) but that doens't worked. The error still persist. How can I solve this? KR Orkun
  12. The error persisted even when i deleted the contents of site/assets/cache/FileCompiler. But I have now added the following inside the PHPExcel File and it is working now: KR Orkun
  13. Hi @BitPoet Thank you for your help. But when I do this: require_once( dirname(__FILE__) . '/Classes/PHPExcel.php' /*NoCompile*/ ); I can't access the processwire backend anymore and this error is thrown: KR Orkun
  14. Hi Guys I upgraded today an existing 2.7.3 PW Installation to PW 3.0.141. I am now always getting this message when refreshing the admin because of a custom module I had made a long time ago which is using the PHPExcel library: The Structure of the module looks like this: And it is included like this in the module file: At first I thought I need to add namespace ProcessWire; at the top of to the ProcessEventManager.module but doing that lead to this error message and I wasn't able to use the admin at all: When I remove the line require_once( dirname(___FILE___) . '/Classes/PHPExcel.php'); from the ProcessEventManager.module file the filecompiler message doesn't come anymore. Do you know how can I remove the FileCompiler Message once and for all without removing PHPExcel? KR Orkun
  15. Hi Guys I needed to add extended functionalities for the InputfieldDatetime Module (module is from processwire version 2.7.3) because of a Request of Customer. So I duplicated the module and placed it under /site/modules/. I have added 3 new Settings to the InputfieldDatetime Module. 1. Day Restriction - Restrict different days based on weekdays selection (e.g. saturday, sunday) - WORKING 2. Time Slots - Define Time slots based on custom Integer Value (max is 60 for 1 hour) - WORKING 3. Time Range Rules per Weekday - Define a minTime and MaxTime per Weekday (e.g. Opening Hours of a Restaurant) - NOT WORKING PROPERLY The Problem Time Slots and Day Restriction working fine so far. But the Time Range Rules per Weekday doesn't work right. What should happen is, that when you click on a date, it should update the minTime and maxTime of the Time Select. But the change on the select only happens if you select a date 2 times or when you select a date 1 time and then close the datepicker and reopen it again. The time select doesn't get change when you select a date 1 time and don't close the picker. Here is the whole extended InputfieldDatetime Module. The Files that I have changed: InputfieldDatetime.module InputfieldDatetime.js jquery-ui-timepicker-addon.js (https://trentrichardson.com/examples/timepicker/) - updated it to the newest version, because minTime and maxTime Option was only available in the new version Thats the Part of the JS that is not working correctly: if(datetimerules && datetimerules.length){ options.onSelect = function(date, inst) { var day = $(this).datetimepicker("getDate").getDay(); day = day.toString(); var mintime = $(this).attr('data-weekday'+day+'-mintime'); var maxtime = $(this).attr('data-weekday'+day+'-maxtime'); console.log("weekday: "+day); console.log("minTime: "+mintime); console.log("maxTime: "+maxtime); var optionsAll = $(this).datetimepicker( "option", "all" ); optionsAll.minTime = mintime; optionsAll.maxTime = maxtime; $(this).datetimepicker('destroy'); $(this).datetimepicker(optionsAll); $(this).datetimepicker('refresh'); //$.datepicker._selectDate($(this).attr("id"),date); //$.datepicker._base_getDateDatepicker(); // var inst = $.datepicker._getInst($(this)); // $.datepicker._updateDatepicker(inst); /*$(this).datetimepicker('destroy'); InputfieldDatetimeDatepicker($(this), mintime, maxtime); $(this).datetimepicker('refresh'); */ // $(this).datetimepicker('option', {minTime: mintime, maxTime: maxtime}); } } Can you have a look and find out what the Problem is? InputfieldDatetime.zip Kind Regards Orkun
  16. Nevermind solved it by deleting the Row inside the table "Fields" and also deleted the Table "field_event_dates". Kind Regards Orkun
  17. Hi Guys I have a problem with a repeater field. Some weeks ago I had exported a repeater field from a dev installation and then imported it to a live installation. All just had worked fine as I remember (the field was created etc...). But today I got an email from the developer of our customer that he has a problem with two repeater fields. When he had changed the fields of another repeater it has also changed it in the other repeater field (which I had imported some weeks ago). I investigated this further and found out that exporting/importing of repeater fields doesn't work for my version of processwire (we are using 2.7.3) (see https://github.com/processwire/processwire-issues/issues/416). So I decided to remove the repeater field and create it again manually on the live enviroment. I could remove the repeater field from the template but I can't delete the repeater field because it is referring to a false repeater template. How can I fix this issue so that I can delete the repeater field? The "event_dates" repeater field is referring to the "repeater_speciality_adresses" template which is wrong. When I try to delete the field I get this error: Do I need to manually remove the field from the db? What do I exactly need to do? Kind Regards Orkun
  18. Thanks @dragan I had solved this with a hook into the processInput of the corresponding Inputfield. It kinda feels dirty but it does the job. It checks at first if all languages are empty. If all languages are empty, it gets the old values of the page and gives the data to the incoming post request, so that the old values are still in place. And also an error message is returned on the field. $wire->addHookAfter("InputfieldPageTitle::processInput", function(HookEvent $event) { if(wire('user')->hasRole("partner")){ $field = $event->object; $page = $this->modules->ProcessPageEdit->getPage(); $allowedTemplates = array( "event", "partner", ); if(in_array($page->template->name, $allowedTemplates)){ $errorCounter = 0; foreach($this->languages as $lang){ $lname = $lang->isDefault() ? "" : "__".$lang->id; if($this->wire('input')->post("title$lname") == ""){ $errorCounter++; } } // If all multi-language Fields are empty if($errorCounter == 4) { // Needs to be done like this for the default language. Somehow id doesn't work inside the foreach loop underneath $default = $this->languages->getDefault(); $oldvalue = $page->getLanguageValue($default, 'title'); $field->value = $oldvalue; // iterate through all languages except default foreach($this->languages as $lang){ if(!$lang->isDefault()){ // Get value which is already in db / on page $oldvalue = $page->getLanguageValue($lang, 'title'); // Overwrite incoming post with old data from the db $postvar = "title__{$lang->id}"; $this->wire('input')->post->$postvar = $oldvalue; } } // Populate Error to field $field->error("You must fill in at least one language"); } } } }); $wire->addHookAfter("InputfieldTextarea::processInput", function(HookEvent $event) { if(wire('user')->hasRole("partner")){ $field = $event->object; $page = $this->modules->ProcessPageEdit->getPage(); $allowedTemplates = array( "event", "partner", ); $allowedFields = array( "body", "about_us", "why_we_join" ); // If field is already required, abort the hook if($field->required) return; $f = $this->wire('fields')->get($field->name); if(in_array($page->template->name, $allowedTemplates) && in_array($field->name, $allowedFields) && $f instanceof Field && $f->type instanceof FieldtypeLanguageInterface){ // Check if field is empty in all languages $errorCounter = 0; foreach($this->languages as $lang){ $lname = $lang->isDefault() ? "" : "__".$lang->id; if($this->wire('input')->post("{$field->name}$lname") == ""){ $errorCounter++; } } // If all multi-language Fields are empty if($errorCounter == 4) { // Needs to be done like this for the default language. Somehow id doesn't work inside the foreach loop underneath $default = $this->languages->getDefault(); $oldvalue = $page->getLanguageValue($default, $field->name); $field->value = $oldvalue; // iterate through all languages except default foreach($this->languages as $lang){ if(!$lang->isDefault()){ // Get value which is already in db / on page $oldvalue = $page->getLanguageValue($lang, $field->name); // Overwrite incoming post with old data from the db $postvar = "{$field->name}__{$lang->id}"; $this->wire('input')->post->$postvar = $oldvalue; } } // Populate Error to field $field->error("You must fill in at least one language"); } } } }); Kind Regards Orkun
  19. Hi Guys My Processwire Installation has 4 Languages installed (German, French, Italian and English). German is the default language. How can I change the behavior of a required Multi-Language Field, that it checks if one of the lanuages is filled out (and not how it is like now where it only checks, if the default language is filled out)? Do I need a Hook for this or some js action? Kind Regards Orkun
  20. Just tested it on DEV Site. Works like a charm. Thank you!
  21. Hi Guys How can I make a redirect inside the .htaccess to my custom maintenance.html file when any URL of my Website is accessed except the processwire admin (www.example.com/processwire/). Because I want that my User's still can access the website when they are loggedin in Processwire. When the current url starts with /processwire or if there is a processwire-login-cookie (Is there a cookie when user is logged in Processwire?) available the redirect should not work. Otherwise it should work. How can I achieve this?
  22. Hi Guys Working now for several years with Sublime Text and lately I had made the decision to try out vscode and I must say that it is really cool. Feels really fast like Sumblime Text. I have a question about the code syntax highlighting. How can I say to vscode that it should treat *.module files as *.php files so that syntax highlighting of php is used for Modules? Edit: Nevermind - https://stackoverflow.com/questions/29973619/how-to-make-vs-code-to-treat-other-file-extensions-as-certain-language Kind Regards Orkun
  23. Hi @kongondo Sorry for my late answer. I could resolve the issue with renaming the audio pagename from "peter-fractures-lac" to "peter-fractures-lac-old" after I have done that somehow a new page was generated automatically called "peter-fractures-lac" with the same audio file like the "old" page ("peter-fractures-lac-old"). From now on I could upload images documents etc... and it worked fine. The Error "Empty file upload result" doesn't come anymore. I also removed now the new generated audio page and renamed "peter-fractures-lac-old" back to "peter-fractures-lac" and everything still works fine. Very strange behavior. - It was working OK previously I upgraded to 0.0.6 now. Thanks. Kind Regards Orkun
  • Create New...