Jump to content

Ksenia

Members
  • Posts

    20
  • Joined

  • Last visited

Everything posted by Ksenia

  1. Hello! I am still exploring how PW works and I am facing this issue: I want to create a selector for a field that is PageReference type (AsmSelect) inside the repeater field. It goes like this: Relation to Document: Select: (you pick Document/Documents) Type: (you pick type/types of relation which are also pages) This is how I find the pages that have current page in the Repeater field, it works: $selector_doc = "template=Document, relation_document_document.relation_document_document_select=$page->name"; But the problem is with how to filter based on repeater entry, meaning if there are multiple entries (its a different repeater, but identical): How do I say "if SELECT == '$page->name', then print it "select and type"? Because now it just loops through all of the Relation entries, but I want it to show me only the one that has current page in Select: My code: $techniques = new PageArray(); $selector_tech = "template=Technique, relation_technique_substance.relation_technique_substance_select=$page->name"; $techniques->add($pages->find($selector_tech)); if (sizeof($techniques) > 0) { echo "<div class='field-cont'>"; echo "<div class='field-name'>Linked techniques:</div>"; echo "<div class='trick'>"; echo "<div class='field-lists tech'>"; foreach ($techniques as $tech) { foreach ($tech->relation_technique_substance as $relation_technique_substance) { $arraySelect_trick = $relation_technique_substance->relation_technique_substance_select; $arrayType_trick = $relation_technique_substance->relation_technique_substance_type; echo "<div class='field-relation'>"; ////here needs to be If()/// echo "<div class='select'>"; echo "<li><a href='$tech->url'>$tech->title</a>"; echo "</div>"; echo "<div class='type'>"; foreach ($arrayType_trick as $item) { echo "<span>$item->title</span></li> "; } echo "</div>"; /// end if echo "</div>"; } } echo "</div></div></div>"; } Best, Ksenia
  2. Hello ! First of all thanks a lot for this post, as a beginner in php and PW I was very happy to find it. But I was wondering if you could direct me to a solution in my case. Because I have applied your code and it works well, but I have one issue with "Confirm Form Resubmission" dialog. What I want: -possibility to add new pages to database of certain template (and it works) Frontend: Code example (top of the page): <?php if ($input->post('title_doc')) { $p = new Page(); $p->template = 'Document'; $p->parent = wire('pages')->get('/Documents/'); $p->title = $input->post->name('title_doc'); $title_format = str_replace("_", " ", $p->title); $p->title = $title_format; $p->save(); } if ($input->post('title_org')) { $p = new Page(); $p->template = 'Organisation'; $p->parent = wire('pages')->get('/Organisations/'); $p->title = $input->post->name('title_org'); $title_format = str_replace("_", " ", $p->title); $p->title = $title_format; $p->save(); } Form example: <div class="pf-sub-column doc_c_light"> <h2 class="pf-title "> Documents <input class="add_document doc" onClick="$('.doc_add').toggleClass('display')" type=button value="+"/> <form class="doc_add add_document_form " method="POST" action="<?php echo $page->url; ?>"> <label for="title_doc">Title</label> <input name="title_doc" type="title" /> <input type="submit" value="add"/> </form> </h2> <?php include('./checkbox_pf_docs.php')?> </div> My issue is not the creation of the page, but that if you open the page and want to press "back" , it shows this window, because my form is not cleaned or refreshed somehow. I was wondering if there is a simple solution I am not aware of due to my nubeeness. Best, Ksenia
  3. Never mind! I solved it! Just was looping selector in the wrong place! foreach ($selected_techniques as $selected_technique) { $selector_ind .= ", relation_individual_technique.relation_individual_technique_select=$selected_technique"; $individuals->add($pages->find($selector_ind)); $output = ""; foreach ($individuals as $match_ind) { echo " <li><a href='$match_ind->url'>$match_ind->title</a></li>"; foreach ($match_ind->relation_individual_organisation as $relation_individual_organisation) { $organisations->add($relation_individual_organisation->relation_individual_organisation_select); $allorganisations = $organisations->explode('id'); foreach ($allorganisations as $item){ $output .= "$item|"; } $final_output = mb_substr($output, 0, -1); } } $selector_org .= ", id=$final_output"; } Never mind! I solved it!
  4. Hello, Clarity! I am not sure I understand your comment also given the bug that I see after using suggested: var_dump($matches->getSelectors()); Is it something to do with me sanitising the array items as IDs? Best, Ksenia But also thanks a lot for this line, now I at least know what to debug. :--)
  5. Yes, I know why it doesn't work, but unfortunately I do not know why it puts "id=" in front of every result ahah. template=Organisation, sort=-created, id=1655, id=1655|1655|1705, id=1655|1655|1705|1655|1705|1661, id=1655|1655|1705|1655|1705|1661|1655|1705|1661|1648"
  6. Hello! Hm, this is very interesting! I see the bug, but can't tell how to fix it. Here is the example of picking two different Techniques (no changing of code) who both happened to have only one matched ID. One works and we can see that it has one Individual to loop through and selector is: "template=Organisation, sort=-created, id=1710" But when it loops through two Individuals, it is messed up: "template=Organisation, sort=-created, id=, id=1705"
  7. I am using IDs now to simplify it, but I really don't get it.... foreach ($allorganisations as $item){ $output .= "$item|"; } $final_output = mb_substr($output, 0, -1); echo $final_output; if ($final_output == "1652|1652|1674") { echo "<div>I don't get it!!!</div>"; } // $final_output = "1652|1652|1674"; $selector_org .= ", id=$final_output"; Then I change it: foreach ($allorganisations as $item){ $output .= "$item|"; } $final_output = mb_substr($output, 0, -1); echo $final_output; if ($final_output == "1652|1652|1674") { echo "<div>I don't get it!!!</div>"; } $final_output = "1652|1652|1674"; $selector_org .= ", id=$final_output"; -------->>>> Am I loosing my mind? ahah
  8. Hello! I have a weird situation going on with my selector field, which I can't really get. I create an array of titles as filter using this logic: firstname=Mike|Steve id=123|124|125 title*=Red|Blue|Green This is the field I am logging: It goes in a for loop till it looks like what you see on the screen. So, my code regarding the selector string looks like this: $output = ""; foreach ($allorganisations as $item){ $output .= "$item | "; echo "<div style='color:red;'>//output String://</div>"; echo $output; } $selector_org .= ", title=$output"; I also log the output just after the matched pages are selected to be sure: $matches = $pages->find($selector_org); echo $output; foreach ($matches as $match) { echo " <li><a href='$match->url'>$match->title</a></li>"; } But you can see that it doesn't select all four needed pages, only selects one of them. Yet when I copy this exact selector text and manually put it in my selector, it works great... I even copy extra space and "|" and all that, it is supposed to be identical. I am very confused, what is the difference between the code? foreach ($allorganisations as $item){ $output .= "Institute for Scientific Research in Cosmic Anthropoecology | Institute for Scientific Research in Cosmic Anthropoecology | Stanford Research Institute | Institute for Scientific Research in Cosmic Anthropoecology | Stanford Research Institute | Institute of Clinical and Experimental Medicine | Institute for Scientific Research in Cosmic Anthropoecology | Stanford Research Institute | Institute of Clinical and Experimental Medicine | Cosmists | "; echo "<div style='color:red;'>//output String://</div>"; echo $output; } $selector_org .= ", title=$output"; } ------> If you see where I'm going wrong, please enlighten me. I am very puzzled with this behaviour . :--) Best, Ksenia
  9. Hello! Thanks for the response! As to what I am trying to do: it is convoluted because of the way pages are logged. But I tried to draw it, maybe it helps: I tried to implement your approach but now it only works if there is only one organisation inside an array! If there are more, it shows nothing. How I implemented it: // Build up a selector string $selector_org = "template=Organisation"; $selector_ind = "template=Individual"; $techniques = $pages->find("template=Technique"); $selected_techniques_raw = $sanitizer->array($input->get('techniques_ind_org')); $selected_techniques = $sanitizer->options($selected_techniques_raw, $techniques->explode('name')); // A new empty PageArray that will hold the organisations selected for all the individuals $organisations = new PageArray(); foreach ($selected_techniques as $selected_technique) { // The $individuals PageArray has been created elsewhere in your code $selector_ind .= ", relation_individual_technique.relation_individual_technique_select=$selected_technique"; $matches_ind = $pages->find($selector_ind); foreach ($matches_ind as $match_ind) { echo " <li><a href='$match_ind->url'>$match_ind->title</a></li>"; foreach ($match_ind->relation_individual_organisation as $relation_individual_organisation) { $organisations->add($relation_individual_organisation->relation_individual_organisation_select); foreach ($organisations as $organisation) { echo " <li><a href='$organisation->url'>$organisation->title</a></li>"; } } // Now do something with $organisations foreach ($organisations as $organisation) { $selector_org .= ", title=$organisation->title"; } } }
  10. Hello Robin! You really helped me out the last time in this topic and I was wondering if you could help me figure out a much more complex filter using the logic you suggested? So, basically, what I need to do is: - filter one type of pages (Organisations) based on a field in another page type (Individuals) which has connection to (Techniques) and (Organisaions) How it looks: Individual has page reference field (a repeater, but it doesn't matter in the context, hence I only need one field in this repeater) called "Techniques" and a page reference field "Organisation". My filter is by Technique. What I am doing is: 1) filtering out all individuals who have selected technique in their technique_relation field; 2) looping through them to get the Organisations they are connected to in their organisation_relation field; 3) (where I fail) trying to match titles of Organisations from action (2) with titles of the list of Organisations I am filtering to make them appear in my matches. My issue is that I overwrite the variable with titles and not loop through it, so it works, but only for the last title. My code: // Build up a selector string $selector_org = "template=Organisation"; //making global var to not get error if there are no matches $org_name = $page->title; //create second selector $selector_ind = "template=Individual"; // get my Techniques $techniques = $pages->find("template=Technique"); //Get the array of techniques that the user has submitted via the form $selected_techniques_raw = $sanitizer->array($input->get('techniques_ind_org')); // Sanitize the techniques against the valid tags $selected_techniques = $sanitizer->options($selected_techniques_raw, $techniques->explode('name')); // Add the selected techniques to the selector string foreach ($selected_techniques as $selected_technique) { //I create another selector to pick the pages from Individuals who have selected technique picked in the field $selector_ind .= ", relation_individual_technique.relation_individual_technique_select= $selected_technique"; //find matching Individuals $matches_ind = $pages->find($selector_ind); //start looping through them foreach ($matches_ind as $match_ind) { //log Individuals echo " <li><a href='$match_ind->url'>$match_ind->title</a></li>"; //for each Individual I get the organisations they are related to // (because i need to end up with the list of Organisations in the end) foreach ($match_ind->relation_individual_organisation as $relation_individual_organisation) { //get array of selected Organisaions $array_orgs_ind = $relation_individual_organisation->relation_individual_organisation_select; //loop through hem to get the names foreach ($array_orgs_ind as $item_select) { //log names echo " <a href='$item_select->url'>$item_select->title</a>"; //try to create a variable for the selector to only pick pages with same titles from my list $org_name = $item_select->title; } } } //try to use the selector, but ofc var re-writes itself and works only for the last name $selector_org .= ", title= $org_name"; } If you can see something obvious I would really appreciate help! I am kind of stuck on that now... Best, Ksenia
  11. Thanks for the response! It is running locally on my computer but will run on a server, but I decided to install export/input module and it worked great for my purpose! Thanks, very helpful tips! I used export/input module and it worked pretty well for my goals for now!
  12. Hello! I am new to PW and while I got a hand of working with .php and coding templates, I am completely lost to how to adjust the file structure from one project to another? The files that we copied from the server were stored like this: While I have a very basic set-up that comes automatically and my main code is all in processwire/site/templates: As I understand, when you launch a project it looks for index.php and then for config.php, and of course it breaks if I just copy the structure in the folder (websites/processwire). Basically, what I need is: - all templates and fields - the pages tree itself (so not only the templates and fields, but also the tree structure using those templates and fields) - all the data from inside the fields But I do not know how to transfer this from the copied files and not get an error. And maybe my question is where does PW store the table with all the field types/ pages/ how data correlates the pages etc and can I copy it and just paste into my project? If you could guide me to options, I'll be very grateful! NOTE: I do not have access to the server with all the data, thats why we just copied the whole thing to adjust.
  13. Thank you a lot! I adjusted it to my code and it works well!
  14. Hello all! I am pretty new to PW and now trying to figure out how to build a filter that uses AND logic and includes many fields. With help I have figured out Page Reference fields and Repeaters, but simple Text Filed with dropdown text tags makes me confused. As I think of it, first I need to get the array of given fixed options of Text Tags here: And then I just need to print it out as checkbox form and circle through each page to see if they have the checked value in place of this field. Like what I have with page references: But for the life of me I cannot figure out how to get this list...So if you have suggestions, I would really appreciate it! Best, Kseniia
  15. Ok sorry for hectic updating, I did figure it out! Turned out to be quite simple! //Techniques $techniques = $pages->find("template=Technique"); $selected_techniques_raw = $sanitizer->array($input->get('techniques')); $selected_techniques = $sanitizer->options($selected_techniques_raw, $techniques->explode('name')); foreach($selected_techniques as $selected_technique) $selector .= ", relation_document_technique.relation_document_technique_select= $selected_technique"; Thanks a lot for your help!
  16. Update: I have figured out that those were arrays of pages, so now I can get the values I need with this: <h1>Relations</h1> <?php foreach($page->relation_document_technique as $relation_document_technique) { $arraySelect = $relation_document_technique->relation_document_technique_select; $arrayType = $relation_document_technique->relation_document_technique_type; echo "<p>Technique:</p>"; foreach($arraySelect as $item) { echo " <li><a href='$item->url'>$item->title</a></li>"; } echo "<p>Type of relation:</p>"; foreach($arrayType as $item) { echo " <li>$item->title</li>"; } } ?> But still am lost at how to turn this into a filter checkbox!
  17. Hello! I am also new to PW and on my internship I need to do a frontend for the research database encoded into PW. Mostly I need filters with AND logic (checkboxes) for various fields. I have figured out how to do it with Page Reference fields, but I cannot figure out how to include simpler Text Tag fields into this structure. So it works like this but including the lists of options from the text tag fields. So, if I have the Text Tag field "type of document" which has options "book, interview, audio", let's say, I want to be able to check a box and be able to only find a book with tag "Russia" and ingredient "lucid dream". If you have ideas, I would be super grateful! New to php so theres a lot of friction for me in figuring it all out :---).
  18. Thank you so much! You saved me ahah I implemented it and it works well! I also made it so it includes different Page Reference fields! But another challenge for me is to use the same logic but for the Repeater fields. Each Repeater includes two Page reference fields. And I can't seem to even first print out the info I need from them (to build a selector). The structure I have looks like this: And I tried to use the code from the documentation, but it only works with simpler fields like text. Otherwise gives the id of the right page, but refuses to access the name/title of it. <h1>Relations</h1> <?php foreach($page->relation_document_technique as $relation_document_technique) { echo "Other name: {$relation_document_technique->other_name}<p>"; //gives me text echo "Technique:{$relation_document_technique->relation_document_technique_select}<p>"; //gives id of the right page echo "Type of relation: {$relation_document_technique->relation_document_technique_type->title} </p>"; //gives nothing } ?> Maybe there is a simple mistake I'm making, but I would be super grateful if you see the solution for filtering based on Repeater structure! Have a neat day! Kseniia
  19. Hello! I am a new user of PW and I really need some guidence. :---) I use PW to design a front-end for the researchers I intern with. They logged all their database with PW (but before only used admin backend). I use Page Reference field mostly to create filters. I have followed this tutorial (very grateful for it!) and it does work as you can see at the screen recording of the test-website. But I cannot figure out how to change the inner workings of it to combine the tags user presses like Russia&&esoterism to see only the items that have both of those tags. What is even more complex: I will have multiple filters working in the same manner (page reference field) and I need all of them to also be using && logic. With possibility of clearing the history and showing all documents again. My tree structure is sth like this: -Documents -document -document -document -Tags -tag -tag -tag -Types -type -type -type etc This is my code right now. <div class="row"> <ul class="nav"> <h3> Filter by tag</h3> <li class="nav-item"> <a class="nav-link" href="/Documents/">Show all</a> </li> <?php $docTags = $pages->get("/Tags/")->children; foreach ($docTags as $docTag): ?> <li class="nav-item"> <a class="nav-link" href='<?php echo "/documents/{$docTag->name}/"; ?>' ?> <?php echo $docTag->title; ?> </a> </li> <?php endforeach; ?> </ul> </div> <div class="row py-5"> <?php // only 1 URL segment should be allowed if ($input->urlSegment2) { throw new Wire404Exception(); } // create a string that will be our selector $selector = "template=Document"; // get URL segment 1 $segment1 = $input->urlSegment1; // if there is a URL segment 1 if ($segment1) { // get cat type page $catType = $pages->findOne("parent=/Tags/, name=$segment1"); // if cat type page exists if ($catType->id) { // add this to the selector $selector .= ", tags=$segment1"; } else { // invalid URL segment 1 throw new Wire404Exception(); } } // find the pages based on our selector $docPages = $pages->find($selector); foreach ( $docPages as $docPage): ?> <div class="col-md-4 pb-3"> <div class="card"> <?php // if the page object has a featured image if ( $docPage->featuredImage): // https://processwire.com/api/fieldtypes/images/ // set some default image options $options = array('quality' => 80, 'cropping' => 'center'); // create a new image on the fly 800px wide $img = $docPage->featuredImage->width(400, $options); // get the url to the image $imgUrl = $img->url; // get the description field $imgDesc = $img->description; ?> <a href="<?php echo $docPage->url; ?>"> <img src="<?php echo $imgUrl; ?>" alt="<?php echo $imgDesc; ?>" class="img-fluid card-img-top" /> </a> <?php endif; ?> <div class="card-body"> <h4 class="card-title"> <a href="<?php echo $docPage->url; ?>"><?php echo $docPage->title; ?></a> </h4> </div> </div> </div> <?php endforeach; ?> </div> I would really appreciate any links to resources/tutorials or even general explanation about which direction to take! Thanks in advance! This forum has already helped me a lot! Best, Ksenia
×
×
  • Create New...