Jump to content

Juergen

Members
  • Content Count

    990
  • Joined

  • Last visited

  • Days Won

    4

Juergen last won the day on July 15

Juergen had the most liked content!

Community Reputation

529 Excellent

About Juergen

  • Rank
    Hero Member

Profile Information

  • Gender
    Male
  • Location
    Linz
  • Interests
    Playing electric guitar (Rock, Heavy), flying model helicopters

Recent Profile Visitors

5,665 profile views
  1. No problem for the moment, because I dont need the raw value. I thought that I needed it, but I dont 😉!
  2. Hello @MoritzLost This is what I wanted, but leads to an internal server error on the frontend. In only know $page->of(false) There is a similar post in the forum, which does not work as expected too. Thanks for your hint.
  3. Thanks @LostKobrakai, but this was a misunderstanding. I wanted to prevent the usage of getUnformatted or page->of(false) or something like that method inside the template. I was looking for a possiblitiy to disable outputformatting inside the method itself, so I can use the API without adding a getUnformatted on the template base. But it doesnt matter, because it was a thinking mistake of mine. I dont need the unformatted value from the db - i need the value from the db in a specific format and therefore I am using a manipulation function to get the desired result. But it would be interesting if disabling the formatting inside a method itself is possible.
  4. Hello @ all, Lets imagine I have a value stored in the database which I can output on the frontend with a simple API call like $page->myValue and this value will be manipulated with the formatValue() method before output on the frontend. So it was stored in the database like this: This is my value And after running through formatValue() method it will be: <p>This is my value.</p> So far so good. Now I have created a method inside my fieldtype/inputfield class which uses this value: public function myMethod() { $value = $this->myValue //value should be unformatted as dirctly stored in the database } Problem: myValue is always formatted because it runs through the formatValue method first - is there a way to get the "raw" data instead without setting ouputformatting to false inside the template if I call echo $page->myValue->myMethod(); I think it would not be possible because myMethod() is part of myValue, but maybe someone has an idea how it could work. Thanks in advance
  5. 2 new methods for Schema.org markup added: print_r($page->fieldname->getjsonLDTimes()); returns an array like this: Array ( [0] => Mo,Tu,We 08:00-12:00 [1] => Mo,Th 13:00-18:00 [2] => Th 08:00-11:00 ) Can be used to create the markup by yourself or echo $page->fieldname->renderjsonLDTimes(); returns a string like this: "Mo,Tu,We 08:00-12:00", "Mo,Th 13:00-18:00", "Th 08:00-11:00" You can use the second method in schema.org Local Business opening hours as followed: ..... "openingHours": [ "Mo,Th,Sa 11:00-14:30", "Mo,Th 17:00-21:30", "Fr,Sa 17:00-22:00" ], ..... Best regards
  6. New feature added: I have updated the inputfield to support multilanguage timeformats on the frontend. You can set the timeformat of each language in the configuration of the inputfield in the backend (see screencast below). Supports strftime() and date() formats. Languageformat.mp4 Version was bumped from 1.0 to 1.1 on Github. Best regards Jürgen
  7. Hello @ all I have 2 new methods added which take care of days with same times. It often happens that different days have exactly the same opening times. To prevent writing the same times over and over again, you can combine these days with this 2 new methods. 1) First new method to output a multidim. array print_r($page->fieldname->combinedDays()); You can use this array to create the markup by yourself. 2) Render method to output an unordered list of same opening times echo $page->fieldname->renderCombinedDays(); This method outputs a rendered string like this one: <ul class="uk-list"> <li>Mo, Fr: 08:00 - 16:00</li> <li>Tu, Th: 08:00 - 16:00, 18:00 - 20:00</li> <li>We: 16:00 - 23:05</li> <li>Sa, Su, Ho: closed</li> </ul> As you can see days with same times are combined now. Changes are added to Github now, so please download the files again if you want the latest version.🙂 Best regards
  8. Issue should be resolved and the file was updated on Github 🙂
  9. Hi @bernhard Thanks for your feedback! I will check this and and try to find a solution. 🙂 I have worked with this library in the past and it's really cool, but for the moment I have not planned to include a third party lib. The main purpose of this inputfield is to make entering of opening times simple for the user. Not really! Holidays are always hassle because they differ from country to country. For the moment you can enter only general opening times for all holidays. Exceptions can be really difficult and I guess there you will need to use Spatie to handle this.
  10. Hello @ all ! Today I want to share another new inputfield with the community! It is called Fieldtype OpeningHours and it is designed to enter one or multiple times per day (especially for company opening times). I know that there is another great fieldtype in the repository (https://modules.processwire.com/modules/fieldtype-business-hours/), but I wanted to create my own with a different UI than the other one. Here is a screencast of what it looks like in action: OpeningHours.mp4 A lot of things going on behind the scenes and I dont want to write it all down here, because you can find the whole information on my Github account (there you can also download this inputfield) Download-link: https://github.com/juergenweb/FieldtypeOpeningHours If you may find any bugs, have any ideas to improve this fieldtype please report it in my Github repository. Greetings from Austria and have a nice day! CHANGELOG: 21.7.20 Add new option to show (true) or hide (false) days with no opening hours on various methods (please be aware that setting options has been changed - it is recommended to deinstall old version and install this inputfield again) . Take a look at the READ.ME for further instructions. 1.1 Add multilang support for timeformat and add 2 additional Schema.org markup methods
  11. Hello @ all, I have created an inputfield with a configuration field in the backend where you can set a time format for every language (see screenshot below). As you can see both language values (default and German) have the default value(%R), but I have set different values, which were correctly stored in the DB (see screenshot below): As you can see the values are '%R' and '%r'. I have created the configuration inputfield like this: /** @var InputfieldText $f */ $languages = $this->wire('languages'); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name+id', 'timeformat'); $f->label = $this->_('Timeformat on frontend'); $f->initValue = '%R';//default value $f->attr('value', $this->timeformat ? $this->timeformat : '%R'); $this->message($this->get('timesformat')); if($languages) { $f->useLanguages = true; foreach($languages as $language) { if($language->isDefault()) continue; $f->set("value$language", (string) $this->get("timeformat$language->id")); } } $f->inputType = 'text'; $f->description = $this->_('Please enter the time format that the times should appear on the frontend in strftime format.'); $f->notes = sprintf($this->_('For example shows the time as 08:00, as 08:00 AM. You can find more examples at %s.'), '<a href="https://www.php.net/manual/de/function.strftime.php">https://www.php.net/manual/de/function.strftime.php</a>'); $f->columnWidth = 100; The important part here is: if($languages) { $f->useLanguages = true; foreach($languages as $language) { if($language->isDefault()) continue; $f->set("value$language", (string) $this->get("timeformat$language->id")); } } I have borrowed the code from the DateTimeInputfield (https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module), but the field values will be always populated with the default value ('%R'). Are I am missing something? Does anyone has experience with multilanguage fields and could help me out? Thanks in advance.
  12. OK, I figured it out. I transformed the values of the inputfields inside the sleepValue function to a json array and now the values will be stored in the database. public function sleepValue(Page $page, Field $field, $value) { // throw error if value is not of the right type if (!$value instanceof OpeningHours) { throw new \Exception($this->_('Expecting an instance of OpeningHours')); } $content = json_encode($value->data['hours']); $sleepValue = ['hours' => $content]; return $sleepValue; } So the responsible lines are $content = json_encode($value->data['hours']); $sleepValue = ['hours' => $content]; The problem of the storage was that the column 'hours' was not defined in the sleepValue method. This was the important part because without it the system doesnt know where to store the value.
  13. OK, I am 1 step forward :-) Adding $this->value['hours'] = $time_values; to the processInput() method adds the values to the object Here is the complete code of this method: public function ___processInput(WireInputData $input): self { $name = $this->attr('name'); $value = $this->attr('value'); //input object includes always every input on the page, so lets filter out only inputs from this field //we need to do this, because the number of values is variable - so extract only values that starts with $name.'_' $nameAttributes = []; foreach($input as $key=>$value){ if(substr($key, 0, strlen($name.'_')) === $name.'_'){ $nameAttributes[$key] = $value; } } // loop through all inputfields and set the value (if changed or not) back $time_values = []; foreach($nameAttributes as $nameAttr => $value) { $time_values[$nameAttr] = $value; } //add it to the object $this->value['hours'] = $time_values; return $this; } Now the values are also reachable in sleepValue() method and the sanitizeValue() method. ProcessWire\OpeningHours Object ( [data] => Array ( [hours] => Array ( [openinghours_mo-0-start] => 09:00 [openinghours_mo-0-finish] => 13:00 [openinghours_mo-1-start] => 14:00 [openinghours_mo-1-finish] => 18:00 [openinghours_mo-2-start] => 21:00 [openinghours_mo-2-finish] => 23:00 [openinghours_tu-0-start] => 09:00 [openinghours_tu-0-finish] => 13:00 [openinghours_tu-1-start] => 14:00 [openinghours_tu-1-finish] => 18:00 [openinghours_we-0-start] => 09:00 [openinghours_we-0-finish] => 13:00 [openinghours_we-1-start] => 14:00 [openinghours_we-1-finish] => 18:00 [openinghours_th-0-start] => 09:00 [openinghours_th-0-finish] => 13:00 [openinghours_th-1-start] => 14:00 [openinghours_th-1-finish] => 18:00 [openinghours_fr-0-start] => 09:00 [openinghours_fr-0-finish] => 13:00 [openinghours_fr-1-start] => 14:00 [openinghours_fr-1-finish] => 18:00 [openinghours_sa-0-start] => [openinghours_sa-0-finish] => [openinghours_so-0-start] => [openinghours_so-0-finish] => [openinghours_ho-0-start] => [openinghours_ho-0-finish] => ) ) ) Nevertheless the value in the DB is NULL :-(
  14. Hello @ all, I am creating a new inputfield/fieldtype to store opening hours, but I am struggeling to save values from multiple dynamic created inputfields in 1 column of the database. Scenario: The user can enter one or more opening times per day in a UI. Fe: Monday open from 08:00 to 12:00 and from 14:00 to 17:00 Tuesday open from 08:00 to 12:00 and from 14:00 to 19:00 and so on Via a little JavaScript you can add as much opening times as you need per day - the additional inputfield will be created dynamically. After form submission all the values are in the POST array -> this works (see example below): ProcessWire\WireInputData Object ( [openinghours_mo-0-start] => 09:00 [openinghours_mo-0-finish] => 13:00 [openinghours_mo-1-start] => 14:00 [openinghours_mo-1-finish] => 18:00 [openinghours_mo-2-start] => 21:00 [openinghours_mo-2-finish] => 23:00 [openinghours_tu-0-start] => 09:00 [openinghours_tu-0-finish] => 13:00 [openinghours_tu-1-start] => 14:00 [openinghours_tu-1-finish] => 18:00 [openinghours_we-0-start] => 09:00 [openinghours_we-0-finish] => 13:00 [openinghours_we-1-start] => 14:00 [openinghours_we-1-finish] => 18:00 [openinghours_th-0-start] => 09:00 [openinghours_th-0-finish] => 13:00 [openinghours_th-1-start] => 14:00 [openinghours_th-1-finish] => 18:00 [openinghours_fr-0-start] => 09:00 [openinghours_fr-0-finish] => 13:00 [openinghours_fr-1-start] => 14:00 [openinghours_fr-1-finish] => 18:00 [openinghours_sa-0-start] => [openinghours_sa-0-finish] => [openinghours_so-0-start] => [openinghours_so-0-finish] => ) The property name is always the name attribute of the field 😉 . If the property is empty means closed on that day. Now I need to combine all those values into 1 array (or json array) and store it in the database in 1 column called 'hours' in my case (see screenshot below): In my ___processInput(WireInputData $input) method I have tried to make it work like this: public function ___processInput(WireInputData $input): self { $name = $this->attr('name'); $value = $this->attr('value'); //input object includes always every input on the page, so lets filter out only inputs from this field //we need to do this, because the number of values is variable - so extract only values that starts with $name.'_' $nameAttributes = []; foreach($input as $key=>$value){ if(substr($key, 0, strlen($name.'_')) === $name.'_'){ $nameAttributes[$key] = $value; } } // loop through all inputfields of this fieldtype $time_values = []; foreach($nameAttributes as $nameAttr => $value) { $time_values[$nameAttr] = $value; } } //save it in the database $input->set('hours', serialize($time_values)); return $this; } The only important part of this code is the last part with the serialize function. After saving it will create a record in the database, but the value is always NULL (default value) (see below). Checking $time_values returns all the values, but printing out "$this" shows me that the property "hours" inside the Openinghours object is empty (see below) - so the mistake must be there, but I dont know where?!?!?!? [title] => Home [openinghours] => ProcessWire\OpeningHours Object ( [data] => Array ( [hours] => ) ) If I check the sleepValue() method or the sanitizeValue() - they are also empty. So it seems that the values will not reach these methods. I havent found a clear documentation of whats going on behind the saving process of an inputfield. As far as I know the saving process starts with the form submission. The values are in the POST array and will be processed by the processInput() method. Before they will be saved in the database they will be sanitized by the sanitizeValue() mehtod and afterwards they will be prepared for storage in the sleepValue() method. The last step is the storage itself. Has someone an idea what is missing by storing values from multiple fields into 1 database column or has someone a working example of such a scenario on github to help me out. A clear explanation of the storage process will be also helpful. Thanks and best regards
×
×
  • Create New...