Jump to content

joer80

Members
  • Posts

    363
  • Joined

  • Last visited

Everything posted by joer80

  1. You are correct. I am going to try to take it out soon but the code right now passes both! It was a weird situation where the pages may or may not have a city as a parent. Thanks for the help!
  2. My query would be: has_parent=1019, has_parent=1056 Not using the | Say the first one is a state, and the second is a city. My code may build both depending on if the second says all in this state, or only one location. (Children of 1056) If I need to, I can probably change it to clear out the first one, just wanted to know if having more than one is possible! Thanks!
  3. I see what you did! Ha. You are getting the children of the top level locations page, which is always a state, instead of reading the state field on the locations template! That would work.... It looks like I was making this harder than it had to be! There was totally a process wire way to do this. I am going to try and see if I can get by with out that statename field on the location as well. I don't think the optional city name will matter.
  4. I apologize! I had some incorrect information in my post #10 and fixed it. Can you tell me if this solution still applies?
  5. My structure is Home Locations Locations -> Statename Locations -> Statename -> City Name -> Location Name Locations -> Statename -> City Name -> Location Name -> Inventory Locations -> Statename -> City Name -> Location Name -> Inventory -> Inventory Listing Then on my inventory page, I want a drop down that shows all states that my website covers. (Inventory can only be in one location and state at a time.) The Inventory Listing does not have a field for state, but the Location template does. I guess I do not even need a state name on the location template because that is my tree! I put it in there though because I only have 30 locations, and some will not need a city parent because we only have one location in that state. In that case I have the Location under the state instead of the city. (That way the navigation that is built from the tree does not have a near empty page.) If I do it the group by method and add a new Location with a new state, it is going to automatically add it to the drop down as a possible way to filter the results. Hope that helps!
  6. If the page ids are different, and the State names are the same, how do you tell it to de duplicate based on the state name and ignore the page id information?
  7. Ah.. Well its good to know I am not missing something. Just did not know if there was a way to do it and I was missing it. I think in this case, this might be the faster and cleaner way: $result = wire('db')->query("SELECT * FROM field_location_state Group by data"); //Distinct while($row = $result->fetch_row()){ $StatesHTML .= '<option>' . $row[1] . '</option>'; }
  8. I have a states drop down that I want to populate and when I find all of my locations, I return duplicates. ie. Texas, Texas, Florida, Florida, etc. This is my code: $Locations = $pages->find('template=Location'); //loop through our locations foreach($Locations as $Location) { if($Location->Location_State){ $StatesHTML .= '<option>' . $Location->Location_State . '</option>'; } } What is the best way to do this the PW way? I thought I saw a way to populate an array on the forums, but then wouldnt I need to do 2 loops? One to load the array, and one to loop through it, instead of just pulling distinct? Thanks!
  9. This is my first module, so be easy on me! I am sure there was a faster and better way to do it, but this is what I have so far and it works pretty well! I figure by showing it, one of you may see a way to make it better! To use it, just make a hidden "csv" page in your root and add at least one csv item as a child. The children will need to have a "csv" template that has a csvFile field, and a csvDatabaseTable field. (I am thinking about adding a third one for csvDelimeter.) Also, I added a new admin page called "Read CSV files", and selected this module as the process. This reads all the children of that csv page, right now I just look up the csv page by id, so be sure and change that to hook it up to the correct page, and puts the content of the csv files into the database table listed on the child. (emptys the table first.) As of right now, the database table needs to be created in advance with the correct number of columns listed in the csv file. How much more work do you think I need to add in before it is worth listing as a public module? I just have never done one and was not sure! Thanks! Here is the page output: Importing All CSV files under csv page (id=1082) Searching for available files: Found: 1 Importing (csvFile.csv) into (csvDatabaseTable) imp row 2, imp row 3, imp row 4, imp row 5, imp row 6 Import Complete! Here is the code: <? class ReadCSV extends Process { public static function getModuleInfo() { return array( 'title' => 'Read CSV', 'summary' => 'This Module Reads the csv files under the csv page and inserts them into a database table. (Finds children of page id=1082)', 'version' => 001, ); } public function execute() { $ReturnHTML = '<p><b>Importing All CSV files under csv page (id=1082)</b></p>'; $ReturnHTML .= '<p>Searching for available files:</p>'; //find all csv files that are below the csv page. (Have it's id as their parent) $matches = $this->pages->find("parent=1082"); //Must spesify $this in a module. The following method also works: $matches = wire("pages")->find("parent=1082"); $count = count($matches); if($count) { $ReturnHTML .= "<p>Found: $count</p>"; foreach($matches as $m) { $csvDelimeter = ','; $csvEnclosure = '"'; $csvPath = '../..' . $this->config->urls->files . $m->id . '/'; //Format: ../site/assets/files/1083/ can also use $config->paths->files. (I added the ../.. to get out of the modules and sites folder.) $csvFullPath = $csvPath . $m->csvFile; $ReturnHTML .= "<p>Importing $m->csvFile into $m->csvDatabaseTable</p>"; //clear out the current database $sql = "TRUNCATE TABLE `$m->csvDatabaseTable`"; $database = $this->wire('database'); $database->exec($sql); //open csv ini_set("auto_detect_line_endings", true); //this is required. I think they are creating the csv on a mac or linux is the reason. $row = 0; $autoid = 1; if (($handle = fopen($csvFullPath, "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, $csvDelimeter, $csvEnclosure)) !== FALSE) { $num = count($data); $row++; //$ReturnHTML .= "<p> $num fields in line $row: <br /></p>\n"; $allData = ''; //this holds the value string. (cell data.) for ($c=0; $c < $num; $c++) { $allData .= '"' . $data[$c] . '",'; } //insert the data if($row == 1){ //skip row 1. Instead of reading the column names, I am just inserting the data so order is important. //echo "<p>Skipping the first row.</p>"; } else { $allData = trim($allData, ','); //trim the trailing , off. $allData = $autoid . ',' . $allData; //add an extra column for the auto id column //insert into db $sql = "INSERT INTO $m->csvDatabaseTable VALUES ($allData)"; $database = $this->wire('database'); $database->exec($sql); $ReturnHTML .= 'imp row ' . $row . ', '; $autoid++; } } //end loop through spreadsheet rows fclose($handle); $ReturnHTML = rtrim($ReturnHTML, ', '); $ReturnHTML .= '<p>Import Complete!</p>'; } //close open csv } // end for loop through pages } else { $ReturnHTML .= "<b>Sorry, no results were found.</b>"; } return $ReturnHTML; } // end of execute function } //end of class ?>
  10. That is really great reading, and really helpful! I have found examples online using both methods! Thank you!
  11. Ah... awesome! It does look like he just passed a filename to fopen on a file uploaded with a form! I could not find much documentation on working with the files stored on a page and just wanted to make sure I was doing it right! What is the $files and $file->url variable used for I see on the cheat sheet? (I see it has things like $files->path available.) Thanks!
  12. Ok, I am sure this is an easy question! I have a page with a csv file attached, and I want to know how I should work with that file! If I do: $matches = $this->pages->find("parent=1082"); (This Finds one page so we are so far so good) (I made a hidden "csv page" in root, and am putting all of the csv files as children with a file field for the file, and a text field for the database table name.) When I loop through and access the page that it finds, I am able to get the filename of the csv file with this: $m->csvFile (gives me filename.csv) However, I am not sure the way I should read the file to work with it! Or should I not, and just use this filename I have, add on the rest of the path, and pass it to fopen? Like this: $file = fopen($csvfilepath,"r"); (I am wanting to read the csv file and insert it into a database table.) Thanks!
  13. In the example in the forum, he had the file named ProcessHello.module and the class name ProcessHello, so it is correct! My issue was because my class name did not match my filename as apeisa suggested. Now that both match on mine, it is working now! Thanks for your helps guys!
  14. That is what I am saying. I never uploaded to the wire tab. And I can shoot it both places by updating the file in the site folder. When I change the class name, it moves from tab to tab. I am pretty sure you are correct and the bug is because I named the file readCSV.module and the class ProcessReadCSV and that caused it to go to the core tab? As soon as they are both readCSV it moves to the site tab!
  15. I wonder if it could be because I named it "class ProcessReadCSV" and the Process part is making the cms think it is a core module? Update: I just tested it, and renameing the class file fixes it! So changing: class ProcessReadCSV extends Process { to class ReadCSV extends Process { Does in fact move it from the wire tab to the site tab. (Even if the file is physically located in the site tab. So doing the example posted in that forum will cause an error when you install the module!
  16. In case it is a bug, I am running ProcessWire 2.4.0 It looks like it picks it up in the wire tab, but if you click install it fails because the file is not there. (It is in the site folder.) This is the error if you click install: Error: Class 'readCSV' not found (line 565 of /home/(removed)/public_html/goac/wire/core/Modules.php) This is what is in the file: /site/modules/readCSV.module <? class ProcessReadCSV extends Process { public static function getModuleInfo() { return array( 'title' => 'Read CSV', 'summary' => 'This Module Reads the csv files under the csv page.', 'version' => 001, ); } public function execute() { return "<p><a href='./hi'>hi</a> or <a href='./bye'>bye</a></p>"; } public function executeHi() { $this->message("Well hello"); return "<p>You clicked hi!</p>"; } public function executeBye() { $this->setFuel('processHeadline', 'Goodbye?'); $this->error('Not so fast!'); return "<p>You clicked bye!</p>"; } } ?>
  17. The forum post mentioned "/site/modules/", and that is where I uploaded it, and it still found it in the core tab! That is why I got confused! So basically what I am seeing is, I upload a module to the site folder, and it adds it to the wire/core tab instead of the site tab when you are on the /admin/module/ page!
  18. This post deleted because I was confused. (Happens all the time.)
  19. I was following the directions listed here. Got to it from a Google search result https://processwire.com/talk/topic/276-creating-new-admin-page/?p=1856
  20. I saw a post on the forum that shows how to do a custom admin process wire module but it puts it in the "/wire/modules/" directory which adds it to the core tab. If I want to do a new admin process module, can I put it in the "/site/modules/" folder instead, and still select it as a process on an admin page? Thanks!
  21. Ok, let me know what your error log says! That should say what they are missing. Or you could try another web host! I think liquid web, hostgator and known host all work out of the box. VPS gives you much more control than a shared host as well, but it should work either way.
  22. Login to your cpanel and post what is under your errors icon. Also let us know what company you are using for your hosting!
  23. I saw the cheat sheet shows the sanitize methods! http://cheatsheet.processwire.com/
  24. Since I would think it would add a db query every time you look up a page id, I think I am going to do the $config->urls->root method in most cases as well!
  25. Has your apache version changed recently? I just got a 500 Internal Server error on my Godaddy vps and this is why, not sure if this will help you or not. (My other vps worked fine.) I was doing a new processwire install, and Godaddy was missing pdo, and gd so I did an easy apache rebuild in WHM. Then the install.php file stopped loading and started throwing a 500 error. I opened up cpanel and looked in my error log and it said: .htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration I am planning on redoing easy apache and making sure the Env module is selected! I will let you know if that fixes mine! What is bad, is it is suppose to start with your previous config, so I am not sure how this box gets unchecked! Could be a bug! **** Edit: Yes, checking the ENV checkbox did fix my 500 issue!
×
×
  • Create New...