Ksenia
Members-
Posts
20 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Ksenia's Achievements
Jr. Member (3/6)
9
Reputation
-
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
-
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
-
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!
-
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. :--)
-
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"
-
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"
-
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
-
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
-
Creating filtering system with AND logic instead of OR logic
Ksenia replied to Ksenia's topic in General Support
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"; } } } -
Creating filtering system with AND logic instead of OR logic
Ksenia replied to Ksenia's topic in General Support
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 -
Copying architecture(database+templates) from one PW project to another
Ksenia replied to Ksenia's topic in General Support
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! -
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.
-
Get Text Tags array from the text field to create checkbox filter
Ksenia replied to Ksenia's topic in General Support
Thank you a lot! I adjusted it to my code and it works well! -
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