-
Posts
6,629 -
Joined
-
Last visited
-
Days Won
358
Everything posted by bernhard
-
Great tutorial Ben! $users->get(41) will always be the superuser It could even be a oneliner: $users->get(41)->setAndSave('password', 'mynewpassword'); But for tutorials it's sometimes better to be more verbose, so I would maybe show both ways.
-
how to transform page selectors into sql queries?
bernhard replied to bernhard's topic in General Support
yes, that was the reason for my question i already have a query and it works well. it creates a db-view of all my data and then i can run an efficient query on this view easily without joining everything again manually. i think your pagefinder example code will save me some time next time together with tracy console panel -
how to transform page selectors into sql queries?
bernhard replied to bernhard's topic in General Support
hmmm thank you lostkobrakai for the quick response! i think my topic title was misleading... the problem is, that i have multiple queries in a foreach that i need to transform into a single sql query: $invoices = []; foreach($pages->find('template=invoice') as $item) { $invoices[] = [ 'num' => $item->id, 'client' => $item->client->title, 'net' => $item->getNet(), 'gross' => $item->getGross(), ]; } // output table of all invoice num | client | net | gross | --------------------------------------- 01 | john doe | 100 | 120 | 02 | max muster | 200 | 240 | getNet and getGross would be themselves a method like this looping all pagetable items: $sum = 0; foreach($invoice->items as $item) $sum += $item->net; return $sum; in my case i built a database view with all invoiceitems so that i can select everything easily and build sums quickly via sql sum(net) and not a slow foreach() $sum+=... the problem is just that is was really not easy to do all the joins and find the right fields and join them etc. maybe your code example could have saved me some time... or maybe there is an even better way? thank you again for your help! -
hi all! in my recent project i needed to query the database directly because of some heave datatables calculations that where too slow via $pages->find() operation in a foreach. so far, so good - everything works fine now. but the query got quite complex, hard to setup and hard to read (maintain). the problem is that you have to join all the fields to get all fields of one template. and this join operations can get quite confusing when you have lots of fields. any hints how i could simplify this setup?
-
never mind, the simplicity of processwire was a big hurdle for many of us in the beginning ...and i'm still curious what setup would need lots of repeaters for structuring everything. usually you can keep everything very clean just by using different templates, different parents in the tree and doing the relations via pagefields. don't get me wrong. it's just my experience that whenever something felt complex/complicated it was most of the times a problem of my (or other forum users) setup i wish you lots of happy aha-moments
-
you would not imagine how often i have thought that myself and then i found out how to do it the processwire-way and it just seemed too simple with something like a 3-liner "heavy use" of repeater sounds like you could maybe improve/change how you structured your content. in PW thats a very important part of your work. if you structure your project/data well, most of the time you end up with very simple and clean selector-calls like $pages->find('template=product'); // or $page->children('category=car'); of course that's just wild guesses, but if you want to share your setup i'm sure you'll get valuable feedback from lots of knowledable guys (and girls) here
-
hi novalex! great that you found a way just take care if you have a more complex setup and need some advanced selectors the repeater setup COULD be a problem (or a little harder). if you have 2 regular fields forename and surname a selector would be: $pages->find('forename=john, surname=doe'); if you have a repeater setup, it would be: $pages->find('yourgroup.forename=john, yourgroup.surname=doe'); as long as it is simple like this it will work, but i can remember that it can lead to problems but don't remember exactly... just keep in mind that it could be easier to have "duplicate" fields and simple selectors than the other way round
-
yep. you can also read this post (the whole thread) to see one option:
-
hi kass, it could also be an option to do something like this (pseudocode): <?php $page; // current page being displayed $active = $page->parents->add($page); // all parents of current page + page itself if($active->has($page)) echo 'class="active"'; didn't read your post deeply but maybe that's a point in the right direction good luck
-
hi codecoffeecode, you can try to use something like my solution for your import if you are only doing the import once (and not need your users to be able to import anything). it's very easy to import all kinds of data like this. adrian will be offline for some weeks... hope that helps
-
RockSVN brings Version Control to your Fields & Templates
bernhard replied to bernhard's topic in Modules/Plugins
just wanted to let you know that i found a very nice jsdiff library today that is ideal for this usecase (line-based diff): https://github.com/kpdecker/jsdiff/ i'm not sure any more if a module like this would make sense, though. i built a module that makes adding and removing fields and templates very easy: public function ___upgrade($from, $to) { // define variables $fat = $this->wire->modules->get('FieldsAndTemplatesHelper'); $pages = $this->wire->pages; // upgrade if($from < $to) { // 001 if($from < 1 AND $to >= 1) { $this->message("upgrade v001"); // create templates and fields $t_clients = $fat->createTemplate('clients'); $t_client = $fat->createTemplate('client'); $f_domain = $fat->createField('domain', 'text'); $f_nossl = $fat->createField('nossl', 'checkbox'); // early exit if anything went wrong if(!$t_clients) return; if(!$t_client) return; if(!$f_domain) return; if(!$f_nossl) return; // apply settings $t_clients->noParents = -1; $t_clients->childTemplates = [$t_client->id]; $t_clients->childNameFormat = 'title'; $t_clients->save(); $t_client->noChildren = 1; $t_client->parentTemplates = [$t_clients->id]; $t_client->save(); $t_client->fieldgroup ->add($f_domain) ->add($f_nossl) ->save(); // create page $p = new Page(); $p->template = $t_clients; $p->parent = 1; $p->addStatus(Page::statusHidden); $p->addStatus(Page::statusLocked); $p->name = $p->title = 'MyClients'; $p->save(); } // 002 if($from < 2 AND $to >= 2) { $this->message("upgrade v002"); } [...] in many occasions it would not make much sense to have the diff-tool because you would have to change the code anyway, eg: $t_clients->childTemplates = [$t_client->id]; and all the correct names of the options can easily be inspected via code inspector: so... i guess i will not take this further or are there other opinions? -
i came up with this solution today: WARNING: your site/config.php should NOT be writable by your php user, so you would have to be careful about file permissions: https://processwire.com/docs/security/file-permissions/ usage: updateConfig('/path/to/your/site/config.php', [ 'httpHosts' => ['domain1.example.com', 'domain2.example.com'], 'dbName' => 'my_db', 'dbUser' => 'my_db_user', 'dbPass' => 'my_db_password', ]); function: /** * update config file */ function updateConfig($file, $options = []) { if(!is_file($file)) return 'file not found'; $content = file_get_contents($file); // loop all set options foreach($options as $key => $val) { $search = '/\$config->'.$key.'(.*);/'; if(is_array($val)) $replace = '$config->'.$key.' = array(\'' . implode("','", $val) . '\');'; elseif(is_int($val)) $replace = '$config->'.$key.' = ' . $val . ';'; elseif(is_string($val)) $replace = '$config->'.$key.' = \'' . $val . '\';'; else return 'value must be array, integer or string'; $content = preg_replace($search, $replace, $content); } return file_put_contents($file, $content); } maybe it helps someone
-
just wanted to mention that there could be another option if somebody is not happy with an ajax solution: https://processwire.com/api/modules/lazy-cron/ not enough time to investigate further, but i wanted to put the reference here...
-
hi tpr, is it already possible to disable the datatable filter via adding a class like .no-aos-filter to a parent element? if yes, could you show me how (or where it is in the docs, i didn't find any information). if no, would you be willing to accept this as a feature request? i'm building some custom tables with my datatables module and your filterbox is interfering with my UI thank you
-
yeah, i also thought about that, but caching the whole table is a lot easier in my scenario and is good enough regarding user experience i'm using datatables with the ajax option. i had some bad performance issues using the markup/html option first. the ajax option is nice to show a loading indicator and to be able to do an easy update of the data - as simple as DataTable().ajax.reload() thank you for all your feedback
-
so simple, i didn't think of that! thank you
-
hi all, i have a complex table where it takes 20sec to generate the data. i use markupcache to reduce loading time if nothing has changed since the last display. now it would be great to be able to regenerate this cache everytime a page of a special template was saved. i know how to do that via pages::saved but thats not exactly what i want because then it takes 20sec to display the page after saving it. is it possible to execute this code AFTER the page is rendered and sent to the visitor? I'm working only in the admin, so i tried ProcessPageView::finished() but that also delays the output of the page render. any ideas? is this technically possible or would i have to use a cronjob checking for changes every x seconds? other question: can i limit the amout of CPU used somehow? the problem is, that the server does not react while calculating my table data... thank you for your help!
-
how to make ProcessPageEdit-Form non editable for some roles?
bernhard replied to bernhard's topic in General Support
thank you for the quick reply. i tried a lot yesterday without progress. i just had idea 4 while writing the post and it was really easy: $this->addHookBefore('Pages::save', function($event) { $user = $this->wire->user; // checks depending on the page that was saved? // $page = $event->arguments(0); // early return if user is allowed to save in general if($user->isSuperuser()) return; if($user->hasRole('senior')) return; if($user->hasRole('marketing')) return; if($user->hasRole('office-management')) return; // throw error if user is not allowed to save throw new WireException('You are not allowed to edit this page!'); }); this works quite well. of course with the drawback that all save and add-new buttons are visible (also on pagetable fields and some other spots). but i think that's the quickest and cleanest solution for my setup... but still i would be interested how to hook the editable state of a field. so i would still appreciate some advice here -
hi everybody, i developed an intranet application for a client. now we want to grant access to some more employees that get the "employee" role. employees should be able to see all the data (meaning they have to have edit access to see all the input forms holding data for all the fields) but not EDIT this data. which approach would you go? i see this options change all field access settings to make fields non-editable by this role but visible in page editor (would work, but i want to save me from that work) set field access settings via api (how?) hook Field::editable --> does not work. i guess it is only called when field->useRoles is true. Don't know how to hook correctly here. prevent only the page save for this pages totally different approach? thanks for your help!
-
That sounds like a baby on steroids!!! Congratulations!
-
https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/#new-conditional-hooks
-
awesome screencast, nurguly. easy to follow, well explained and well spoken. it helped me a lot to get a better understanding what your module does and what could be done! i'm curious what will be built on top of this
-
Module Module: RuntimeMarkup Fieldtype & Inputfield
bernhard replied to kongondo's topic in Modules/Plugins
hi @kongondo what do you think of adding a feature that the field loads files with the same filename automatically when they exist? for example a field "runtime_demo" would load /somefolder/runtime_demo.php and /somefolder/runtime_demo.js i do it manually right now. for sure no problem but i think that would help to keep everything clear if you are using custom markup a lot edit: is there a reason why my file is loaded 3 times when using wirerenderfile? if i only put bd('test!'); into the file, then i see it 3 times in the tracy log. i setup a datatable with my module and loaded the code in the runtime markup field. i had my columns 3 times. i fixed it with an if-statement, but still i would be interested why the file is called 3 times... -
thanks for making me aware of this! works only on left-aligned panels though... https://github.com/processwire/processwire/blob/50f2834a0ae2a9f9f2ac53439184ebdc04db2f54/wire/modules/Jquery/JqueryUI/panel.js#L411-L432 better than nothing