b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/model/_goal.class.php - 173 lines - 3767 bytes - Summary - Text - Print

Description: This file implements the Goal class. b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements the Goal class.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   *
   8   * @package admin
   9   *
  10   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  11   * @author fplanque: Francois PLANQUE.
  12   *
  13   * @version $Id: _goal.class.php 3328 2013-03-26 11:44:11Z yura $
  14   */
  15  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  16  
  17  load_class( '_core/model/dataobjects/_dataobject.class.php', 'DataObject' );
  18  
  19  /**
  20   * Goal Class
  21   *
  22   * @package evocore
  23   */
  24  class Goal extends DataObject
  25  {
  26      var $name = '';
  27      var $key = '';
  28      var $redir_url = '';
  29  
  30      /**
  31       * @var double
  32       */
  33       var $default_value = '';
  34  
  35  
  36      /**
  37       * Constructor
  38       *
  39       * @param object Database row
  40       */
  41  	function Goal( $db_row = NULL )
  42      {
  43          // Call parent constructor:
  44          parent::DataObject( 'T_track__goal', 'goal_', 'goal_ID' );
  45  
  46          $this->delete_restrictions = array(
  47                  array( 'table'=>'T_track__goalhit', 'fk'=>'ghit_goal_ID', 'msg'=>T_('%d related goal hits') ),
  48              );
  49  
  50          $this->delete_cascades = array();
  51  
  52           if( $db_row )
  53          {
  54              $this->ID            = $db_row->goal_ID;
  55              $this->name          = $db_row->goal_name;
  56              $this->key           = $db_row->goal_key;
  57              $this->redir_url     = $db_row->goal_redir_url;
  58              $this->default_value = $db_row->goal_default_value;
  59          }
  60          else
  61          {    // Create a new goal:
  62          }
  63      }
  64  
  65  
  66      /**
  67       * Generate help title text for action
  68       *
  69       * @param string action code: edit, delete, etc.
  70       * @return string translated help string
  71       */
  72  	function get_action_title( $action )
  73      {
  74          switch( $action )
  75          {
  76              case 'edit': return T_('Edit this goal...');
  77              case 'copy': return T_('Duplicate this goal...');
  78              case 'delete': return T_('Delete this goal!');
  79              default:
  80                  return '';
  81          }
  82      }
  83  
  84  
  85      /**
  86       * Check permission on a persona
  87       *
  88       * @todo fp> break up central User::check_perm() so that add-on modules do not need to add code into User class.
  89       *
  90       * @return boolean true if granted
  91       */
  92  	function check_perm( $action= 'view', $assert = true )
  93      {
  94          /**
  95          * @var User
  96          */
  97          global $current_User;
  98  
  99          return $current_User->check_perm( 'stats', $action, $assert );
 100      }
 101  
 102  
 103      /**
 104       * Load data from Request form fields.
 105       *
 106       * @return boolean true if loaded data seems valid.
 107       */
 108  	function load_from_Request()
 109      {
 110          // Name
 111          $this->set_string_from_param( 'name', true );
 112  
 113          // Key
 114          $this->set_string_from_param( 'key', true );
 115  
 116          // Redir URL:
 117          $this->set_string_from_param( 'redir_url' );
 118  
 119          // Default value:
 120          param( 'goal_default_value', 'string' );
 121          param_check_decimal( 'goal_default_value', T_('Default value must be a number.') );
 122          $this->set_from_Request( 'default_value', 'goal_default_value', true  );
 123  
 124          return ! param_errors_detected();
 125      }
 126  
 127  
 128  	function get_name()
 129      {
 130          return $this->name;
 131      }
 132  
 133  
 134      /**
 135       * Set param value
 136       *
 137       * By default, all values will be considered strings
 138       *
 139       * @param string parameter name
 140       * @param mixed parameter value
 141       * @param boolean true to set to NULL if empty value
 142       * @return boolean true, if a value has been set; false if it has not changed
 143       */
 144  	function set( $parname, $parvalue, $make_null = false )
 145      {
 146          switch( $parname )
 147          {
 148              case 'default_value':
 149                  return $this->set_param( $parname, 'number', $parvalue, true );
 150  
 151              case 'redir_url':
 152                  return $this->set_param( $parname, 'string', $parvalue, true );
 153  
 154              case 'name':
 155              case 'key':
 156              default:
 157                  return $this->set_param( $parname, 'string', $parvalue, $make_null );
 158          }
 159      }
 160  
 161  
 162      /**
 163       * Check existence of specified goal in goal_key unique field.
 164       *
 165       * @return int ID if goal exists otherwise NULL/false
 166       */
 167  	function dbexists()
 168      {
 169          return parent::dbexists('goal_key', $this->key);
 170      }
 171  }
 172  
 173  ?>

title

Description

title

Description

title

Description

title

title

Body