Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About bookie

  • Rank
    Jr. Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Good to know about the underscore. I'll do that. Thank you for the help. I'm going to try this this evening and if it works there will be multiple problems solved here. Cross your fingers for me please. 😬
  2. @teppo, Please bear with me here as I have 0 education in php and am figuring it out as I go. I had never heard of implode before but that looks like it could be what I need. If I understand what the purpose of the code is, you're creating a single string that combines subject, cleanauthor and cleantitle. If there's no subject, the string simply ignores that value and starts at cleanauthor? Or if subject = American Fiction author = [null] title = Some anonymous book The resulting string would be "American Fiction some anonymous book" ? That sounds like it would probably work, actually. There is some redundancy but that's been the story of my life with this project, as the display of information is very particular and the data behind it is very irregular. For example, cleanauthor and cleantitle are both temp variables derived from author and title fields. I would assume that before the implode I will need to define these as I do in the template. Will this cause problems when calling the variables with array_filter()?
  3. I suspected the problem was something like that. Re: solution 1, the list I'm rendering consists of 700 pages, so load time is the primary driver of why I'm looking for a pagination solution. It looks like this option will have the same load time issues as the single page setup I've currently got going. Re: solution 2, if I understand you correctly a single sort_weight variable won't do the trick, because the sort does depend on dynamic input. Different catalog pages will have a different collection of child pages rendered, and their positions can change. I'll explain what the sorting is intended to do: The template running this code produces a list of books. Those books always have a title, but they may or may not have an author and/or subject. When sorting, we want books to be listed by subject, but if there is no subject, then primarily by author, but if there is neither subject nor author, then by title. When subject/author is identical between books we want items to then be properly sorted within that subset by the next highest priority field. So for example a set of books might be sorted as below: 1. [American Fiction] Frost, Robert. Poems. 2. [American Fiction] Twain, Mark. Huckleberry Fin. 3. Christie, Agatha. And then there were None. 4. Report on the Mississippi River Valley. If you are wondering why the data is as convoluted as it seems to be (why not give everything a subject?), the answer is the traditions of the field I'm in are centuries older than modern computing and have no concerns over the misery of the poor person trying to make sense out of it. Previously I had a sort that looked like this: foreach($items as $tempsort){ $tempsort->set('sortval', $tempsort->subject ?: $tempsort->cleanauthor ?: $tempsort->cleantitle); // Runtime field } $items->sort("sortval, date"); This is imperfect because after something is sorted by subject, the items that share a subject are not subsequently sorted by author since it's only sorting once, by a single assigned value. So I created a tier-based sort so that every book would be sorted by primary, secondary, and tertiary terms. What I'm thinking is the most effective way is to make permanent fields for srt1, srt2, and sr3 that are generated on saving the page. I've never used hooks before and am still a little apprehensive about it, but if pages did have those fields baked into the database then would the below work as expected? $items = $pages->find("template=book, catalog={$page->title}, sort=srt1, srt2, srt3, limit=50");
  4. I've been trying to solve this one by myself for a while now but I think my unfamiliarity with the grammar of php/processwire is keeping an obvious solution from my grasp. I have a collection of items that need to be sorted by variables of descending priority. I can figure that part out. I also have a general idea of how to sort using a single variable and then paginate the results. But I can't figure out how to both create a complex sort function and then properly apply a limit. Here is my sort, taken mostly from another solution offered on the forums (that I forgot to bookmark) // Create Sort Hierarchy $subjectsort = $pages->find("template=book, catalog={$page->title}, subject!=''")->each(function($sort_subject){ $sort_subject->srt1 = $sort_subject->subject; if($sort_subject->author){ $sort_subject->srt2 = $sort_subject->cleanauthor; $sort_subject->srt3 = $sort_subject->cleantitle;} else{ $sort_subject->srt2 = $sort_subject->cleantitle; } }); $authorsort = $pages->find("template=book, catalog={$page->title}, subject='', author!=''")->each(function($sort_author){ $sort_author->srt1 = $sort_author->cleanauthor; $sort_author->srt2 = $sort_author->cleantitle; });; $titlesort = $pages->find("template=book, catalog={$page->title}, subject='', author=''")->each(function($sort_title){ $sort_title->srt1 = $sort_title->cleantitle; });; $subjectsort->add($authorsort)->add($titlesort)->sort('srt1, srt2, srt3'); //concatinates all items then sorts them If I simply then list out the results of $subjectsort everything is ordered correctly. But if instead of the final line above I try something like: $items = $pages->find("template=book, catalog={$page->title}, sort=$srt1, $srt2, $srt3, limit=50"); The resulting array is simply sorted by page title, which is radically different from cleantitle. And if I try $items = $pages->find("template=book, catalog={$page->title}, sort=srt1, srt2, srt3, limit=50"); I get a fatal error (Unknown Selector operator: '[empty]') Out of curiosity I tried $items = $subjectsort("limit=50"); Which got me a list of 50 completely blank items. I don't know if it's possible to add a limit to the concatenation of $subjectsort after the fact, and I don't know if it's possible to carry over the prioritization done in the code above to sort via a new find function later. It seems that "limit" is limited in where it operates. I wonder if it would be better to make srt1 etc. permanent fields that are modified in a module hooked to saving a page, but I haven't touched modules yet, and don't want to add to the problem pile just yet. Any ideas of where I'm going wrong? Thanks a ton for all the help so far.
  5. At the moment the script is the first half of a template in which the second part is front-end, but I want to change that in the future. At the moment I am just commenting out the import code when I don't want to run it. This is why I'd like to move towards using some sort of module, but building that is low on the priority list by virtue of some time pressure.
  6. @Robin S Thank you so much for the detailed explanation. I had only a vague understanding of $page->of(false) while looking at the documentation and hadn't understood exactly what commands were affected by it. I also wasn't entirely sure of the purpose of creating a new $pageimages array, but didn't know if it would be appropriate to add files directly to $page->images as you suggested. So it's good to know that this is something that can be done a little more directly. I made the edits you suggested and it worked like a charm! A tangental question, is there danger in not "closing" the $page->of(false) command to prevent unwanted editing of a page? Should I be adding a $page->of(true) line at the end of the while loop? I expect that after I do a mass "import" I will be removing this code from the template anyway but if there is a best practices answer I'd like to learn good habits early on. Ideally I'd like to make some sort of module to do this process, but after reading the documentation I'm still not sure I understand exactly how to utilize them. I'm optimistic about figuring it out though considering how good the documentation and how helpful the community here is.
  7. Hello all, I have been trying to figure out how best to transfer the product images we have from old website to new. Each page has from 0 to 10 images. They can be .jpg or .png and are named consistently. Because the old site is going to remain up and this is a side project I thought I might just pull from that server every time, and first tried this: $affixnum = 1; $extension = ".jpg"; $file = 'https://www.site.com/pictures/' . $item->itemid . "_" . $affixnum . $extension; $file_headers = @get_headers($file); if($file_headers[0] != 'HTTP/1.1 200 OK'){ $extension = ".png"; //if no .jpg, check for .png $file = 'https://www.site.com/pictures/' . $item->itemid . "_" . $affixnum . $extension; $file_headers = @get_headers($file); } if($file_headers[0] != 'HTTP/1.1 200 OK'){ echo "<br />"; // creates content in the div so that the description aligns correctly } while($file_headers[0] == 'HTTP/1.1 200 OK'){ echo "<img src='" . $file . "' class='u-max-full-width'>"; $affixnum++; $file = 'https://www.site.com/pictures/' . $item->itemid . "_" . $affixnum . $extension; $file_headers = @get_headers($file); } In this case the code is in a for loop that displays every item in a catalog with its images. This works on catalogs with a couple items, but as there are 600+ items with multiple images each for a single catalog, the server timed out when I tried it for the whole thing. So I thought I should probably just upload all the images to the new site to prevent this. This thread > was very helpful but I have run into another problem. Below is my new code: if(count($page->images)){ echo "Images Present"; //debug to see what is being returned } else{ /* get the images object array for the Page */ $myPageImg = $page->images; $affixnum = 1; $extension = ".jpg"; $file = 'https://www.site.com/pictures/' . $page->title . "_" . $affixnum . $extension; echo "Testing " . $file . "<br />"; $file_headers = @get_headers($file); if($file_headers[0] != 'HTTP/1.1 200 OK'){ $extension = ".png"; $file = 'https://www.site.com/pictures/' . $page->title . "_" . $affixnum . $extension; $file_headers = @get_headers($file); if($file_headers[0] != 'HTTP/1.1 200 OK'){ echo "no images returned"; } } while($file_headers[0] == 'HTTP/1.1 200 OK'){ $page->of(false); // output formating I don't understand but seems to be needed $myPageImg->add($file); $affixnum++; $file = 'https://www.site.com/pictures/' . $page->title . "_" . $affixnum . $extension; $file_headers = @get_headers($file); $page->save(); echo $file . " added. <br />"; } } // ... followed by the below to display <?php if(count($page->get('images'))): foreach($page->get('images') as $image): ?> <a href='<?php echo $image->url?>' data-uk-lightbox="{group:'photos'}"> <img src="<?php echo $image->url; ?>" class='u-max-full-width'> </a> <?php endforeach; else : ?> <br /> <!-- fills div to keep formatting if there is no image --> <?php endif; ?> </div> In this case I put it in the individual item $page as a test. I didn't want the import to happen if images already were imported previously. Then I wanted to save a copy of each image into the page's folder and put it in the array. After running this I checked the item edit page in the admin side and did not see any new images in the images field. Also, no images ended up displaying on the page even though some debugging text told me that something had been found. However, if I go into the page's assets folder the images are there, so partial success! If I load the page again another copy of the images are downloaded too, which seems to mean there is nothing actually going into the $images array? Can someone help me get these images that were imported into the asset folder also appear in the $images array? Is this a remarkably convoluted solution for which a much simpler alternative is available? Thanks in advance for any guidance.
  8. I suspected that the paragraph tag issue was something like that. I wasn't sure that carrots could be safely parsed by the import module but if including HTML tags in the string is not an issue it shouldn't be too difficult for me to add them. This actually might be the solution to the line break issue at the same time. For reference here is the test CSV that I am using currently. Thanks for the advice! newtest.csv
  9. Hello all. Thanks to the wonderful help from this forum I've gotten much further in my project in a lot less time than expected. I'm now trying to figure out the best method of importing the records that will make up the bulk of my site. I'm using the ImportPagesCSV module and for the most part it is doing exactly what I need. I'm just running into a couple of issues. The major one is a lack of line breaks for the body field. I can get the line breaks to appear if I open the .csv in excel or notepad, but they don't seem to carry over when the page is imported. Is there a particular way to format the .csv file that will get the line breaks to transfer? I have searched around for solutions but have not found anything that seems to apply as the solutions seem to vary by application. The other issue is that when I publish the body of the page in my template, the content of the body has no paragraph tags, which screws up the styles. If I go into the page record and edit the body field manually (merely clicking the "source" button and then saving for example), then paragraph tags will appear, but since I expect to import about 600 records, I'm hoping not to have do this for all of them. Any insight on how to fix these issues are appreciated.
  10. Ottogal, that looks like what I needed, thanks! Pip, it does look like Page References are what I was looking for. The car example in the tutorial ottogal linked is close to what I'm doing. For example if you have a movie that is both in Japanese, and a Horror movie, I want to simply create pages that list it under both Japanese Movies and Horror Movies.
  11. I am slowly feeling my way through processwire and am trying to get an idea how best to structure my pages to make it easy to execute what I'm looking for. My intention is to create catalogs that can contain multiple items. Those items may appear in multiple catalogs. I was thinking of creating a tag field in item pages, and have catalog templates publish items that contain the relevant tag. But it appears that fields can only hold a single value. If I create multiple fields to serve the same purpose I assume that being able to determine if an item belongs in a catalog would get significantly more difficult. Is there an elegant solution to this that has already been worked out somewhere?
  12. Ah yes, I see the link was staring me in the face the whole time. I was looking on the demo site itself for it. There's a lot of reading ahead for me for sure. Thanks for your help.
  13. Hello all. I'm dipping my toes back into some development after ten years away and am excited to figure processwire out and start using it on some projects. The first thing I am trying to do is create a sortable database, similar to the skyscraper demo provided on the site. I would love to know if the source code for the templates are available anywhere for that site, as it solves a number of problems I anticipate having, and I learn well by picking apart code. Thank you in advance for any advice or help you can give. I'm going through all the tutorials and documentation I can find and get the sense that this is the first of many questions to come.
  • Create New...