Jump to content

Juergen

Members
  • Posts

    1,419
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Juergen

  1. I dont know if this is a problem of the module or from PW in general. The path names on a multilingual site are only changed for the default language and not for the other languages. In my case I use parent title and date. In German (default) it shows me both, but in English I only get the parent title without the date. Best regards It is not a big problem because you can change the pathname afterwards via a hook for the other languages.
  2. Hello @ all I want to share my code of a module which copies values from a parent page to a child page by using the add button of a pagetable field. If you find it useful you can copy the code or you can improve the code and post your ideas of improvement here. The intention for me was that I have pages with events and I dont want to write all the data for an event manually. Especially if only the date of the event is different. I use a pagetable field for the events and I want to click the add button of this field and a new childpage will be created with all the data of the event (title, description, summary,...) so I have only to fill in the start and end date for the event. So far so good, but it was a little bit tricky to get this to work with the add button of the pagetable field. So I decided to write a module which does the work for me. Here is the piece of code: <?php class CopyPageTableAdd extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Pagetable copy values', 'summary' => 'Copy Pagetable content by pressing the add button', 'href' => '', 'version' => 001, 'autoload' => true, 'singular' => true ); } public function ready() { $this->pages->addHookBefore('ProcessPageAdd::execute', $this, 'copyaddpage'); } public function copyaddpage() { //configuration $parenttemplatename = "events"; //the template name of the parent template $childtemplatename = "single-event"; //the template name of the newly created child template $page = new Page(); $page->parent = $this->input->get->parent_id; if ($page->parent->template == $parenttemplatename) {//check if it is the right parent template $page->template = $childtemplatename; //set the template for the created child page //copy all fields field values from the parent template (start) //enter all fields which you want to copy into the child page $page->title = $page->parent->title; $page->eventstatus = $page->parent->eventstatus; $page->eventtype = $page->parent->eventtype; $page->summary = $page->parent->summary; $page->headline = $page->parent->headline; $page->importanteventstext = $page->parent->importanteventstext; $page->importanteventstext = $page->parent->importanteventstext; $page->notifiable = $page->parent->notifiable; $page->reservationtype = $page->parent->reservationtype; $page->participantlimit = $page->parent->participantlimit; $page->participantmaxnumber = $page->parent->participantmaxnumber; $page->eventmaxstatus = $page->parent->eventmaxstatus; $page->eventcosttype = $page->parent->eventcosttype; $page->eventprice = $page->parent->eventprice; $page->eventpriceadd = $page->parent->eventpriceadd; $page->eventlocationname = $page->parent->eventlocationname; $page->street = $page->parent->street; $page->postalcode = $page->parent->postalcode; $page->eventlocationname = $page->parent->eventlocationname; $page->place = $page->parent->place; $page->region = $page->parent->region; $page->country = $page->parent->country; $page->googlemap = $page->parent->googlemap; //copy all fields field values from the parent template (end) $page->addStatus(Page::statusUnpublished); //this foreach loop is only if you have a multilanguage site to get the path names in each language //if your site is only single language you can use $page->name=$page->parent->name (but not tested) foreach ($this->languages as $lang) { $lname = $lang->id; $pageName = $page->title->getLanguageValue($lang); $page->set("name$lang", $pageName); if ($lang->isDefault()) continue; $page->set("status$lang", 1);//activate the multilanguage checkbox } $page->save(); $this->session->redirect("../edit/?id=$page"); } } } The configuration part: //configuration $parenttemplatename = "events"; //the template name of the parent template $childtemplatename = "single-event"; //the template name of the newly created child template This is the part where you have to define the templates. The name of the parent template is responsible that the module only run on that template (in my case the template with the name "events). The name of the child template ist the template which should be created after pressing the add button (in my case the template with the name "single-event"). You have to fill in your template names. The module runs only if the parent template has the specific name and creates only child pages with the child pages template name. Copy all field values par: //copy all fields field values from the parent template (start) //enter all fields which you want to copy into the child page $page->title = $page->parent->title; $page->eventstatus = $page->parent->eventstatus; $page->eventtype = $page->parent->eventtype; $page->summary = $page->parent->summary; $page->headline = $page->parent->headline; $page->importanteventstext = $page->parent->importanteventstext; $page->importanteventstext = $page->parent->importanteventstext; $page->notifiable = $page->parent->notifiable; $page->reservationtype = $page->parent->reservationtype; $page->participantlimit = $page->parent->participantlimit; $page->participantmaxnumber = $page->parent->participantmaxnumber; $page->eventmaxstatus = $page->parent->eventmaxstatus; $page->eventcosttype = $page->parent->eventcosttype; $page->eventprice = $page->parent->eventprice; $page->eventpriceadd = $page->parent->eventpriceadd; $page->eventlocationname = $page->parent->eventlocationname; $page->street = $page->parent->street; $page->postalcode = $page->parent->postalcode; $page->eventlocationname = $page->parent->eventlocationname; $page->place = $page->parent->place; $page->region = $page->parent->region; $page->country = $page->parent->country; $page->googlemap = $page->parent->googlemap; //copy all fields field values from the parent template (end) This ist the part where you can fill in all fields which you want to copy the values. It copies the values from the parent page to the child page. You can do this also with a foreach loop, but I dont want to copy all field values so I write it manually for each field. The multilanguage part: foreach ($this->languages as $lang) { $lname = $lang->id; $pageName = $page->title->getLanguageValue($lang); $page->set("name$lang", $pageName); if ($lang->isDefault()) continue; $page->set("status$lang", 1);//activate the multilanguage checkbox } The multilanguage part is necessary if you have a multilanguage site, because it creates the path names for each language in the right language. After that the multilanguage checkbox for the non default language should be checked to activate the page in this language. Here are some screenshots: 1) Press the add button of the pagetable field 2) A new child page will be created with prefilled values of the parent page 3) Path names are in the right language and multilanguage checkbox is activated So this might be useful for others Best regards
  3. This was also my first thought, but this is not the case. I also added a complete new title and path name I never used before on that site but it doesnt matter. The number problem is still there. It is a little bit spooky. Here are the screenshots where you can see the path names: German: English:
  4. I have inserted the following code before the $k->save(); command: foreach($this->languages as $lang){ if($lang->isDefault()) continue; $k->set("status$lang", 1); $pageName = $page->title->getLanguageValue($lang); $k->set("name$lang", $pageName); } Now the multilanguage checkbox is activated and the multilanguage page names are in the correct language. Unfortunately the number of the page at the end of the language page name is different between German and English. The same childpage have the following page name for the URL: German: termine-im-februar-2 English: events-in-february-1 As you can see the number at the end is always one step lower in English than in German. It is not a really big problem, but if anyone has an explanation or a solution for this behaviour it would be great to post it here.
  5. The above code from Mr. NiceGuy works quite well, but I have a multilanguage site so I need that the childpages have to be created in every language. At the moment they are only created for my default language. The problem is here: The alias is the same as in the default language and the "active" checkbox is not checked. How can I create childpages for all languages in this case? Best regards
  6. New problem: comment form stops sending if email address for approval is in this syntax "id:fieldname". If I enter the email address for comment approval like 1006:mail ("1006" is the id of the page which contains the email field and "mail" is the name of the email field) no email will be sent. If I enter the email address as plain text like "myemail@abc.com" the email will be sent correctly. I have updated to the lates dev 2.7.3. The syntax above has worked in the past. Best regards EDIT: I have created a new comment field and now it works again
  7. Problem solved: The cause of the problem was the wrong order of fields with dependencies in the template. Field B has a dependency of field A, but A was after B. I changed the field order from B, A to A, B and now it works.
  8. Today I have discovered that my options fieldtype doesnt store any value. It had been working in the past as expected. I have updated to the latest dev version 2 days ago. If I want to select one or more options in that fieldtype the storage doesnt work anymore. It will be empty after pressing the save button. I use following options under the details tab: 1=user|persönlich 2=phone|telefonisch 3=envelope|per E-Mail 4=list-alt|per Anmeldeformular Does anyone has the same problem? Best regards
  9. I have downloaded the latest version from Github today but the modal closes and saves after there are errors. In my case I have a field which is mandatory and the modal will be closed after pressing the save button and the field is empty. The fieldtype in this case is a options field with 4 checkboxes. One must be checked at least (required). In backend I get the error message that this field is required. Best regards
  10. I changed the code a little bit. I dont use children in this case and now it works. <?php class AddCronJob extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Cron jobs for various functions.', 'version' => 100, 'summary' => 'Executing cron job tasks depending on time set', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('LazyCron::every30Seconds', $this, 'ChangeOfferPages'); } public function ChangeOfferPages(HookEvent $e) { $seconds = $e->arguments[0]; $currentdatetime = time(); // Get timestamp for current date $pricelistpages = wire("pages")->find("template=productpricelistitem"); //get the page with the price template foreach ($pricelistpages as $pp) { $pp->setOutputFormatting(false); // without this we can't save the page later on $offerend = $pp->getunformatted(offerend); if ($offerend) { if (($pp->afterofferend == "1") AND ($offerend < $currentdatetime)) { $pp->pricetype = "1"; //set back price type to standard price $pp->offertprice = ""; //delete offerprice $pp->offerstart = ""; //delete offerdate start $pp->offerend = ""; //delete offerdate end $pp->save(); //save the price page } } } } }
  11. I am also interested in this. I still haven`t found a solution `til now.
  12. Question: How can I approve comments via email if the comments list is custom? Hello @ all, I use a custom code to show the comments in my own markup as described here (documentation of the comments). All works fine, but if a comment is approved via an email it doesnt change the status to approved. In the commentlist.php the following lines of code could be relevant. public function renderCheckActions() { $action = $this->wire('input')->get('comment_success'); if(empty($action) || $action === "1") return ''; if($action === '2' || $action === '3') { $message = $this->wire('session')->get('CommentApprovalMessage'); if($message) { $this->wire('session')->remove('CommentApprovalMessage'); $class = $action === '2' ? 'success' : 'error'; $commentID = (int) $this->wire('input')->get('comment_id'); $message = $this->wire('sanitizer')->entities($message); if($commentID) $message = str_replace($commentID, "<a href='#Comment$commentID'>$commentID</a>", $message); return "<p id='CommentApprovalMessage' class='$class'><strong>$message</strong></p>"; } } Does anyone have tried to make a custom comment list which works with email approval and how? Best regards
  13. Problem solved: I deinstalled and reinstalled the comments and now it works. The problem was that the database was not updated, so comments rating could not be stored.
  14. Does no one have a hint why the values of the fields will not be changed after the cronjob had been triggered? Here is the complete module code: <?php class AddCronJob extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Cron jobs for various functions.', 'version' => 100, 'summary' => 'Executing cron job tasks depending on time set', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('LazyCron::every30Seconds', $this, 'RunOfferPages'); } public function RunOfferPages(HookEvent $e) { $currentdatetime = time(); // Get timestamp for current date $pricelistpages = wire("pages")->find("template=products"); //get the parent page with the product template $pricelistpages->setOutputFormatting(false); foreach ($pricelistpages as $pp) { $pp->setOutputFormatting(false); // without this we can't save the page later on $childpages = $pp->children("template=productpricelistitem"); //get the children with the productpricelistitem foreach ($childpages as $p) { $p->setOutputFormatting(false); // without this we can't save the page later on $offerend = $p->getunformatted(offerend); if ($offerend) { if (($p->afterofferend == "1") AND ($offerend < $currentdatetime)) { $p->pricetype = "1"; //set back price type to standard price $p->offertprice = ""; //delete offerprice $p->offerstart = ""; //delete offerdate start $p->offerend = ""; //delete offerdate end $p->save(); //save the price page } } } $pp->save(); //save the productpage } } }
  15. Cron job stops working for now For testing purposes I added Ryans example code directly in a template to show if cron job triggers. // create your hook function function myHook(HookEvent $e) { echo "30 Minutes have passed!"; } // add a hook to your function: wire()->addHook('LazyCron::every30Minutes', null, 'myHook'); It outputs nothing, if this code is directly in a template, so it seems that cron job doesnt work at all. The template is not cached!!!!
  16. It works now, I have changed the code to: foreach($pricelistpages as $pp) { //start foreach $pp->setOutputFormatting(false); // without this we can't save the page later on $childpages = $pp->children("template=productpricelistitem"); foreach($childpages as $p){ $p->setOutputFormatting(false); // without this we can't save the page later on $this->message("Kind"); if($p->offerend){ if(($p->afterofferend == "1")AND(($p->offerend)<$currentdatetime)){ //set back to standard price after offerend $p->pricetype = "1";//set back price type to standardprice $p->offertprice = "";//delete offerprice standardprice $p->offerstart = "";//delete offerdate start $p->offerend = "";//delete offerdate end $p->save();//save the price page } } //end foreach } $pp->save();//save the productpage } } As you can see I inserted $p->setOutputFormatting(false);
  17. You mean $p->setOutputFormatting(false); $p->pricetype = "1";//set back price type to standardprice for every field value that should be changed via the cron??
  18. Hello @ all, I have a product page and several price pages as children. Here is the structure: - Product -- Price 1 -- Price 2 -- Price 3 -- etc Product is the parent page and the price pages are all children. The product page is linked and you can call it directly over an URL. The children pages (sub pages) are part of the product page, but you cannot call it directly with a link. Goal: I want to use lazy cron to change some values in the children pages (fe set another price at a date in the future) I have a module where I have place all the code, but there were no changes in the children pages after lazy cron is triggered. Here is my code: public function init() { $this->addHook('LazyCron::everyMinute', $this, 'RunOfferPages'); } //RUN CRONJOB //OFFER PRICES public function RunOfferPages($event) { $currentdatetime = time(); // Get timestamp for current date $pricelistpages = wire("pages")->find("template=products"); foreach($pricelistpages as $pp) { $children = $pp->children("template=productpricelistitem"); foreach($children as $p){ if($p->offerend){ if(($p->afterofferend == "1")AND(($p->offerend)<$currentdatetime)){ //set back to standard price after offerend $p->pricetype = "1";//set back price type to standardprice $p->offertprice = "";//delete offerprice $p->offerstart = "";//delete offerdate start $p->offerend = "";//delete offerdate end $p->save();//save the price page } } } $pp->save();//save the productpage } } I guess this line of code doesnt grab the children: $children = $pp->children("template=productpricelistitem"); I have used cron for parent pages and it works, the problem is only at children pages. It seems that they wont be affected with these lines of code. Has someone an idea how to make it work on childpages - I cannot call them directly to trigger the cron job because they are only a part of the parent page. Thanks in advance
  19. Thanks Wanze and LostKobrakai, I changed the path to /home/.sites/24........ (absolute path) and now it works. It was a path problem. Why it works in the past with the old path - ?? Problem solved! Best regards
  20. Hello Stefan, I am using the latest dev 2.7.2 and PHP 5+. The var-folder is in the root, but this was not a problem at all. Here are some screenshots of uploaded files in the past, which are still located in the folder: As you can see the files are still there. As I pointed out - the folders have permission 777 (only for testing) so they are writeable in any case and they are still there. Best regards Jürgen
  21. Another problem: Cannot upload files with the latest version 1.0.1 of secure files. I have detected that upload of files is no longer possible with this field type in my case. I cannot point out the exact time when this problem starts because I havent upload secure files for a longer time. In the meantime I have updated PW more times. The upload has worked in the past but now I get the error message, that the folder doesnt exist or is not writeable. I store all the files in the folders var/securefiles and these folders exist: All folders has the permission 777 for testing purposes My settings of the input field: And this is what I got if I had tried to upload a file: Help would be appreciated Best regards
  22. Oh, I have installed it a longer time ago, so I have forgotten that it is not in the Modules directory right now. Adding a "add new page" feature would be awesome!!!!
  23. Thanks for the changes! BTW if you have time, it would be great if you add update information to the module so it would be fetched by PW updates. At the moment FEEL doesnt appear under this section and I have to look manually if an update is available or not. I hope it is understandable what I mean Best regards Jürgen
  24. I dont know what you exactly need in your guestbook but why dont you use the comment field as a guestbook? You can style it in the way you want with overrides.
  25. Thanks for your answeres - I guess the CSS solution would be the easiest in this case.
×
×
  • Create New...