Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | <?php /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* # ***** BEGIN LICENSE BLOCK ***** # This file is part of Plume Framework, a simple PHP Application Framework. # Copyright (C) 2001-2010 Loic d'Anterroches and contributors. # # Plume Framework is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Plume Framework is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # ***** END LICENSE BLOCK ***** */ Pluf::loadFunction( 'Pluf_Shortcuts_RenderToResponse' ); Pluf::loadFunction( 'Pluf_HTTP_URL_urlForView' ); /** * Manage and visualize the tests. * * It is possible to mark a test as inactive by picking a * winner. * * Check the urls.php file for the URL definition to integrate the * dashboard in your application/project. * * The permission used are: * * Pluf_AB.view-dashboard: The user can view the dasboard. * Pluf_AB.edit-test: The user can edit a test. * */ class Pluf_AB_Views { /** * Display the currently running tests. * * The name of the view in the urls must be 'pluf_ab_dashboard'. */ public $dasboard_precond = array ( array ( 'Pluf_Precondition::hasPerm' , 'Pluf_AB.view-dashboard' )); public function dashboard( $request , $match ) { $url = Pluf_HTTP_URL_urlForView( 'pluf_ab_dashboard' ); $can_edit = $request ->user->hasPerm( 'Pluf_AB.edit-test' ); if ( $can_edit && $request ->method == 'POST' ) { // We mark the winner. $form = new Pluf_AB_Form_MarkWinner( $request ->POST); if ( $form ->isValid()) { $form ->save(); $request ->user->setMessage(__( 'The test has been updated.' )); return new Pluf_HTTP_Response_Redirect( $url ); } } else { // To have it available for the control of the errors in // the template. $form = new Pluf_AB_Form_MarkWinner(); } // Get the list of tests $db = Pluf_AB::getDb(); $active = array (); $stopped = array (); foreach ( $db ->tests->find() as $test ) { $test [ 'stats' ] = Pluf_AB::getTestStats( $test ); if ( $test [ 'active' ]) { $active [] = $test ; } else { $stopped [] = $test ; } } return Pluf_Shortcuts_RenderToResponse( 'pluf/ab/dashboard.html' , array ( 'active' => $active , 'stopped' => $stopped , 'form' => $form , 'can_edit' => $can_edit , ), $request ); } /** * Display the list of funnels. * */ public $funnels_precond = array ( array ( 'Pluf_Precondition::hasPerm' , 'Pluf_AB.view-funnels' )); public function funnels( $request , $match ) { $url = Pluf_HTTP_URL_urlForView( 'pluf_ab_funnels' ); $funnels = Pluf_AB_Funnel::getFunnels(); return Pluf_Shortcuts_RenderToResponse( 'pluf/ab/funnels.html' , array ( 'funnels' => $funnels , ), $request ); } /** * Display a given funnel stats. * */ public $funnel_precond = array ( array ( 'Pluf_Precondition::hasPerm' , 'Pluf_AB.view-funnels' )); public function funnel( $request , $match ) { $periods = array ( 'yesterday' => __( 'Yesterday' ), 'today' => __( 'Today' ), '7days' => __( 'Last 7 days' ), 'all' => __( 'All time' )); $period = 'today' ; $nperiod = $periods [ $period ]; if (isset( $request ->REQUEST[ 'p' ]) and isset( $periods [ $request ->REQUEST[ 'p' ]])) { $period = $request ->REQUEST[ 'p' ]; $nperiod = $periods [ $request ->REQUEST[ 'p' ]]; } $props = Pluf_AB_Funnel::getFunnelProps( $match [1], $period ); $prop = null; if (isset( $request ->REQUEST[ 'prop' ]) and in_array( $request ->REQUEST[ 'prop' ], array_keys ( $props ))) { $prop = $request ->REQUEST[ 'prop' ]; } $stats = Pluf_AB_Funnel::getStats( $match [1], $period , $prop ); return Pluf_Shortcuts_RenderToResponse( 'pluf/ab/funnel.html' , array ( 'stats' => $stats , 'funnel' => $match [1], 'nperiod' => $nperiod , 'period' => $period , 'props' => $props , 'prop' => $prop , ), $request ); } /** * A simple view to redirect a user and convert it. * * To convert the user for the test 'my_test' and redirect it to * the URL 'http://www.example.com' add the following view in your * urls.php: * * <pre> * array('regex' => '#^/goto/example/$#', * 'base' => $base, * 'model' => 'Pluf_AB_Views', * 'method' => 'convRedirect', * 'name' => 'go_to_example', * 'params' => array('url' => 'http://www.example.com', * 'test' => 'my_test') * ); * </pre> * * Try to put a url which reflects the final url after redirection * to minimize the confusion for the user. In this example, in * your code or template you use the named url 'go_to_example'. * */ public function convRedirect( $request , $match , $p ) { Pluf_AB::convert( $p [ 'test' ], $request ); return new Pluf_HTTP_Response_Redirect( $p [ 'url' ]); } } |
Source at commit 4923c6efe552 created 10 years 5 months ago. By Nathan Adams, Changing formating of files |
---|