Changeset 2904
- Timestamp:
- 09/19/08 16:57:48 (4 months ago)
- Location:
- branches/1.0
- 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/1.0/CHANGELOG
r2891 r2904 73 73 0.11.3 RC3 (September ??, 2008) 74 74 ------------------------------- 75 76 CHG: Improve sample app SearchEngineSpamAction to use ID and optionally name (#859) (David) 75 77 76 78 FIX: AgaviXmlrpcepiphpResponse::setHttpStatusCode() is not implemented but gets called in sample app Error404SuccessView (#849) (David) -
branches/1.0/samples/app/config/routing.xml
r2648 r2904 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/1.0/samples/app/modules/Default/actions/SearchEngineSpamAction.class.php
r2733 r2904 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/1.0/samples/app/modules/Default/cache/SearchEngineSpam.xml
r2384 r2904 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/1.0/samples/app/modules/Default/models/PriceFinderModel.class.php
r2733 r2904 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/1.0/samples/app/modules/Default/templates/MenuSuccess.php
r1784 r2904 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/1.0/samples/app/modules/Default/templates/SearchEngineSpamSuccess.php
r1784 r2904 10 10 </tr> 11 11 </table> 12 <p><a href="<?php echo $ro->gen(null, array('name' => null)); ?>">Product ShortLink</a></p> -
branches/1.0/samples/app/modules/Default/validate/SearchEngineSpam.xml
r2396 r2904 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/1.0/samples/app/modules/Default/views/MenuSuccessView.class.php
r2371 r2904 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/1.0/samples/app/modules/Default/views/SearchEngineSpamErrorView.class.php
r2646 r2904 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 }

