Jump to content

muzzer

Members
  • Posts

    126
  • Joined

  • Last visited

Everything posted by muzzer

  1. I have a modx-based tourism site which I would love to port to PW, but unsure about the database structure. The site lists accommodation and adventure activities, currently has about 1000 (should soon be at max of about 3000) listings. Each listing contains about 60 fields covering such things as business name, description, pricing etc. This listing data is currently held in a single mysql listing table, 1000 rows, 60 fields. Converting this into PW would result in 1000 pages, each page containing 60 fields, which means another 60 tables in the database. Thats fine, but what are the likely effects (speed) for queries - to get data to display one listing currently I have one select query (select * where id = 'x'). How would PW handle this? It would presumably need to query all 60 tables to get all the field data for a single listing? Is this slower and would it be a drag on the server? I have a solid knowledge of databases on a simple level (simple queries etc), but have not used JOINs etc (which I presume PW uses to grab page info) so and a bit lost here as to what is realistically achievable. Some advise would be appreciated - I would love to port this to PW and converting the listings records to PW pages would be sweet from an admin and code development point of view. But I can't help feeling this type of data be kept in a single table as I currently have it?
  2. Thx for confirming that Adrian. What is the process here, do I need to file this as a bug and if so where? Or do Ryans powers stretch to "all seeing God" allowing him to magically pick this up?
  3. I'm using PW2.4 which has the [new, I think] option of displaying image input-types as a grid rather than in rows in the page-edit mode. This is sw-eet, but if the user needs to delete an image the trashcan which is in the heading (in row display mode at least) is not there. If I have two or more images a grid/row icon appears so I can switch into row mode and delete an image, but with only one image this grid/row icon does not appear. Can anyone confirm this (bug?) or is it just my installation?
  4. Yeah, I can't help I'm afraid but would also love to know if there is a quick non-phpmyadmin-style method to updating local database from live and vise-versa.
  5. Aw man, this is the bomb! I was stressing my brain on ways to do exactly what @boundaryfunc was try to nail and it's so damn easy. How can permissions be so simple! PW continues to prove itself.....
  6. Thanks Macrura, Profile exporter is exactly what I was trying to achieve for the sql dump so it was good to see how that was wrapped up in a module. I've used a readfile() function with html headers to do a direct download of the dump, which works well. Now to tackle the import section, I'm thinking this will need to be a bit selective as overwriting session info in the database will log the user out. Hmm, have not looked into yet but at a glance just now it looks like session info is not stored in the database. Anyways,thanks for the pointers, helpful. I'm now beginning to see what the fuss is with module development, great stuff.
  7. OK, I'm finally writing my first PW module. I've grabbed Ryans Hello Process Module and mangled it to do roughly what I want. I've got a new item in the admin>setup menu called Backup Database. Clicking this runs my module which creates a backup of the PW database and saves it to the /site/assets/backups folder. Works sweet. At present when I do an update to a PW site I make the changes locally, then go into phpMyAdmin, select the database, select options, export the database, and then import the sql to the live database. This module is meant to make the exporting process much quicker, plus since everything else in PW is so cool I just wanted to learn a bit about modules development Anyways, next I've created a link to download the file after which it is to be deleted from the /site/assets/backup folder. However, clicking the download link gives me: Forbidden: You don't have permission to access /site/assets/backups/db-backup.sql.gz on this server. Is there a location where I can save this file but only a logged in admin user can access it? Obviously I need to be able to download this file but cannot have joe public having access to the database sql.
  8. Hi nik, Thanks for the response and for testing this on your system for me. I debugged the queries as suggested with the same weird result, number of rows returned confirming the above. I also installed the SelectorTest mod (which is damn sweet BTW) and no luck. In frustration I upgraded to PW 2.3 and problem sorted. I see in the docs the ^= selector works in PW v2.1 onwards. I previously had 2.2 I'm sure, possibly 2.1 at oldest, as when I first started using PW ver2.1 was the current release. Anyways, guess this is a good example of the advantages of being up-to-date. SelectorTest will be a must-have on all my PW site install from here-on-in. Very nice peice of work. Thanks nic
  9. I have some sample pages setup, titles as follows Adams page Anitas page Another page Another page 2 Another page3 These all have parent id 29. I'm trying to get all pages with title starting with "An". So $pgs= $pages->find('parent=29, title^=An'); foreach( $pgs as $p ) echo $p->title This returns Anitas Page, Another Page, Another page 2, and Another page 3, which is correct. Adams Page is not included as it does not start with "An". Cool. PW makes this so easy! However, if I alter the title selector to find page titles starting with just "A": $pgs = $pages->find('parent=29, title^=A'); this weirdly produces Adams Page and Anitas Page. For some reason the other three pages are not returned. What??! Am I missing something obvious with the ^= selector?
  10. Don't know if anyone else is seeing this or it's something confined to my site, but when I use Fredi with a TinyMCE field and click the insert image icon I get an error: TemplateFile: No page specified It works fine in the backend.
  11. Hey Apeisa, just took this for a test run and she rocks! I have developed something very similar, but I have to say your effort is just quite a bit nicer. I'll have to pull it apart to see how do did it, and learn some stuff at the same time no doubt. Awesome job, frontend editing is what I loved from modX, PW just gets better and it feels complete now I see you were looking at adding a $fredi->newPage method, is this still on the cards? This would be the ultimate. Thanks for the awesome module Edit: Hey, just noticed mention of work-in-progress on $fredi->newPage in another thread, look forward to seeing that.
  12. Great stuff Teppo, very useful. A minor thing, the java-script field is not showing correct for me though, see attached image. I'm wondering if it's possible to track not only logins but also some editor actions - say log each time a page is edited. I use this logging feature a lot when I use modX as I can see if clients have edited a page in the last hour or so - It allows me to download the latest database to my dev machine, make some changes and then reupload (overwrite) knowing I'm not overwriting any new client edits. Anyway, thanks for a cool mod
  13. You are right! I've altered it to read: if(wire('config')->ajax) $productImage = $product->wcart_image->first()->size(80,60); else $productImage = $product->wcart_image->size(80,60); and it's all go Still, I'm not sure I understand why this is so. Can someone explain exactly how wire('page') is different structurally to $page. This is one aspect of PW that has confused me from day dot. Thank you Soma for your awesome assistance. Much appreciated.
  14. Soma, thanks for your time on this. Sorry I seems to have confused you as to how it's all set up, so heres a fuller version of the code: ajax call: $('.numberAdjustment').live('change', function(){ var $this = $(this) var btnText = $(this).html(); var inputVal = $(this).val(); var inputId = $(this).attr('name'); var serial = "inputId=" + inputId + "&inputVal=" + inputVal; $.ajax({ url: location.protocol + '//' + location.host + '/site/wdnzScripts/wcart.inc.php', type: "post", data: serial, success: function(responseText){ $('#cart').fadeOut(500, function() { $('#cart').css('display', 'none'); $('#cart').html(responseText); $('#cart').fadeIn(500); showNotif('<p>Your cart contents have been updated.</p>', $this, btnText ); }); }, error: function(){ alert("Oops, there was an error adjusting the cart contents"); } }); }); that simply detects when the input with class 'numberAdjust' in the cart table is altered and calls out troublesome script, which updates the number of the product in the cart and returns the updated cart table HTML. It then fades the old cart table out and fades the updated version in. No problems there. The script /site/wdnzScripts/wcart.inc.php: <?php include_once( $_SERVER['DOCUMENT_ROOT'] . $_SERVER['HTTP_HOST'] . '/index.php' ); // bootstrap PW // ajax calls if(wire('config')->ajax) { // set number of units of a product in the cart if( isset( $_POST['inputId'] ) AND isset( $_POST['inputVal'] )) { $id = str_replace( 'units_id', '', $_POST['inputId'] ); alterProductPurchase( wire( 'pages' ), wire( 'input' ), wire( 'config' ), $id ); echo generateCart( wire( 'pages' ), wire( 'config' )); } return; } // alter number of units for an existing product in the cart. Called from the units input in the cart table function alterProductPurchase( $pages, $input, $config, $id ) { // check if the page with this exact product already exists, if so add to it, else create $purchase = $pages->get( '/wcart/sprees/' . session_id() . '/' )->find( 'template=wcart-product-page,id=' . $id ); if( $purchase[0] ) { if( $input->post['inputVal'] == 0 ) { // delete product from cart $pages->delete( $purchase[0] ); } else { // exact product exists for this customer, so add the new purchase's units $purchase = $purchase[0]; // get first record returned $purchase->wcart_product_units = $input->post['inputVal']; $purchase->setOutputFormatting( false ); $purchase->save(); } } } function generateCart( $pages, $config ) { $purchases = $pages->get( '/wcart/sprees/' . session_id() . '/' )->find( 'template=wcart-product-page' ); $cartHtml = '<table id="cart" class="table table-striped table-bordered table-hover"><thead><tr><th>id</th><th>title</th><th>colour</th><th>size</th><th>number</th><th></th><th></th></tr></thead><tbody>'; foreach( $purchases as $purchase ) { $product = $pages->get( $purchase->wcart_product_id ); $productImage = $product->wcart_image; debug( 'prior to image resize' ); if($productImage) $productImage = $productImage->size(80,60); //THE ERROR OUTPUTS BETWEEN THESE TO DEBUG CALLS ('debug' is a chrome/lagger function) debug( 'after image resize' ); $cartHtml .= '<tr>'; $cartHtml .= '<td><a href="' . $product->url . '"><img src="' . $productImage->url . '" width="80" alt="" /></a></td>'; $cartHtml .= '<td>' . $product->title . '</td>'; $cartHtml .= '<td>' . $purchase->wcart_product_colour . '</td>'; $cartHtml .= '<td>' . $purchase->wcart_product_size . '</td>'; $cartHtml .= '<td><input type="text"class="numberAdjustment input-mini" name="units_id' . $purchase->id . '" value="' . $purchase->wcart_product_units . '"></td>'; $cartHtml .= '<td><button class="removeLink btn btn-mini btn-danger" id="remove_id' . $purchase->id . '"type="button">Remove</button></td>'; $cartHtml .= '<td></td></tr>'; } $cartHtml .= '</tbody></table>'; return $cartHtml; } ?> Note: If I remove the image resizing lines and the script/ajax works beautifully.
  15. Hey Soma, sorry, I completely didn't see your reply; What does this mean in practice exactly? I'm still trying to get my head around this. How would it be accessed (compared to a normal php array)? The function is located in /site/wdnzScripts/wcart.inc.php. When called from ajax this file is called directly and the function call is if(wire('config')->ajax) echo generateCart( wire( 'page' ), wire( 'pages' ), wire( 'config' )); and is located directly above the function. When called normally the function call is in a template: include_once( $config->paths->root . 'site/wdnzScripts/wcart.inc.php' ); echo generateCart( $page, $pages, $config ); I'm obviously missing something obvious here. Both you and Ryan say it should be an array so thats as good as gospel for me, it should be an array. But whatever way I look at it it appears to be a string!
  16. Further: function generateCart( $page, $pages, $config ) { $purchases = $pages->get( '/wcart/sprees/' . session_id() . '/' )->find( 'template=wcart-product-page' ); foreach( $purchases as $purchase ) { $product = $pages->get( $purchase->wcart_product_id ); debug( $product->wcart_image ); $productImage = $product->wcart_image; debug($productImage); if($productImage) $productImage = $productImage->size(80,60); .... } } The two debug lines output a string 'bioflow-dog-collars.jpg' (not an array). Output of both is the same (as you would expect). Changing $productImage = $product->wcart_image; to $productImage = $product->wcart_image->first(); produces the error.
  17. Thanks Ryan. Tried your suggestion, resulting in: E_USER_ERROR: Exception: Method Pageimage::first does not exist or is not callable in this context The generateCart function is called on a "show cart" page to generate the shopping cart table. There is definately an image for the product. It's called again (but with parameters passed in wire('var') format) from ajax when the number of items is adjusted (from an input field in the cart table), so nothing has changed at this point (images etc) other than the number of items in the cart. Essentially what it appears to me is there is something missing when the function is called via ajax as it's exactly the same code in every respect other than the call method. It's doing my head in!
  18. Thanks but doing so produces: Fatal error: Call to a member function size() on a non-object. $product->wcart_image is not an array according to is_array($product->wcart_image)
  19. I'm building my first PW site (lovin this system) and working on a custom shopping cart at present. But I'm having a problem getting image resizing to work using AJAX. I have a function which is called in different circumstances both normally and via AJAX function generateCart( $page, $pages, $config ) { $purchases = $pages->get( '/wcart/sprees/' . session_id() . '/' )->find( 'template=wcart-product-page' ); foreach( $purchases as $purchase ) { $product = $pages->get( $purchase->wcart_product_id ); $productImage = $product->wcart_image->size( 80, 60 ); .... } } Calling from AJAX fails with the error: WireException: Method Pageimages::size does not exist or is not callable in this context [C:\wamp\www\spv\wire\core\Wire.php:232] The function call normally is : echo generateCart( $page, $pages, $config ); That's fine, works as you would expect. But from ajax: if(wire('config')->ajax) echo generateCart( wire( 'page' ), wire( 'pages' ), wire( 'config' )); and it throws the error. What's going on, is something not visible here that needs to be? In case you're wondering 'wcart_image' is a field of type image.
  20. Thanks guys, awesome replies and a real insight into how the hooks system works. I'll have a tinker with these ideas and see how I go. Love the way you can hook into PW at different stages and do almost anything. One thing I have struggled with a bit is getting my head around the way the page, pages etc objects work, what they contain and when, but I guess that's just a matter of trying things out. Apeisas commented code above for example was helpful... // $page will keep the page that user has just saved $page = $event->arguments[0]; as I was wondering exactly what $event->arguments[0] was all about! Thanks again guys, the answers on this forum are amazing.
  21. OK, my first effort with modules and I've run into a similar infinite loop issue. I'm writing a module which will allow me to automatically delete a number of existing pages and create a handful of new pages when a certain document is saved. At present my code is very cut-down - it doesn't do anything as yet except create a new page when the one being edited is saved. public function init() { $this->pages->addHookBefore('save', $this, 'pageSaved'); } public function pageSaved($event) { $page = $event->arguments[0]; $p = new Page(); $p->template = 'basic-page'; $p->parent = '/about/'; $p->status = Page::statusUnpublished; $p->title = "This is the pagename"; $p->save(); } When I edit and save a page it loops endlessly on the save hook. Apeisa mentioned you could get rid of the $p->save() and use the addHookBefore save hook- doing this results in no page save. I'm not following his logic there, can someone help me to understand what's happening here.
  22. Thanks guys, answers the question very nicely.
  23. Hi, Coming from modx (Evolution) I found one restriction (which was later solved in Revo version) was a page limit of between 2000 and 5000 pages, after which performance apparently took a nosedive. I never fully tested this but it was a restriction I was always aware of and it did prevent be building a couple of sites. I would be interested to know if there is a theoretical "page limit" in PW, or alternatively has anyone developed a site with 5000+ pages and how well does it perform. How does it affect caching? Thanks
  24. Thanks guys, beautiful module Soma, I'll be giving that some more thought and trying it out for sure. Maybe I'm stuck in a modX way of thinking, I dunno. I do love the feel of PW so far and a big part of that is the simplicity you talked about Ryan, so I can understand you not wanting to complicate things too much by adding too many options/capabilities. It's an outstanding system and obviously really well thought out. Ryan, I'm not sure I argee however that this should be done from a template; the reason I like an ability to inject data into any page in certain places (hence fields preContent, postContent etc) without having to write a different template for each page (or use lots of conditional coding in one template), is that for example, I can drop a call in to run a snip of php to insert a google map or other random stuff, or simply add some data to a page which I don't want the client to have access to edit - if the code is not editable by the client then they can't mess it up (which clients are awesome at doing given the opportunity!). Doing that from a template on a per-page basis seems messy and awkward to me - if I have one template that services 100 pages, and they each have different content which I don't want the client to be able to edit, managing this in the template file would be nightmarish. Or am I missing something? :-
×
×
  • Create New...