Jump to content

gebeer

Members
  • Posts

    1,393
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by gebeer

  1. Results for saving 581 timestamps: 1. save as comma delimited values in a textarea field: 0.0258 s 2. save each in a page (create and sve 581 pages): 18.1477 s So clearly, option 1 would be the way to go for saving timestamps. Next I will benchmark search times and add them to this post. Search results 1.Searching through 5 pages to find a timestamp inside a comma delimited list (about 600 timestamps) with this query. 5matches. $ads = $pages->find("template=advertisement, ad_server={$serverID}, ad_publish_at*=$ts"); 0.0264 s 2. Searching through 2600 pages to find the timestamp. with this query. 5 matches. $ads = $pages->find("template=publishing_schedule, publish_at=$ts"); 0.0200 s I will have to create some more ads to see how option 1 performs when more pages need to be searched. But ATM it looks like I will go with option 1 because it is significantly faster when saving timestamps.
  2. Thanks for the link to the debug class. I found two posts that show how to use the Debug::Timer() method here and here. Will use those examples in my code for benchmarking my searches and get back with results here.
  3. Update: My function for calculating the recurrences is working fine and producing the correct timestamps. I tried and compared both methods in terms of performance. When I save each timestamp in an extra page together with the advert id, as suggested by netcarver, it takes quite a long time to create and save those pages if I have hundreds of timestamps for one ad. If it gets beyond 1300 or so pages, I get an error Maximum execution time of 30 seconds exceeded I could set a higher limit for the execution time. But then the user would have to wait quite some time until the operation is finished. I need to delete all timestamp pages that belong to an ad when the ad gets edited and the start/end times change, before the new timestamp pages get created. This also takes quite long for 100s of pages. So I also tried option 1 from my first post and save all timestamps comma delimited in a textarea field. This is much much faster when creating/editing an ad. Now I have to benchmark and compare the 2 methods when it comes to searching through the timestamps either as pages or within the textarea. Is there a PW way of showing execution times when $config->debug = true? Couldn't find anything on showing debug info in the frontend except Ryan's post here.
  4. Seems like I'm working too many hours and can't think clearly ATM. Taken my function from above, I could easily calculate the count from it and use that in either when or recurr function getRecurrenceCount($start,$end,$interval) { $format = 'Y-m-d H:i'; $start = DateTime::createFromFormat($format, $start); $end = DateTime::createFromFormat($format, $end); $end = $end->modify( '+1 minute' ); $duration = 'PT' . $interval . 'M'; $interval = new DateInterval($duration); $daterange = new DatePeriod($start, $interval ,$end); $count = iterator_count($daterange); return $count; }
  5. As both, when and recurr do not work for start/end dates but rather need a count for recurring events, I don't really want to use them because I can't get my head around calculating the count from start and end date and my interval. For now I'm using my own function derived from here to calculate my recurring events. It is not really flexible and assumes that you provide the date/time in a specific format and the interval in minutes. This function suits my job and makes use of the PHP DatePeriod Class. function getRecurrences($start,$end,$interval) { $format = 'Y-m-d H:i'; $start = DateTime::createFromFormat($format, $start); $end = DateTime::createFromFormat($format, $end); $end = $end->modify( '+1 minute' ); $duration = 'PT' . $interval . 'M'; $interval = new DateInterval($duration); $daterange = new DatePeriod($start, $interval ,$end); return $daterange; /* to get the timstamps use a loop like this foreach($daterange as $date){ echo $date->format($format) . " : " . $date->getTimestamp() . "<br>"; }*/ }
  6. Thanks, great. I'll test both of them over the next days and will let you know. EDIT: After having a quick look at both libraries, I found that both of them require a count for the recurrence of events. So I first need to calculate the count myself from the data available. Would have been great to just throw start date/time, end date/time and interval at some library and have it figure out the count by itself. (Being lazy again ). Think now I understand count. In recurr FREQ=MONTHLY;COUNT=5 means every 5 months.
  7. Not sure if the when library can handle hourly or even minutely recursion as it is not so well documented. Found recurr library which seems more suitable for my project.
  8. Thanks, adrian, for correcting me. Indeed, I meant the Page Table field and pasted the wrong link.
  9. Thanks a lot, netcarver, for your detailed answer. I think I will go the pages route and save every timestamp as a page. Following your example above, I'd need a pages field type in my advertisement template to store the references to the timestamp pages, right? Or don't store the references and just extend your sample code: $published_at = $pages->find("template=publishing_schedule, published_at=$timestamp, advert_id={$page->id}"); And thanks also for pointing me to the when library. Interesting stuff. Might save me from reinventing the wheel
  10. Hi all, I'm not sure how to best store multiple timestamps in a field for a page. As there can be 100 or more timestamps attached to the page, I need to find the most efficient way to save those timestamps in a field and later search through that field. My use case: I have pages for advertisements with start date, end date and start time, end time and frequency of publishing (every 15, 30, 60 minutes). From that data I calculate timestamps at which the advertisement will be available for viewing. One advertisement can have 100 or more timestamps attached to it. Example: title of page: Advertisement1 field "ad_publish" contains timestamps: 1413136860,1413136920,1413136980,1413137040,1413137100...(can be a lot) Now what would be the best way of storing these multiple timestamps. IOW: what field type to use? I need to take into consideration that the field needs to be searchable with a *= selector like $publishedAds = $pages->find("template=advertisement, ad_publish*={$timestamp}") 2 options that I can think of for my "ad_publish" field: 1. textarea field, store timestamps as comma delimited values. 2. page field: store each timestamp as a page What would be more efficient and faster when it comes to searching through hundreds of timestamps? I'm sure some of you had similar use cases in their projects and I would be happy if you could share your experience or give me pointers on how to best approach this. Thank you.
  11. If I get you right, you need to have a page field where the user can add/remove characteristics and at the same time the user should be able to enter a value for that characteristic. I'm not sure how you could implement this with available PW functionality at the moment, but there is a discussion that seems to be related to your use case: https://processwire.com/talk/topic/7902-ability-to-edit-pages-from-a-page-field/?hl=%2Bpages+%2Bfield+%2Badd+%2Bpages+%2Bapi And also maybe the Profield Page Table may help.
  12. Hello, I'm trying to add a custom description to my formfield $serverField = $modules->get("InputfieldText"); $serverField->label = "Server Name"; $serverField->attr("id+name","servername"); $serverField->attr("value",$prefillServer); $serverField->attr("class","form-control"); $serverField->description("description","Desc");// need right syntax here. Or is the method missing $serverForm->append($serverField); I get an error: Method InputfieldText::description does not exist I looked at InputfieldText.module and there is no method for adding a description. Shouldn't there be one? Couldn't find anything in the API cheatsheet that would let me do that. How would I then go about adding a description to a form field?
  13. no swipe keyboard? Mine is also auto correcting and garbling things
  14. Thank you Soma, now I got you. I moved $serverads = $pages->find("template=advertisement, ad_server={$serverId}"); before $serverpage->delete() And now everything is working
  15. @Soma I already checked that page object for second page is still there after I delete first page. They are independent from another and $serverID is defined before the other stuff and is not related to the first page that gets deleted. $serverpage and $serverad live under different parents in the tree and both never have children.
  16. Thanks for that hint. But no subpages. I also tried $pages->delete($serverad). Same result. EDIT: and $pages->delete($serverad, true)
  17. Nice guide if you want to develop on a physical server. A year ago or so I switched to developing on virtual servers set up with vagrant. They're a breeze to setup and you can carry them with you wherever you go. Recently I discovered protobox which makes it quite easy to setup virtual machines with preinstalled processwire, wordpress or whatever else.
  18. Hi, I want to delete 2 pages with $page->delete() after one another . But only one of the pages gets deleted. My code $serverpage = $pages->get($serverId); if ($action == "delete") { if ($serverpage->id) { $serverpage->delete(); //When I comment this out, $serverad further down gets deleted //if ads for that server exist, delete them $serverads = $pages->find("template=advertisement, ad_server={$serverId}"); if (count($serverads) != 0) { foreach ($serverads as $serverad) { if ($serverad->id) $serverad->delete(); //does not get deleted when $serverpage->delete() above executes. } $serverout .= "<div class='alert alert-success' role='alert'>All Ads for the server deleted.</div>"; } $serverout .= "<div class='alert alert-success' role='alert'>Server successfully deleted.</div>"; } else { $serverout .= "<div class='alert alert-danger' role='alert'>Server does not exist and could not be deleted.</div>"; } $serverout .= $serverForm->render(); } When $serverpage->delete() is executed, $serverad->delete() has no effect. When I comment out $serverpage->delete(), $serverad->delete() is working. I don't get any errors and I already checked that $serverad is a valid page object in all cases. Now I'm clueless of what the problem might be.
  19. Thanks for that link kongondo. It really helped. When I do print_r($GLOBALS), I get: [_POST] => Array ( [name] => Test [uname] => test1 [regemail] => my@email.net [pass] => [_pass] => [sort_repeater1708] => 0 [publish_repeater1708] => 0 [_disable_repeater1708] => 1708 [servername_repeater1708] => [sort_repeater1709] => 1 [publish_repeater1709] => 0 [_disable_repeater1709] => 1709 [servername_repeater1709] => [sort_repeater1710] => 2 [publish_repeater1710] => 0 [_disable_repeater1710] => 1710 [servername_repeater1710] => [sort_repeater1711] => 3 [publish_repeater1711] => 0 [_disable_repeater1711] => 1711 [servername_repeater1711] => [sort_repeater1712] => 4 [publish_repeater1712] => 0 [_disable_repeater1712] => 1712 [servername_repeater1712] => [_reg_servers_add_items] => 0 [timezone] => Europe/Berlin [submitregistration] => Register Account [TOKEN609710988X1412858909] => VehDxck9zIEvN191SQ5G.1HKmG0EeQG41 ) Now I process $_POST with the function from the linked post. $servers = getMultiDimensional($_POST, "servername_repeater"); And get back my array Array ( [1798] => A Server [1799] => Another Server [1800] => And one more Server [1801] => [1802] => ) Now I can go on from there and process my values.
  20. Hello, I'm building a form through the API. In that form I am using a repeater field that is setup with 5 Ready-To-Edit New Repeater items. In the repeater is only one text input field named "servername". Now I'm having trouble accessing the repeater field values when I process the form. I read through the docs at https://processwire.com/api/fieldtypes/repeaters/. But when processing form input post values things seem to be different. I add the field to the form with: $registrationField = $fields->get("reg_servers")->getInputfield($pages->get("/registration")); $registrationField->attr("class","form-control"); $registrationForm->append($registrationField); The field is there in the form and working fine. Now when processing the form, I need to access the values of my repeater. Here's the relevant code: if($input->post->submitregistration) { $registrationForm->processInput($input->post); $servers = $registrationForm->get("reg_servers")->value; var_dump(count($servers)); // this gives int 5, which is fine foreach ($servers as $server) { echo "<pre>"; print_r($server->fields->servername); //servername is my text input field in the repeater echo "</pre>"; } exit(); } In the print_r output I can't find the value of my fields. I also tried var_dump($server->servername) and var_dump($server->servername->value) inside the foreach which gives an empty string. var_dump($server->fields->servername->value) gives null. How can I access my field values?
  21. GOT IT: After moving the $jsConfig script part to the head of my _main.php template file, I don't get the console errors anymore and I have a shiny CKEditor interface attached to my textarea
  22. I followed this thread carefully but still cant get CKEditor to work on the frontend. I'm building my form through the API. My setup: <script> <?php $jsConfig = $config->js(); $jsConfig['urls'] = array( 'root' => $config->urls->root, 'admin' => $config->urls->admin, 'modules' => $config->urls->modules, 'core' => $config->urls->core, 'files' => $config->urls->files, 'templates' => $config->urls->templates, 'adminTemplates' => $config->urls->adminTemplates, 'adminTemplates' => $config->urls->adminTemplates, ); ?> var config = <?php echo json_encode($jsConfig); ?>; </script> <?php $modules->get('JqueryCore'); $modules->get('CKEditor'); //$modules->get('InputfieldCKEditor'); //$config->styles->prepend($config->urls->adminTemplates . "styles/main.css?v=2"); $config->styles->append($config->urls->adminTemplates . "styles/inputfields.css"); $config->styles->append($config->urls->adminTemplates . "styles/ui.css?v=2"); $config->scripts->append($config->urls->JqueryUI . "JqueryUI.js"); $config->scripts->prepend($config->urls->JqueryCore . "JqueryCore.js"); $config->scripts->append($config->urls->adminTemplates . "scripts/inputfields.js"); So I think I'm loading everything necessary and in the correct order. Even when I switch $modules->get('InputfieldCKEditor'); for $modules->get('CKEditor');, the editor doesn't show. I get console errors: Uncaught TypeError: Cannot read property 'editors' of undefined (index):111 Uncaught TypeError: Cannot read property 'plugins' of undefined InputfieldCKEditor.js?v=128:16 line 111 is <textarea id="Inputfield_ad_content" class="FieldtypeTextarea InputfieldMaxWidth" name="ad_content" rows="5"></textarea> All scripts are loaded and visible in the resources tab of chrome debug console. Now I'm lost and any pointers to a solution would be great.
  23. I don't know about bumping the limit further up. But when setting up file downloads, there are some useful functions in the API that you could use. E.g. if you want to allow downloads only for certain users. Here's a post that helped.me.out: https://processwire.com/talk/topic/3634-down-uploads-on-a-per-user-policy/
  24. Thanks again. That helped. I'm using the API to build my forms. They have different names and ids already. When I create the submit button like // submit button! $submit = $modules->get("InputfieldSubmit"); $submit->label = " "; $submit->attr("value","Save Changes"); $submit->attr("id+name","submitprofile"); //Notice submitprofile here - that did the trick $submit->attr("class","btn btn-success"); $profileForm->append($submit); and check if data should be processed with if ($input->post->submitprofile) { //do processing here } It is working and other form submissions do not interfere anymore
  25. Each form has its own. I meanwhile checked that post data is only available for the form that was submitted. So the problem seems to be in my form processing logic somewhere. I will first try myself and find that problem and then report back here. Thank you so far kongondo.
×
×
  • Create New...