Changeset 2904

Show
Ignore:
Timestamp:
09/19/08 16:57:48 (4 months ago)
Author:
david
Message:

merge [2876:2903/branches/0.11]

Location:
branches/1.0
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/CHANGELOG

    r2891 r2904  
    73730.11.3 RC3 (September ??, 2008) 
    7474------------------------------- 
     75 
     76CHG: Improve sample app SearchEngineSpamAction to use ID and optionally name (#859) (David) 
    7577 
    7678FIX: AgaviXmlrpcepiphpResponse::setHttpStatusCode() is not implemented but gets called in sample app Error404SuccessView (#849) (David) 
  • branches/1.0/samples/app/config/routing.xml

    r2648 r2904  
    2828      <route name="search_engine_spam" pattern="^/products(/buy-cheap-{name:[\S\s]+}-at-agavi-dot-org)?/(id:\d+)" module="Default" action="SearchEngineSpam"> 
    2929        <defaults> 
    30           <default for="name">/buy-cheap-{chainsaws}-at-agavi-dot-org</default> 
     30          <default for="name">/buy-cheap-{}-at-agavi-dot-org</default> 
    3131        </defaults> 
    3232      </route> 
     
    4444      <route pattern="^getItemPrice$" module="Default" action="SearchEngineSpam" method="read"> 
    4545        <wsdl:input> 
    46           <wsdl:part name="name" type="xsd:string" /> 
     46          <wsdl:part name="id" type="xsd:int" /> 
    4747        </wsdl:input> 
    4848        <wsdl:output> 
  • branches/1.0/samples/app/modules/Default/actions/SearchEngineSpamAction.class.php

    r2733 r2904  
    55  public function executeRead(AgaviRequestDataHolder $rd) 
    66  { 
    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    } 
    918    if($price !== null) { 
     19      $this->setAttribute('product_id', $id); 
     20      $this->setAttribute('product_name', $name); 
    1021      $this->setAttribute('product_price', $price); 
    1122      return 'Success'; 
  • branches/1.0/samples/app/modules/Default/cache/SearchEngineSpam.xml

    r2384 r2904  
    77      <caching method="read" lifetime="2 hours"> 
    88         
    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> 
    1012        <group source="request_parameter">name</group> 
    1113        <group source="locale" /> 
  • branches/1.0/samples/app/modules/Default/models/PriceFinderModel.class.php

    r2733 r2904  
    33class Default_PriceFinderModel extends AgaviSampleAppDefaultBaseModel implements AgaviISingletonModel 
    44{ 
     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   
    539  public function getPriceByProductName($productName) 
    640  { 
    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      } 
    2072    } 
    2173  } 
  • branches/1.0/samples/app/modules/Default/templates/MenuSuccess.php

    r1784 r2904  
    99  <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> 
    1010  <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> 
    1212</ul> 
  • branches/1.0/samples/app/modules/Default/templates/SearchEngineSpamSuccess.php

    r1784 r2904  
    1010  </tr> 
    1111</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  
    1414 
    1515      <!-- 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"> 
    1717        <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> 
    1923      </validator> 
    2024 
  • branches/1.0/samples/app/modules/Default/views/MenuSuccessView.class.php

    r2371 r2904  
    2222    $this->setupHtml($rd); 
    2323 
    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)]); 
    2627  } 
    2728 
  • branches/1.0/samples/app/modules/Default/views/SearchEngineSpamErrorView.class.php

    r2646 r2904  
    3131    // fault code must be "Server", check the SOAP spec 
    3232    // 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')); 
    3434  } 
    3535 
     
    3939  public function executeXmlrpc(AgaviRequestDataHolder $rd) 
    4040  { 
    41     return array('faultCode' => 101, 'faultString' => 'Unknown Product "' . $this->getAttribute('product_name') . '"'); 
     41    return array('faultCode' => 101, 'faultString' => 'Unknown Product ' . $rd->getParameter('id')); 
    4242  } 
    4343}