Jump to content

Jan Romero

Members
  • Posts

    612
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by Jan Romero

  1. What exactly is the behaviour you see on mobile? Maybe it’s some kind of caching issue?
  2. Hi @Larhendiel, there appears to be some custom abstraction that is not part of ProcessWire called "MenuItem". There should be a place where these MenuItem objects are used to generate the actual markup ("<a href" etc.). You may be able to just hardcode your external link there, or build something that aligns more closely with the current system. From the look of it, a MenuItem takes a Page object to generate a link, so unless there already is a way to give it an external address, you’ll have to build it yourself. If you need more concrete assistance, please post the class definition of MenuItem and the code that renders the menu markup (please use the code function for this, it’s the button with the "<>" symbols on it).
  3. $page->select_categories is a PageArray (multiple values can be selected), so you can’t compare it to "unternehmen". Try $page->select_categories->has('name=unternehmen').
  4. I don’t know what’s going wrong, but maybe I can contribute a couple of things. Firstly, a more readable version of your code: include("/html/index.php"); // bootstrap ProcessWire // Get derefAsPage property of page_field_b to distinguish multiple/single page fields $deref = $fields->get('select_related_articles')->derefAsPage; // […] some stuff appears to have been omitted here ($pgs) foreach ($pgs as $p) { // For this page, get the pages selected in page_field_a $selected_pages = $p->select_author; // Standardise $selected_pages to PageArray in case of "single" field if ($selected_pages instanceof Page) $selected_pages = $selected_pages->and(); foreach ($selected_pages as $selected_page) { // Add this page to page_field_b on the selected page $selected_page->of(false); // <-- This is the offending line if ($deref) { $selected_page->select_related_articles = $p; echo "Set $p \n"; } else { $selected_page->select_related_articles->add($p); echo "Added $p \n"; } $selected_page->save(); } $numPgs--; echo $numPgs . "\r"; } Secondly, I don’t think you even need to turn off output formatting explicitly, because it’s off by default in this bootstrapped context. Lastly and probably most relevant, the error message tells you that $selected_page is an integer when you try to call of(false) on it. I don’t really see how that would happen given your code, but maybe just dump its value here and there to figure it out? Since it’s the value of a page reference field, it should be Page (perhaps a custom page type), NullPage or PageArray. Btw, if it is a Page or NullPage object and you call and() on it, you’ll get a WireArray, not a PageArray.
  5. Maybe this helps? https://whatsmychaincert.com/?test2.gemeindeguru.at I wish I knew more about this stuff 🙄
  6. I think the problem is here https://github.com/processwire/processwire/blob/924f93214536a506babbce1bab5c6c9e2093fc1e/wire/core/WireHttp.php#L471 See how it sanitizes the url at the top of the function. That’s where it prepends the scheme if necessary. Curl and fopen are called with that sanitized url, but your error came from the "socket" method, which seems to be called with the unsanitized url. I’m probably missing something, but I’m not going to look into this any more deeply from my phone 😄
  7. Not at a computer right now, but the error should have the host name in it (where the two spaces collide instead, and before the :80 port). Apparently something went wrong inside wireHttp->get() where it parses the url string. Indeed, url_parse() doesn’t return the right components when given "test2.gemeindeguru.at". I think you’re required to pass the url including the protocol.
  8. Well, I have only tested it with the "Default" admin theme (is that even still the default or new installations?) and only in Firefox. Also, while I doubt the CSS changes have any unintended consequences, it would be cleaner to refactor the gridImage__trash class to something more generic. I guess just renaming it would suffice for a start, but it clearly wasn’t made to hold a simple link. You’re too kind 🙂
  9. I’ve made a different wild guess https://github.com/JanRomero/processwire/commit/1641e1681ae20fb01ca0ec3568da0832fb3337b1 It’s messed up because my editor uses spaces by default and PW uses tabs, also I did it on the master branch because I’m an idiot, but whatever. Works okay, looks like this: And this is the list view: I would not merge this though 😉 Edit: oh yeah because it uses an <a> inside the <label> you have to hit the icon quite precisely, even though the cursor changes over the whole label. Well, I don’t mess with SCSS… @bernhard Thanks for the like, finally I’m a hero member 😄 Took me long enough
  10. I do: Added "download" to the labels array at the top, and "class='$modalButtonClass'" to the button. This still requires several clicks, though. First, unless you’re already in the list view, you have to open the image to see the button, then the button will just open a lightbox where you can right click -> save as (you can’t do it on the button because it’s a button element).
  11. What TextFormatter are you using? The Parsedown formatter for example will wrap indented blocks in <pre><code></code></pre> tags. It will also give the code tag a class if you use backtick syntax and specify a language: Will turn into: <p>Some prose text.</p> <pre><code class="language-SQL">select * from pages p left join field_title t on p.id = t.pages_id where p.templates_id = 69</code></pre> <p>More prose.</p> Then you can use the class to apply syntax highlighting.
  12. Can you not do this? $cl = $languages->get($user->language->name); $blog_title = empty($page->getUnformatted('title')->getLanguageValue[$cl]) ? 'Look Ma No Title' //user’s language title is empty : $page->getLanguageValue($cl, 'title'); //user’s language title is not empty The unformatted value of language fields should be a LanguagesPageFieldValue object that you can ask about language values without fallback: https://github.com/processwire/processwire/blob/dev/wire/modules/LanguageSupport/LanguagesPageFieldValue.php
  13. Try this? <?php $events = $pages->find('template=calendar-post'); // populate dayname according to user’s language $grouped = [ 'Mon' => (object)['events' => [], 'dayname' => 'Ponedeljek'], 'Tue' => (object)['events' => [], 'dayname' => 'Torek'], 'Wed' => (object)['events' => [], 'dayname' => 'Sreda'], 'Thu' => (object)['events' => [], 'dayname' => 'Četrtek'], 'Fri' => (object)['events' => [], 'dayname' => 'Petek'], 'Sat' => (object)['events' => [], 'dayname' => 'Sobota'], 'Sun' => (object)['events' => [], 'dayname' => 'Nedelja'] ]; foreach ($events as $event) { $dayname = date('D', $event->getUnformatted('Start_date')); $grouped[$dayname]->events[] = $event; } ?> <div class="tabs movies"> <!-- tab buttons --> <ul> <?php foreach ($grouped as $anchor => $day): ?> <li> <a href="#<?=$anchor?>"><?=$day->dayname?> (<?=count($day->events)?>)</a> </li> <?php endforeach;?> </ul> <!-- /tab buttons --> <!-- tab contents --> <?php foreach ($grouped as $anchor => $day): ?> <div id="<?=$anchor?>"> <?php foreach ($day->events as $p): ?> <div class="row movie-tabs"> <div class="col-md-2 col-sm-3"> <a href="<?=$p->url?>"><img alt="Movie title" src="<?php echo $config->urls->templates?>assets/images/movie-6.jpg"></a> </div> <div class="col-md-10 col-sm-9"> <span class="title">Action, Adventure, Fantasy</span> <h3 class="no-underline"><?=$p->title?></h3> <?=$sanitizer->truncate($p->body, 150);?> <p><a class="arrow-button" href="<?=$p->url?>">Beri več</a></p> <div class="row"> <div class="col-md-8 col-sm-9"> <hr class="space-10"> <span class="viewing-times"><i class="material-icons">access_time</i> Viewing times</span> <span class="time past">14:45</span> <span class="time">18:30</span> <span class="time">20:30</span> <span class="time">24:45</span> </div> <div class="col-md-4 col-sm-3 running-time"> <hr class="space-10"> 105 mins <span class="certificate">15</span> </div> </div> </div> </div> <?php endforeach ;?> </div> <?php endforeach ;?> <!-- /tab contents --> </div>
  14. strftime() is deprecated, you shouldn’t use it anymore. You can use IntlDateFormatter to format localised dates: $weekdayFormatter = new \IntlDateFormatter('es_CO', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, null, null, 'eee'); $events = $pages->find('template=calendar-post'); $grouped = []; foreach ($events as $event) { $dayname = $weekdayFormatter->format($event->getUnformatted('Start_date')); $grouped[$dayname][] = $event; } I wouldn’t really do this because you may get unexpected results and maybe even characters that are illegal in URL fragments (?). For example with de_DE you’ll get “Mo.” and “Lun.” with es_CO. I would probably keep the URL fragments English and have a second localised string. Also, the method above will only give you days that actually have events, so maybe pre-populate the $grouped array with all 7 days.
  15. I see, well, try this maybe? $events = $pages->find('template=calendar-post'); $grouped = []; foreach ($events as $event) { $dayname = date('D', $event->getUnformatted('Start_date')); $grouped[$dayname][] = $event; }
  16. Please use code formatting with the correct language. It’s the „<>“ button in the comment editor. Here it is: <?php $events = $pages->find('template=calendar-post'); $grouped = []; foreach ($events as $event) { $dayname = $datetime->date('%A', $event->Start_date); if (isset($grouped[$dayname])) { $grouped[$dayname][] = $event; } else { $grouped[$dayname] = [$event]; } } ?> <div class="tabs movies"> <ul> <!-- Events by day START --> <?php foreach ($grouped as $dayname => $eventsingle): ?> <li> <a href="#<?= $dayname ?>"><?= $dayname ?></a> </li> <?php endforeach;?> <!-- Events by day END --> <li class="date"><span>Wednesday, 8 March</span> </li> </ul> <!-- Events by day END --> <?php foreach ($grouped as $dayname => $eventsingle): ?> <div id="<?= $dayname ?>"> <!-- EVENT START --> <?php foreach ($eventsingle as $p): ?> <div class="row movie-tabs"> <div class="col-md-2 col-sm-3"> <a href="<?=$p->url?>"><img alt="Movie title" src="<?php echo $config->urls->templates?>assets/images/movie-6.jpg"></a> </div> <div class="col-md-10 col-sm-9"> <span class="title">Action, Adventure, Fantasy</span> <h3 class="no-underline"><?=$p->title?></h3> <?=$sanitizer->truncate($p->body, 150);?> <p><a class="arrow-button" href="<?=$p->url?>">Beri več</a></p> <div class="row"> <div class="col-md-8 col-sm-9"> <hr class="space-10"> <span class="viewing-times"><i class="material-icons">access_time</i> Viewing times</span> <span class="time past">14:45</span> <span class="time">18:30</span> <span class="time">20:30</span> <span class="time">24:45</span> </div> <div class="col-md-4 col-sm-3 running-time"> <hr class="space-10"> 105 mins <span class="certificate">15</span> </div> </div> </div> </div> <?php endforeach ;?> <!-- EVENT END --> </div> <!-- Events by day END --> <?php endforeach ;?> </div> What is $datetime? Also, what is $event->Start_date? That is to say, what types are they?
  17. If you’re running MySql 8 you can use the row_number window function: update pages p inner join (select id, row_number() over (partition by parent_id order by rand()) - 1 as randomsort from pages where parent_id = :YOUR_PARENT_ID) as r on r.id = p.id set p.sort = r.randomsort There may be faster ways to give consecutive sort numbers to random children, but this runs in the blink of an eye (Adminer says 0.005s for my 986 pages). Repeat until you get the order you like. Make sure you set the parent to “manual drag-and-drop” or you won’t see any effect.
  18. Hi, sounds like you want this: (only without the negating “!” in your case)
  19. This is in the selector docs, right were you would expect it ? Granted, the page is pretty long and cluttered when you’re just scrolling through, but it’s great for CTRL+F’ing and the table of contents at the top is very helpful. Mostly “find“ means “I have some criteria, give me any pages that match it” (only those the user may view, by default). “Get” means “I know exactly which page I want, give it to me”. Get gives you one specific page, Find gives you multiple. There is also pages()->findOne() if you only want a single page – the difference here is that this will check if you have access first, while pages()->get() will always give it to you if it exists, even if it’s unpublished or hidden. Anyway, rock on! I’m sure you will be enjoying PW for years to come ?
  20. What you’re doing very much hinges on the stability of your products and the order they’re in between rendering the form and processing its submission. If you open the form in your browser and let it sit there for an hour while you or someone else adds, removes or modifies a product, you will update the wrong products when you get back to the form! This is because you’re using the products’ positions in the selector results to identify them. It would be better to use their IDs or their page names because those are much less likely to change. Consider this: <form method="post"> <?php $products = $pages->find("template=product, sort=title"); foreach ($products as $product) { ?> <li> <h3><?=$product->id?>&nbsp;&nbsp;<input type="number" value="<?=$product->amount ?: 0?>" name="product[<?=$product->id?>]" min="0" style="width: 50px;">&nbsp;&nbsp;<?=$product->title?></h3> </li> <?php } ?> <button type="submit" name="submit" value="update" style="width: auto;">Bestand aktualisieren</button> </form> if ($input->post->submit) { $amounts = $input->post->product; $products = $pages->find("template=product, sort=title"); if ($amounts) { foreach ($amounts as $id => $amount) { $products->getPageByID((int)$id)?->setAndSave('amount', $amount); } } } Well, one answer is “because Ryan didn’t program it that way”. You were giving $pages->get() a Page that you already had. It certainly could work, because all the necessary information is there, but the get() method wasn’t programmed for that situation, because if you have the Page object already, why would you need to get it again? You can still do so by converting the Page object to a string (which is always its ID) or just getting its ID explicitly. Because your Page object was named $id, that would have been $pages->get($id->id). Here is an unrelated tip: you can just use single quotes instead of escaping the double quotes, because mercifully both are legal in HTML. You can even mix them in the same tag: <input type="text" value='call me ishmael'/>
  21. Yes, in a file with namespace ProcessWire that will let you use it: $foo = new \stdClass(); You can also put “use \stdClass” at the top if you need it a lot. The same goes for all the other stuff outside PW’s namespace. Often you’ll need \DateTime or \IntlDateFormatter for example. Edit: the technical term is “The Global Space”: https://www.php.net/manual/en/language.namespaces.global.php
  22. Put a backslash in front if you want to use PHP classes, or am I missing something? It’s near impossible to answer your question without knowing why you want to use stdClass. Could well be that ProcessWire has something suitable for your use case, but what is your use case?
  23. Granted, I don’t have much experience with the complex column types (I only just updated after 10 years or so, to get the Page type), but if you primarily use primitive types, ProFields Table has the benefit of being a single SQL join away. So if you’re like me and you sometimes want to do custom queries, that’s pretty cool. Plus, while I have nothing against repeaters, for some things it just feels icky to have the Page overhead. I have a site with playlists, so there’s a table with Artist, Title and some auto-generated normalisation columns for search, for example. Another site manages ”trips“ using a column for the place and two DateTime columns for the duration. I think the need to connect multiple Page references to some metadata like dates is pretty common, and ProFields Table is perfect for that.
  24. if ($input->post->submit) { //it is a mystery to us what this, and since it comes //from the client, it may also be a mystery to you $amounts = $input->post->product; //you’re looking up pages, so this will be a PageArray //with arbitrary numerical indices $products = $pages->find("template=product, sort=title"); if ($amounts) { //apparently we’re assuming the client sent us an //array with meaningful indices foreach ($amounts as $index => $amount) { //because $products is a PageArray, you’re going to //get NULL or a Page object when you access it like //this. In your case probably NULL unless your client //can somehow divine what pages result from the above //selector AND in what order $id = $products[$index]; //because $id is either NULL or a Page, this selector //cannot work. It will work if you put $id in quotes: //– if $id is NULL it will look for nothing and give you // a NullPage. //– if $id is a Page, PHP will call toString() on it, // resulting in its ID, so you’ll just get the same // Page back. //Both paths seem useless though? $pages->get($id)->setAndSave('amount', $amount); } } } This is my understanding from looking at it… Can you explain what $input->post->product contains?
  25. Looks like I subscribed not a moment too soon ? ProFields Table is the greatest ???
×
×
  • Create New...