b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/model/_userfield.class.php - 300 lines - 7512 bytes - Summary - Text - Print

Description: This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file is part of the evoCore framework - {@link http://evocore.net/}
   4   * See also {@link http://sourceforge.net/projects/evocms/}.
   5   *
   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.
   8   *
   9   * {@internal License choice
  10   * - If you have received this file as part of a package, please find the license.txt file in
  11   *   the same folder or the closest folder above for complete license terms.
  12   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  13   *   then you must choose one of the following licenses before using the file:
  14   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  15   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  16   * }}
  17   *
  18   * {@internal Open Source relicensing agreement:
  19   * The Evo Factory grants Francois PLANQUE the right to license
  20   * The Evo Factory's contributions to this file and the b2evolution project
  21   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  22   * }}
  23   *
  24   * @package evocore
  25   *
  26   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  27   * @author evofactory-test
  28   * @author fplanque: Francois Planque.
  29   *
  30   * @version _userfield.class.php,v 1.5 2009/09/16 18:11:51 fplanque Exp
  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  load_class( '_core/model/dataobjects/_dataobject.class.php', 'DataObject' );
  35  
  36  /**
  37   * Userfield Class
  38   *
  39   * @package evocore
  40   */
  41  class Userfield extends DataObject
  42  {
  43      var $group_ID = '';
  44      var $type = '';
  45      var $name = '';
  46      var $options = NULL;
  47      var $required = 'optional';
  48      var $duplicated = 'allowed';
  49      var $order = '';
  50      var $suggest = '1';
  51      var $bubbletip = '';
  52  
  53      /**
  54       * Constructor
  55       *
  56       * @param object Database row
  57       */
  58  	function Userfield( $db_row = NULL )
  59      {
  60          // Call parent constructor:
  61          parent::DataObject( 'T_users__fielddefs', 'ufdf_', 'ufdf_ID' );
  62  
  63          // Allow inseting specific IDs
  64          $this->allow_ID_insert = true;
  65  
  66          $this->delete_restrictions = array();
  67  
  68          $this->delete_cascades = array();
  69  
  70          if( $db_row != NULL )
  71          {
  72              $this->ID         = $db_row->ufdf_ID;
  73              $this->group_ID   = $db_row->ufdf_ufgp_ID;
  74              $this->type       = $db_row->ufdf_type;
  75              $this->name       = $db_row->ufdf_name;
  76              $this->options    = $db_row->ufdf_options;
  77              $this->required   = $db_row->ufdf_required;
  78              $this->duplicated = $db_row->ufdf_duplicated;
  79              $this->order      = $db_row->ufdf_order;
  80              $this->suggest    = $db_row->ufdf_suggest;
  81              $this->bubbletip  = $db_row->ufdf_bubbletip;
  82          }
  83          else
  84          {    // Create a new user field:
  85          }
  86      }
  87  
  88  
  89      /**
  90       * Returns array of possible user field types
  91       *
  92       * @return array
  93       */
  94  	function get_types()
  95      {
  96          return array(
  97              'email'  => T_('Email address'),
  98              'word'   => T_('Single word'),
  99              'list'   => T_('Option list'),
 100              'number' => T_('Number'),
 101              'phone'  => T_('Phone number'),
 102              'url'    => T_('URL'),
 103              'text'   => T_('Text'),
 104           );
 105      }
 106  
 107  
 108      /**
 109       * Returns array of possible user field required types
 110       *
 111       * @return array
 112       */
 113  	function get_requireds()
 114      {
 115          return array(
 116              array( 'value' => 'hidden', 'label' => T_('Hidden') ),
 117              array( 'value' => 'optional', 'label' => T_('Optional') ),
 118              array( 'value' => 'recommended', 'label' => T_('Recommended') ),
 119              array( 'value' => 'require', 'label' => T_('Required') ),
 120           );
 121      }
 122  
 123  
 124      /**
 125       * Returns array of possible user field duplicated types
 126       *
 127       * @return array
 128       */
 129  	function get_duplicateds()
 130      {
 131          return array(
 132              array( 'value' => 'forbidden', 'label' => T_('Forbidden') ),
 133              array( 'value' => 'allowed', 'label' => T_('Allowed') ),
 134              array( 'value' => 'list', 'label' => T_('List style') ),
 135           );
 136      }
 137  
 138      /**
 139       * Returns array of user field groups
 140       *
 141       * @return array
 142       */
 143  	function get_groups()
 144      {
 145          global $DB;
 146  
 147          return $DB->get_assoc( '
 148              SELECT ufgp_ID, ufgp_name
 149                FROM T_users__fieldgroups
 150               ORDER BY ufgp_order, ufgp_ID' );
 151      }
 152  
 153  
 154      /**
 155       * Get last order number for current group
 156       * Used in the action add a new field OR move fielddef from other group
 157       *
 158       * @param integer Group ID
 159       * @return integer
 160       */
 161  	function get_last_order( $group_ID )
 162      {
 163          global $DB;
 164  
 165          $order = $DB->get_var( '
 166              SELECT MAX( ufdf_order )
 167                FROM T_users__fielddefs
 168               WHERE ufdf_ufgp_ID = '.$DB->quote( $group_ID ) );
 169  
 170          return $order + 1;
 171      }
 172  
 173  
 174      /**
 175       * Load data from Request form fields.
 176       *
 177       * @return boolean true if loaded data seems valid.
 178       */
 179  	function load_from_Request()
 180      {
 181          // Group
 182          param_string_not_empty( 'ufdf_ufgp_ID', T_('Please select a group.') );
 183          $this->set_from_Request( 'ufgp_ID' );
 184  
 185          // Type
 186          param_string_not_empty( 'ufdf_type', T_('Please enter a type.') );
 187          $this->set_from_Request( 'type' );
 188  
 189          // Name
 190          param_string_not_empty( 'ufdf_name', T_('Please enter a name.') );
 191          $this->set_from_Request( 'name' );
 192  
 193          // Options
 194          if( param( 'ufdf_type', 'string' ) == 'list' )
 195          {    // Save 'Options' only for Field type == 'Option list'
 196              $ufdf_options = explode( "\n", param( 'ufdf_options', 'text' ) );
 197              if( count( $ufdf_options ) < 2 )
 198              {    // We don't want save an option list with one item
 199                  param_error( 'ufdf_options', T_('Please enter at least 2 options on 2 different lines.') );
 200              }
 201              $this->set_from_Request( 'options' );
 202          }
 203          else
 204          { // The 'options' field must be set because it doesn't have a default value
 205              $this->set( 'options', '' );
 206          }
 207  
 208          // Required
 209          param_string_not_empty( 'ufdf_required', 'Please select Hidden, Optional, Recommended or Required.' );
 210          $this->set_from_Request( 'required' );
 211  
 212          // Duplicated
 213          param_string_not_empty( 'ufdf_duplicated', 'Please select Forbidden, Allowed or List style.' );
 214          $this->set_from_Request( 'duplicated' );
 215  
 216          // Order
 217          if( $this->group_ID != $this->ufgp_ID )
 218          {    // Group is changing, set order as last
 219              $this->set( 'order', $this->get_last_order( $this->ufgp_ID ) );
 220          }
 221  
 222          // Suggest
 223          if( param( 'ufdf_type', 'string' ) == 'word' )
 224          { // Save 'Suggest values' only for Field type == 'Single word'
 225              param( 'ufdf_suggest', 'integer', 0 );
 226              $this->set_from_Request( 'suggest' );
 227          }
 228  
 229          // Bubbletip
 230          param( 'ufdf_bubbletip', 'text', '' );
 231          $this->set_from_Request( 'bubbletip' );
 232  
 233          return ! param_errors_detected();
 234      }
 235  
 236  
 237      /**
 238       * Set param value
 239       *
 240       * By default, all values will be considered strings
 241       *
 242       * @param string parameter name
 243       * @param mixed parameter value
 244       */
 245  	function set( $parname, $parvalue )
 246      {
 247          switch( $parname )
 248          {
 249              case 'type':
 250              case 'name':
 251              case 'required':
 252              default:
 253                  $this->set_param( $parname, 'string', $parvalue );
 254          }
 255      }
 256  
 257  
 258      /**
 259       * Get user field name.
 260       *
 261       * @return string user field name
 262       */
 263  	function get_name()
 264      {
 265          return $this->name;
 266      }
 267  
 268  
 269      /**
 270       * Check existence of specified user field ID in ufdf_ID unique field.
 271       *
 272       * @todo dh> Two returns here!!
 273       * @return int ID if user field exists otherwise NULL/false
 274       */
 275  	function dbexists()
 276      {
 277          global $DB;
 278  
 279          $sql = "SELECT $this->dbIDname
 280                            FROM $this->dbtablename
 281                         WHERE $this->dbIDname = $this->ID";
 282  
 283          return $DB->get_var( $sql );
 284  
 285          return parent::dbexists('ufdf_ID', $this->ID);
 286      }
 287  }
 288  
 289  
 290  /*
 291   * _userfield.class.php,v
 292   * Revision 1.5  2009/09/16 18:11:51  fplanque
 293   * Readded with -kkv option
 294   *
 295   * Revision 1.1  2009/09/11 18:34:06  fplanque
 296   * userfields editing module.
 297   * needs further cleanup but I think it works.
 298   *
 299   */
 300  ?>

title

Description

title

Description

title

Description

title

title

Body