Jump to content

Jan Romero

Members
  • Posts

    695
  • Joined

  • Last visited

  • Days Won

    20

Everything posted by Jan Romero

  1. Glad you figured it out! Is this documented somewhere or did you find this by trial and error? They flag you just for some url segments?!
  2. I was looking at this thread earlier and was confused, but now I’ve had a drink, I think you want to show a single list of pages whose parent matches some conditions? You can use selectors on fields of the parent like this: pages()->find('parent.title=something, parent.mengtest=orother')
  3. I think you just need to change this to $uploadpage->programme_photo->add($uploadPath . $file); Have you checked if there are any errors from WireUpload? $doc->getErrors()
  4. I mean… it’s always going to be departments/<some department>/<some category>/, right? So when you navigate to a catetory page such as your example /sitename/departments/hardware/heating/, you want to see products that have both department=hardware and category=heating? Do you use the same template for sellers, brands, categories and departments? It would be easy if you had a specific category template. Otherwise you have to go by position in the page tree: if ($page->matches('has_parent=departments')) { // you could also use $page->rootParent if /departments/ is immediately below root //now $page may be either a department or a category. we assume //that /departments/ has ONLY departments as children, and all //such departments have ONLY categories as children (or perhaps //they have things that don’t run this template) if ($page->parent->name === 'department') $items = $pages->find("parent=/products/, department=$page, sort=$order, limit=4"); else $items = $pages->find("parent=/products/, department=$page->parent, category=$page, sort=$order, limit=4"); $file = "_products.php"; } else { //sellers and brands }
  5. What exactly is the behaviour you see on mobile? Maybe it’s some kind of caching issue?
  6. 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).
  7. $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').
  8. 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.
  9. Maybe this helps? https://whatsmychaincert.com/?test2.gemeindeguru.at I wish I knew more about this stuff ?
  10. 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 ?
  11. 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.
  12. 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 ?
  13. 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
  14. 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).
  15. 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.
  16. 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
  17. 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>
  18. 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.
  19. 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; }
  20. 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?
  21. 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.
  22. Hi, sounds like you want this: (only without the negating “!” in your case)
  23. 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 ?
  24. 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'/>
  25. 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
×
×
  • Create New...