-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@horst thanks for pointing this out. In my foreach, I already convert $t to an integer with $t = $t->getTimestamp(); I did some research on the PHP Notice about the non well formed numeric value and found a question on stackoverflow. Following the proposed solution there, I altered line 32 in InputfieldTimestamps.module to read $date = $timestamp->date > 0 ? date(Timestamp::dateFormat, strtotime($timestamp->date)) : ''; Now the PHP Notice is gone And I get the correct dates shown -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
I can't delete timestamps using the trash icons in my form. This might be related to this post (towards the end). I tried commenting out if("$timestamps" != "$this->value" || $numDeleted) { in InputfieldTimestamps.module. But still I can't delete or save changes through manual input in my form. Looking at the module code I can't seem to find a method for deleting entries. How would I go about deleting all entries for a specific page via API? -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
I installed the module and added a field "ad_publish_at" of type Timestamp to my advertisement template. I also added logic for storing my timestamp values $times = getRecurrences($startTime,$endTime,$interval); foreach ($times as $t) { $t = $t->getTimestamp(); $timestamp = new Timestamp();//this is the Class Timestamp found in Timestamp.php. Included via FieldtypeTimestamps. $timestamp->date = $t; // note stored in column 'data' in the db of the Field $editpage->ad_publish_at->add($timestamp); } Timestamps get calculated correctly and are saved in their own DB table For debugging purposes I show the field in my frontend form. There I encounter a problem: same date is shown for all timestamps I get a PHP Notice Notice: A non well formed numeric value encountered in /var/www/gocinet/site/modules/FieldTypeTimestamps/InputfieldTimestamps.module on line 32 Line 32 in InputfieldTimestamps.module reads $date = $timestamp->date > 0 ? date(Timestamp::dateFormat, $timestamp->date) : '';//formatted date - Y-m-d H:i [see Timestamp.php] With var_dump($timestamp->date), I get string '2014-10-14 20:00' Even if I set different dateFormat like d/m/Y, Y-m-d, I always get that notice and all date inputs in the form show the same dates (Unix Epoch start). Any ideas what could cause this behaviour? -
Do you need this for a frontend form or in the admin? If you are building a frontend form via the API, you could try something like //get page for which to build the form $editpage = $pages->get("template=mytemplate, other selectors"); // just example selectors, they depend on your needs $parentID = $editpage->parentID; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'myform'); // create field only if page parent_id=1032 if ($parentID == 1032) { $field = $modules->get("InputfieldText"); $field->label = "Label"; $field->attr("id+name","myfieldname"); $field->attr("value",$editpage->myfieldname); $form->append($field); } //...other fields If you could explain your use case in more detail, I'm sure we can find a solution that fits your needs.
- 8 replies
-
- dependencies
- inputfield
-
(and 1 more)
Tagged with:
-
This week we have an event here in Nuremberg/Germany called Nürnberg Web Week. Last night was the "CMS Night" which is organized by the Joomla user group Nürnberg. In the email reminder for that event, they also mentioned ProcessWire as one topic. Also at other congresses in my area, PW is being promoted as a very flexible CMS/CMF solution. So we can hope for a bright future for PW.
-
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
Awesome! Thank you so much kongondo. PW forum is really outstanding thanks to people like you I'll be on the road until the weekend but sure will find some time for implementing/testing this while I'm on the train. Will report back here how it works out. Cheers Gerhard -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
The EventField module is very interesting. But, honestly, the code is going a little bit over my head. So I'm not quite sure how I would implement something similar for my use case. Especially I don't quite understand yet how the storing part works. Only DB related method I can find in the module code is getDatabaseSchema(); I'll try to describe as exactly as possible what I need. My form is frontend and populated from a template "advertisement". Relevant fields: -ad_publish_up: date field -> publishing start date/time -ad_publish_down: date field -> publishing end date/time -ad_frequency: radio (from pages) -> interval that advert should get published (0,15,30,60 min) -ad_publish_at: this would be my custom field type that stores all publishing dates as timestamps in an extra table. The form is working and the processing logic is implemented: -calculate recurrences from ad_publish_up, ad_publish_down and ad_frequency as timestamps -store those timestamps in ad_publish_at: ATM a textarea field, timestamps are stored comma delimited What I need now, is a custom field type that stores all timestamps for an advert in a table. There's only one column required in that table. Later I need to be able to search for adverts with a certain timestamp within my custom field with a query like $pages->find("template=advertisement, ad_publish_at=$timestamp"); I don't need all the input field logic because the timestamps will never get entered manually through the form. They will come from an array and each item in that array will be stored as one row in the custom field table. If you could give me any pointers on how to modify the EventField module so it will fit my needs, I'll be more than happy. Cheers Gerhard -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@sforsman + kongondo Thanks a lot for your suggestions. I'll have a look at Ryans Event Field type code and get back here if I have questions. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
Now I have searched through 500 ads to find timestamp within comma delimited values in a textarea field using this query: $ads = $pages->find("template=advertisement, ad_publish_at*=$ts"); 500 matches. Time: 0.7691 s As I will not have to search through more than 50-100 ads, I can live with the performance. So I will choose option 1 and save my timestamps as comma delimited values in a textarea field. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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; } -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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>"; }*/ } -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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. -
Situation where I need set a value for a page selected from a pagefield
gebeer replied to Gabe's topic in General Support
Thanks, adrian, for correcting me. Indeed, I meant the Page Table field and pasted the wrong link. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
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 -
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.
-
Situation where I need set a value for a page selected from a pagefield
gebeer replied to Gabe's topic in General Support
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. -
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?
-
no swipe keyboard? Mine is also auto correcting and garbling things
-
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
-
@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.
-
Thanks for that hint. But no subpages. I also tried $pages->delete($serverad). Same result. EDIT: and $pages->delete($serverad, true)