Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Everything posted by a-ok

  1. Thanks guys. @Robin S yes that sounds like it should work... ->add(selector) is effectively filter->() but without it being destructive, right? So gives me full access. This is essentially but code so far so reckon I could totally use ->add() on this. Much appreciated help! $dateFormat = date('D. j F Y'); $today = strtotime($dateFormat); $first_day_of_next_month = strtotime("first day of next month"); $last_day_of_next_month = strtotime("last day of next month"); $events = $pages->find("template=events-detail, events_detail_dates_final_date>=$today"); foreach($events as $event) { // Get the repeater page with the next upcoming date $next_upcoming_date = $event->events_detail_dates->get("events_detail_dates_end_date>=$today, sort=events_detail_dates_end_date"); // $next_month_start_date = 0; $next_month_end_date = 0; $next_month_start_date = $event->events_detail_dates->get("events_detail_dates_start_date<=$last_day_of_next_month, sort=-events_detail_dates_start_date"); $next_month_end_date = $event->events_detail_dates->get("events_detail_dates_end_date>=$first_day_of_next_month, sort=-events_detail_dates_end_date"); // Add the timestamp of the next upcoming date to the result as a custom property $event->events_detail_dates_upcoming_start_date = $next_upcoming_date->getUnformatted('events_detail_dates_start_date'); $event->events_detail_dates_upcoming_end_date = $next_upcoming_date->getUnformatted('events_detail_dates_end_date'); if (!empty($next_month_start_date) && !empty($next_month_end_date)) { $event->events_detail_dates_next_month_start_date = $next_month_start_date->getUnformatted('events_detail_dates_start_date'); $event->events_detail_dates_next_month_end_date = $next_month_end_date->getUnformatted('events_detail_dates_end_date'); } } $events->sort('events_detail_dates_upcoming_end_date'); $calendar = $this->input->post->calendar; $query = $this->input->post->query; $events->filter("{$query}, {$calendar}"); Whoa that's good!
  2. Thanks for your reply, guys. Sorry if I haven’t managed to explain things correctly. @BitPoet‘s reply is definitely what I’m after HOWEVER I don’t think you can use the OR group parenthesis in a ->filter() but do correct me if I’m wrong? I’m doing some checks before this code which requires me to use ->filter().
  3. Within a pages selector... I'm building a filtering system (using checkboxes) and thus this allows the user to select a date range (today, this week, this weekend, this month, next month) and have built the functionality and selectors for this... for example... $now = strtotime("now"); $saturday = strtotime("saturday this week"); $sunday = strtotime("sunday this week"); events_detail_dates_upcoming_start_date<=$now events_detail_dates_upcoming_start_date<=$sunday events_detail_dates_upcoming_end_date>=$saturday, events_detail_dates_upcoming_start_date<=$sunday I'm using this with a filter->() so for example the full query would be, for example... $events = $pages->find("template=events-detail, events_detail_dates_final_date>=$today"); $events->filter("events_detail_dates_upcoming_start_date<=$now"); This all works fine and if I was to add tags to this too I would do add $events->filter("events_detail_dates_upcoming_start_date<=$now, tags.name=art|film"); This also works fine... but as I am using checkboxes, a user can select both "today" and "next month" and ideally what it would return are events that are both today and next month... (almost like how tags work with the | separator) but for each checkbox ticked, for dates, it adds a comma separator (I've coded it to do this) so for example... events_detail_dates_upcoming_start_date<=1517080159,events_detail_dates_next_month_start_date<=1519844959, events_detail_dates_next_month_end_date>=1517512159 Ignoring the field names (won't bother explaining this) but is there a way to return events that have ALL those attributes... and not using commas to filter it down?
  4. Sorry for the drama... I guess I could just wrap the whole hook in an if ($user->hasRole())... got it.
  5. Is it possible to check what the current role is (that's logged in) via a hook? I'm running a hook on the method Page::editable and want to check what the role is before I do anything within the hook. If not via the Page::editable method... is it then possible to combine hooks?
  6. I actually think @adrian may have solved this in a separate post but I just need to hook it into the user/role (so only hide them for a specific user/role)
  7. I've got it all working... almost. I've just been using the core permissions, AdminRestrictBranch, and the optional 'page-publish' permission which looks good. The only final thing is that the user/role can edit non-published pages within that branch. They can't edit published pages... just the unpublished ones. Anything I could do to get around this?
  8. I've managed to restrict the PageTree view to a branch only using http://modules.processwire.com/modules/admin-restrict-branch/ which is great but I can't work out how the user can add child pages only and not edit the other child pages. I've set my parent template to allow add child pages but not edit pages but unsure what to do next? I've managed to limit the publishing of a page, for that role, with the optional permission 'page-publish'.
  9. Hi all, I was originally in need of child pages to be created via a front end form (using the same fields as the template for the child page) and once submitted to be sent to an Unpublished state. This was my original thought, anyway. But there's a lot of complex functionality (repeaters, ASMselect fields etc) that has made me stop and think about it. Now I'm thinking I could create a user role and have them log in to the site but only have access to add a child page to a certain page. They would need to not see any other pages (even other pages with the same template) and only save and unpublish (not publishing rights). Do you think something like this is possible? And wise? Any thoughts are appreciated.
  10. Apologies for the late reply. Yes this is perfect... great to use just the PW API. Thanks @BitPoet
  11. Yep, sorry. Front end template. I could use a count() but it's getting a count of the repeater matrix's type that's 'text' only.
  12. Bit of an odd one here. I'm using a RepeaterMatrix which has various 'types' (text, image, video etc) and on the last iteration of one of the types (text) I want to add an element (for example, a share element... but this has to come after the last text type... not the last RepeaterMatrix row). I'm struggling a bit on how to achieve this? Is there a way to count the total 'text' types then create a PHP count and if the two match then it'll show? foreach ($page->flexible_content as $content) { if ($content->type === 'text') { // } elseif ($content->type === 'images') { // } }
  13. As I am saving the product ID of the Shopify product to each page... I ended up building an array of all the pages that currently exists on Shopify, with the product ID as the key, then I imploded that array by "|" then created a nonActiveProducts pageArray using $nonActiveProducts = wire('pages')->find("shop_detail_shopify_id!=$activeProducts"); What this does is return all the pages that exist in PW that's shopify ID doesn't match the active products... so this returns all the pages that need to be deleted. So, my final question is... is there a method to delete all the pages returned by a pageArray (rather than looping through each and deleting?)
  14. Thanks for the reply. It is currently saving the product ID in a field (in order to load the product detail data) – it's creating the pages fine it's just I cannot work out how to delete the pages that no longer exist in the endpoint list of products (once they remove it from Shopify).
  15. Anyone have any thoughts on this? Just need to work out how to delete the pages that aren't in the JSON but on PW...
  16. Hi folks, I'm going to be using a combination of Shopify's JS Buy SDK (to display the products and add to cart etc) and their API endpoint response to generate the pages required on PW (to match the products on Shopify). The idea is that I'll have two PW templates; one for the Shop overview and then one for the individual detail pages. These will both use the JS Buy SDK to either fetchAll products or fetch a specific product. Obviously the pages on PW need to be created from an endpoint response and thus updated (delete or added to) when new products are removed/added on Shopify. My plan was to do something similar to this forum post: https://processwire.com/talk/topic/16064-create-pages-from-json-feed/ where I would "use a lazy cron function to automatically query the API endpoint every 24 hours. To delete pages that are no longer contained in the JSON response you can collect all of the unique identifiers in the response and then use a PW selector to get pages not matching any of those identifiers. Those pages you delete." I think this sounds good and I have the understanding of it... but I have a couple of questions that I am currently stuck on. Using the PW API... what would be the best way to update the pages based on the returned result? Would it be to loop through the products and check if they exist... if not then create it? I'm unsure how to reverse this to then check if a page exists in the feed that's not on PW then delete it? function myHook(HookEvent $event) { $http = new WireHttp(); $host = 'XXX'; $shopify_api = 'XXX'; $shopify_password = 'XXX'; $shopify_base = 'https://' . $shopify_api . ':' . $shopify_password . '@' . $host . '/admin/products.json'; $products = $http->getJSON($shopify_base); foreach ($products['products'] as $product) { $productID = $product['id']; $productHandle = $product['handle']; $p = wire('pages')->get("shop_detail_shopify_id=$productID"); if (!$p->id) { // If it doesn't exist, create it $p = new Page(); $p->template = 'shop-detail'; $p->parent = '/shop/'; $p->name = $productHandle; $p->title = $product['title']; $p->shop_detail_shopify_id = $productID; $p->of(false); } $p->save(); } } wire()->addHook('LazyCron::every30Minutes', null, 'myHook');
  17. This seemed to have done the trick, Tom! Thanks!
  18. Hi all I have the hook written below... and it works fine on pages that have already been created (when I click 'Save') but when I try to create a new page it throws an error that I can't seem to get by. It appears to be firing this at the title entry point and not at the first 'Save/Publish' option once the client has finished editing. Any thoughts? ProcessPageAdd: Can't save field from a new page - please save the entire page first function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $today = strtotime("now"); $dateRepeater = $page->events_detail_dates; $lastRow = $page->events_detail_dates->last(); $page->set("events_detail_dates_final_date", $lastRow->events_detail_dates_end_date); $page->save("events_detail_dates_final_date"); } } wire()->addHookAfter('Pages::saveReady', null, 'myHook');
  19. Thanks, Robin. I had used $image->removeVariations(); later after posting and it still didn’t help. Is this what you meant?
  20. I've had a look at a lot of the forum posts relating to the gamma correction on images and I've followed some examples and declared this in my config file. $config->imageSizerOptions = array( 'upscaling' => true, 'cropping' => true, 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1 ); But when comparing the original uploaded image, and the resized image, it still seems to be altering the image a lot. I have even changed this directly in /wire/config.php in case it was related to my setup but this still doesn't work. You can see the difference in images here: http://plh.dk/site/assets/files/2554/natalia-1.760x950.jpg and http://plh.dk/site/assets/files/2554/natalia-1.jpg (original) Any thoughts? I have created new resized sizes to test (so it builds the new images based on this new config change) but, again, it doesn't seem to affect anything. I have also set up the options directly on the usage in the template but, again, doesn't seem to affect the image (http://plh.dk/site/assets/files/2554/natalia-1.720x900.jpg). $options = array( 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1 ); $image = $person->contact_team_image->size(720, 900, $options);
  21. I believe when using 'filter->()' it's using IDs? So I had to do... $limit = 18; $articles = $pages->find("template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"); if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $articles->filter("tags.name=$currentTags"); // Append original query with the tags selector if (!count($articles)) throw new Wire404Exception(); }
  22. What I can't work out is why this wouldn't work? $limit = 18; $articles = $pages->find("template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"); if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $articles->filter("tags={$currentTags}"); // Append original query with the tags selector if (count($articles)) { continue; } else { throw new Wire404Exception(); } }
  23. Thanks, Robin. I have come up with the following on my overview template (replacing the setup for URL segments and replacing it with a GET setup) $limit = 18; $query = "template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"; if ($input->get("tags")) { var_dump($input->get("tags")); $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $query .= ", tags={$currentTags}"; $articles = $pages->find($query); } else { $articles = $pages->find($query); } What do you think? Looks good? I would then use isset($currentTags) to check if a tag has been queried.
  24. I’m guessing this isn’t possible. I’ve had a bit of a play and would need the URL to allow for more than one word in one segment and don’t think that’s possible?
  25. Sorry to bring this up again but felt it was best to keep it under the same topic. I'm wondering if it's possible to do the same with multiple categories? Obviously this line would need to change... $current_category = $categories->get("name=$segment_1"); Any thoughts? Obviously the categories returns would be piped (for example, music|art) is that right? I don't mind using ids either... but just curious to know if you think it's possible.
×
×
  • Create New...