Changeset 2903
- Timestamp:
- 09/19/08 16:55:22 (4 months ago)
- Location:
- branches/0.11
- Files:
-
- 10 modified
-
CHANGELOG (modified) (1 diff)
-
samples/app/config/routing.xml (modified) (2 diffs)
-
samples/app/modules/Default/actions/SearchEngineSpamAction.class.php (modified) (1 diff)
-
samples/app/modules/Default/cache/SearchEngineSpam.xml (modified) (1 diff)
-
samples/app/modules/Default/models/PriceFinderModel.class.php (modified) (1 diff)
-
samples/app/modules/Default/templates/MenuSuccess.php (modified) (1 diff)
-
samples/app/modules/Default/templates/SearchEngineSpamSuccess.php (modified) (1 diff)
-
samples/app/modules/Default/validate/SearchEngineSpam.xml (modified) (1 diff)
-
samples/app/modules/Default/views/MenuSuccessView.class.php (modified) (1 diff)
-
samples/app/modules/Default/views/SearchEngineSpamErrorView.class.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/CHANGELOG
r2824 r2903 4 4 0.11.3 RC3 (September ??, 2008) 5 5 ------------------------------- 6 7 CHG: Improve sample app SearchEngineSpamAction to use ID and optionally name (#859) (David) 6 8 7 9 FIX: AgaviXmlrpcepiphpResponse::setHttpStatusCode() is not implemented but gets called in sample app Error404SuccessView (#849) (David) -
branches/0.11/samples/app/config/routing.xml
r2629 r2903 28 28 <route name="search_engine_spam" pattern="^/products(/buy-cheap-{name:[\S\s]+}-at-agavi-dot-org)?/(id:\d+)" module="Default" action="SearchEngineSpam"> 29 29 <defaults> 30 <default for="name">/buy-cheap-{ chainsaws}-at-agavi-dot-org</default>30 <default for="name">/buy-cheap-{}-at-agavi-dot-org</default> 31 31 </defaults> 32 32 </route> … … 44 44 <route pattern="^getItemPrice$" module="Default" action="SearchEngineSpam" method="read"> 45 45 <wsdl:input> 46 <wsdl:part name=" name" type="xsd:string" />46 <wsdl:part name="id" type="xsd:int" /> 47 47 </wsdl:input> 48 48 <wsdl:output> -
branches/0.11/samples/app/modules/Default/actions/SearchEngineSpamAction.class.php
r2687 r2903 5 5 public function executeRead(AgaviRequestDataHolder $rd) 6 6 { 7 $this->setAttribute('product_name', $rd->getParameter('name')); 8 $price = $this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductName($rd->getParameter('name')); 7 $pfm = $this->getContext()->getModel('PriceFinder', 'Default'); 8 $id = $rd->getParameter('id'); 9 10 // was the name in the url? then validate that, too 11 if($rd->hasParameter('product_name')) { 12 $name = $rd->getParameter('name'); 13 $price = $pfm->getPriceByProductInfo($id, $name); 14 } else { 15 $name = $pfm->getNameByProductId($id); 16 $price = $pfm->getPriceByProductId($id); 17 } 9 18 if($price !== null) { 19 $this->setAttribute('product_id', $id); 20 $this->setAttribute('product_name', $name); 10 21 $this->setAttribute('product_price', $price); 11 22 return 'Success'; -
branches/0.11/samples/app/modules/Default/cache/SearchEngineSpam.xml
r2383 r2903 7 7 <caching method="read" lifetime="2 hours"> 8 8 9 <group>asdf</group> 9 <group>products</group> 10 <!-- we need to vary by both id and name, as they can both be valid --> 11 <group source="request_parameter">id</group> 10 12 <group source="request_parameter">name</group> 11 13 <group source="locale" /> -
branches/0.11/samples/app/modules/Default/models/PriceFinderModel.class.php
r2687 r2903 3 3 class Default_PriceFinderModel extends AgaviSampleAppDefaultBaseModel implements AgaviISingletonModel 4 4 { 5 // imagine this stuff is in a database :) 6 protected static $products = array( 7 array( 8 'id' => 8172401, 9 'name' => 'brains', 10 'price' => 0.89, 11 ), 12 array( 13 'id' => 917246, 14 'name' => 'chainsaws', 15 'price' => 129.99, 16 ), 17 array( 18 'id' => 7856122, 19 'name' => 'mad coding skills', 20 'price' => 14599, 21 ), 22 array( 23 'id' => 123456, 24 'name' => 'nonsense', 25 'price' => 3.14, 26 ), 27 array( 28 'id' => 3165463, 29 'name' => 'viagra', 30 'price' => 14.69, 31 ), 32 ); 33 34 public function getProducts() 35 { 36 return self::$products; 37 } 38 5 39 public function getPriceByProductName($productName) 6 40 { 7 switch(strtolower($productName)) { 8 case 'brains': 9 return 0.89; 10 case 'chainsaws': 11 return 129.99; 12 case 'mad coding skills': 13 return 14599; 14 case 'nonsense': 15 return 3.14; 16 case 'viagra': 17 return 14.69; 18 default: 19 return null; 41 foreach(self::$products as $product) { 42 if($product['name'] == $productName) { 43 return $product['price']; 44 } 45 } 46 } 47 48 public function getPriceByProductId($productId) 49 { 50 foreach(self::$products as $product) { 51 if($product['id'] == $productId) { 52 return $product['price']; 53 } 54 } 55 } 56 57 public function getNameByProductId($productId) 58 { 59 foreach(self::$products as $product) { 60 if($product['id'] == $productId) { 61 return $product['name']; 62 } 63 } 64 } 65 66 public function getPriceByProductInfo($productId, $productName) 67 { 68 foreach(self::$products as $product) { 69 if($product['id'] == $productId && $product['name'] == $productName) { 70 return $product['price']; 71 } 20 72 } 21 73 } -
branches/0.11/samples/app/modules/Default/templates/MenuSuccess.php
r1635 r2903 9 9 <li><a href="<?php echo $ro->gen('asdjashdasd'); ?>" onclick="return alert('<?php echo $tm->_('You will now be redirected to an invalid URL. If no rewrite rules are in place, this means you will see a standard 404 page of your web server, unless you configured an ErrorDocument 404 or some similar setting. If rewrite rules are in place (i.e. no index.php part in the URL), you will be shown the Agavi 404 document. This is correct and expected behavior.', 'default.menu'); ?>');"><?php echo $tm->_('Call invalid URL', 'default.menu'); ?></a></li> 10 10 <li><a href="<?php echo $ro->gen('disabled'); ?>"><?php echo $tm->_('Try Disabled Module', 'default.menu'); ?></a></li> 11 <li><a href="<?php echo $ro->gen('search_engine_spam', array('name' => $ products[array_rand($products = array('nonsense', 'chainsaws', 'brains', 'viagra', 'mad coding skills'))], 'id' => 4815162342)); ?>"><?php echo $tm->_('Search Engine Spam', 'default.menu'); ?></a></li>11 <li><a href="<?php echo $ro->gen('search_engine_spam', array('name' => $template['product']['name'], 'id' => $template['product']['id'])); ?>"><?php echo $tm->_('Search Engine Spam', 'default.menu'); ?></a></li> 12 12 </ul> -
branches/0.11/samples/app/modules/Default/templates/SearchEngineSpamSuccess.php
r1690 r2903 10 10 </tr> 11 11 </table> 12 <p><a href="<?php echo $ro->gen(null, array('name' => null)); ?>">Product ShortLink</a></p> -
branches/0.11/samples/app/modules/Default/validate/SearchEngineSpam.xml
r2395 r2903 14 14 15 15 <!-- just a simple example. no error message here, since the error view redirects to the 404 page anyway. usually, you'd have a ProductValidator that looks into the database, and then also exports the record into the request data so you don't have to fetch it again in the action --> 16 <validator class=" isnotempty">16 <validator class="string" required="false"> 17 17 <argument>name</argument> 18 <parameter name="min">5</parameter> 18 <parameter name="min">1</parameter> 19 </validator> 20 21 <validator class="number"> 22 <argument>id</argument> 19 23 </validator> 20 24 -
branches/0.11/samples/app/modules/Default/views/MenuSuccessView.class.php
r2370 r2903 22 22 $this->setupHtml($rd); 23 23 24 // set the title 25 $this->setAttribute('title', $this->getContext()->getTranslationManager()->_('Welcome to the Agavi Sample Application', 'default.layout')); 24 // pick a random product and set it as a template var 25 $products = $this->getContext()->getModel('PriceFinder', 'Default')->getProducts(); 26 $this->setAttribute('product', $products[array_rand($products)]); 26 27 } 27 28 -
branches/0.11/samples/app/modules/Default/views/SearchEngineSpamErrorView.class.php
r2629 r2903 31 31 // fault code must be "Server", check the SOAP spec 32 32 // do not throw the exception please. it can be done with some fiddling, but returning it is a much better idea 33 return new SoapFault('Server', 'Unknown Product "' . $this->getAttribute('product_name') . '"');33 return new SoapFault('Server', 'Unknown Product ' . $rd->getParameter('id')); 34 34 } 35 35 … … 39 39 public function executeXmlrpc(AgaviRequestDataHolder $rd) 40 40 { 41 return array('faultCode' => 101, 'faultString' => 'Unknown Product "' . $this->getAttribute('product_name') . '"');41 return array('faultCode' => 101, 'faultString' => 'Unknown Product ' . $rd->getParameter('id')); 42 42 } 43 43 }

