[ Index ]

PHP Cross Reference of Xoops v2.3.1

[Global whois Lookup]    [Ranchi, Jharkhand, India website]     [Hindi Magazine]     [Desi Community website in tristate area]    [B 4 Bollywood]    [Internet nation of India]

title

Body

[close]

/modules/profile/class/ -> profile.php (source)

   1  <?php
   2  /**

   3   * Extended User Profile

   4   *

   5   * You may not change or alter any portion of this comment or credits

   6   * of supporting developers from this source code or any supporting source code 

   7   * which is considered copyrighted (c) material of the original comment or credit authors.

   8   * This program is distributed in the hope that it will be useful,

   9   * but WITHOUT ANY WARRANTY; without even the implied warranty of

  10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  11   *

  12   * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/

  13   * @license         http://www.fsf.org/copyleft/gpl.html GNU public license

  14   * @package         profile

  15   * @since           2.3.0

  16   * @author          Jan Pedersen

  17   * @author          Taiwen Jiang <phppp@users.sourceforge.net>

  18   * @version         $Id: profile.php 2196 2008-09-29 14:29:32Z phppp $

  19   */
  20  
  21  /**

  22   * @package kernel

  23   * @copyright copyright &copy; 2000 XOOPS.org

  24   */
  25  class ProfileProfile extends XoopsObject 
  26  {
  27      function __construct($fields) 
  28      {
  29          $this->initVar('profile_id', XOBJ_DTYPE_INT, null, true);
  30          $this->init($fields);
  31      }
  32      
  33      function ProfileProfile($fields) 
  34      {
  35          $this->__construct($fields);
  36      }
  37  
  38      /**

  39      * Initiate variables

  40      * @param array $fields field information array of {@link XoopsProfileField} objects

  41      */
  42      function init($fields) 
  43      {
  44          if (is_array($fields) && count($fields) > 0) {
  45              foreach (array_keys($fields) as $key) {
  46                  $this->initVar($key, $fields[$key]->getVar('field_valuetype'), $fields[$key]->getVar('field_default', 'n'), $fields[$key]->getVar('field_required'), $fields[$key]->getVar('field_maxlength'));
  47              }
  48          }
  49      }
  50  }
  51  /**

  52   * @package kernel

  53   * @copyright copyright &copy; 2000 XOOPS.org

  54   */
  55  class ProfileProfileHandler extends XoopsPersistableObjectHandler 
  56  {
  57      /**

  58      * holds reference to {@link profileFieldHandler} object

  59      */
  60      var $_fHandler;
  61  
  62      /**

  63      * Array of {@link XoopsProfileField} objects

  64      * @var array

  65      */
  66      var $_fields = array();
  67  
  68      function __construct(&$db) 
  69      {
  70          parent::__construct($db, "profile_profile", 'profileprofile', "profile_id");
  71          $this->_fHandler = xoops_getmodulehandler('field', 'profile');
  72      }
  73  
  74      /**

  75       * create a new {@link ProfileProfile}

  76       *

  77       * @param bool $isNew Flag the new objects as "new"?

  78       *

  79       * @return object {@link ProfileProfile}

  80       */
  81      function &create($isNew = true) 
  82      {
  83          $obj =& new $this->className($this->loadFields());
  84  
  85          $obj->handler =& $this;
  86          if ($isNew === true) {
  87              $obj->setNew();
  88          }
  89          return $obj;
  90      }
  91  
  92      /**

  93       * Get a {@link ProfileProfile}

  94       *

  95       * @param   boolean $createOnFailure create a new {@link ProfileProfile} if none is feteched

  96       *

  97       * @return  object {@link ProfileProfile}

  98       */
  99      function &get($uid, $createOnFailure = true) 
 100      {
 101          $obj = parent::get($uid);
 102          if (!is_object($obj) && $createOnFailure) {
 103              $obj = $this->create();
 104          }
 105          return $obj;
 106      }
 107  
 108      /**

 109      * Create new {@link profileField} object

 110      * 

 111      * @param bool $isNew

 112      *

 113      * @return object

 114      */
 115      function &createField($isNew = true) 
 116      {
 117          $return =& $this->_fHandler->create($isNew);
 118          return $return;
 119      }
 120  
 121      /**

 122      * Load field information

 123      *

 124      * @return array

 125      */
 126      function loadFields() 
 127      {
 128          if (count($this->_fields) == 0) {
 129              $this->_fields = $this->_fHandler->loadFields();
 130          }
 131          return $this->_fields;
 132      }
 133  
 134      /**

 135      * Fetch fields

 136      *

 137      * @param object $criteria {@link CriteriaElement} object

 138      * @param bool $id_as_key return array with field IDs as key?

 139      * @param bool $as_object return array of objects?

 140      *

 141      * @return array

 142      **/
 143      function getFields($criteria, $id_as_key = true, $as_object = true) 
 144      {
 145          return $this->_fHandler->getObjects($criteria, $id_as_key, $as_object);
 146      }
 147  
 148      /**

 149      * Insert a field in the database

 150      *

 151      * @param object $field

 152      * @param bool $force

 153      *

 154      * @return bool

 155      */
 156      function insertField(&$field, $force = false) 
 157      {
 158          return $this->_fHandler->insert($field, $force);
 159      }
 160  
 161      /**

 162      * Delete a field from the database

 163      *

 164      * @param object $field

 165      * @param bool $force

 166      *

 167      * @return bool

 168      */
 169      function deleteField(&$field, $force = false) 
 170      {
 171          return $this->_fHandler->delete($field, $force);
 172      }
 173  
 174      /**

 175      * Save a new field in the database

 176      *

 177      * @param array $vars array of variables, taken from $module->loadInfo('profile')['field']

 178      * @param int $categoryid ID of the category to add it to

 179      * @param int $type valuetype of the field

 180      * @param int $moduleid ID of the module, this field belongs to

 181      * @param int $weight

 182      *

 183      * @return string

 184      **/
 185      function saveField($vars, $weight = 0) 
 186      {
 187          $field =& $this->createField();
 188          $field->setVar('field_name', $vars['name']);
 189          $field->setVar('field_valuetype', $vars['valuetype']);
 190          $field->setVar('field_type', $vars['type']);
 191          $field->setVar('field_weight', $weight);
 192          if (isset($vars['title'])) {
 193              $field->setVar('field_title', $vars['title']);
 194          }
 195          if (isset($vars['description'])) {
 196              $field->setVar('field_description', $vars['description']);
 197          }
 198          if (isset($vars['required'])) {
 199              $field->setVar('field_required', $vars['required']); //0 = no, 1 = yes

 200          }
 201          if (isset($vars['maxlength'])) {
 202              $field->setVar('field_maxlength', $vars['maxlength']);
 203          }
 204          if (isset($vars['default'])) {
 205              $field->setVar('field_default', $vars['default']);
 206          }
 207          if (isset($vars['notnull'])) {
 208              $field->setVar('field_notnull', $vars['notnull']);
 209          }
 210          if (isset($vars['show'])) {
 211              $field->setVar('field_show', $vars['show']);
 212          }
 213          if (isset($vars['edit'])) {
 214              $field->setVar('field_edit', $vars['edit']);
 215          }
 216          if (isset($vars['config'])) {
 217              $field->setVar('field_config', $vars['config']);
 218          }
 219          if (isset($vars['options'])) {
 220              $field->setVar('field_options', $vars['options']);
 221          } else {
 222              $field->setVar('field_options', array());
 223          }
 224          if ($this->insertField($field)) {
 225              $msg = '&nbsp;&nbsp;Field <b>'.$vars['name'].'</b> added to the database';
 226          } else {
 227              $msg = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert field <b>'.$vars['name'].'</b> into the database. '.implode(' ', $field->getErrors()).$this->db->error().'</span>';
 228          }
 229          unset($field);
 230          return $msg;
 231      }
 232  
 233      /**

 234       * insert a new object in the database

 235       *

 236       * @param object $obj reference to the object

 237       * @param bool $force whether to force the query execution despite security settings

 238       * @param bool $checkObject check if the object is dirty and clean the attributes

 239       * 

 240       * @return bool FALSE if failed, TRUE if already present and unchanged or successful

 241       */
 242  
 243      function insert(&$obj, $force = false, $checkObject = true) 
 244      {
 245          $uservars = $this->getUserVars();
 246          foreach ($uservars as $var) {
 247              unset($obj->vars[$var]);
 248          }
 249          if (count($obj->vars) == 0) {
 250              return true;
 251          }
 252          return parent::insert($obj, $force, $checkObject);
 253      }
 254  
 255  
 256      /**

 257       * Get array of standard variable names (user table)

 258       *

 259       * @return array

 260       */
 261      function getUserVars() 
 262      {
 263          return $this->_fHandler->getUserVars();
 264      }
 265  
 266      /**

 267       * Search profiles and users

 268       *

 269       * @param CriteriaElement $criteria

 270       * 

 271       * @return array

 272       */
 273      function search($criteria, $searchvars) 
 274      {
 275          $sql =  "SELECT uid, uname, user_viewemail, email, " . implode(',', $searchvars) . 
 276                  " FROM " . $this->db->prefix("users") . " LEFT JOIN " . $this->table . " ON uid=profile_id";
 277          $sql .= ' ' . $criteria->renderWhere();
 278          if ($criteria->getSort() != '') {
 279              $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
 280          }
 281          $limit = $criteria->getLimit();
 282          $start = $criteria->getStart();
 283  
 284          $result = $this->db->query($sql, $limit, $start);
 285          
 286          if (!$result) {
 287              return array(array(), array(), 0);
 288          }
 289          $user_handler = xoops_gethandler('user');
 290          $uservars = $this->getUserVars();
 291          $users = array();
 292          $profiles = array();
 293          while ($myrow = $this->db->fetchArray($result)) {
 294              $profile = $this->create(false);
 295              $user = $user_handler->create(false);
 296              
 297              foreach ($myrow as $name => $value) {
 298                  if (in_array($name, $uservars)) {
 299                     $user->assignVar($name, $value);
 300                  } else {
 301                      $profile->assignVar($name, $value);
 302                  }
 303              }
 304              $profiles[$myrow['uid']] = $profile;
 305              $users[$myrow['uid']] = $user;
 306          }
 307          
 308          $sql_count  = "SELECT count(*) FROM " . $this->db->prefix("users") . " LEFT JOIN " . $this->table . " ON uid=profile_id";
 309          $sql_count .= ' ' . $criteria->renderWhere();
 310          $count_res = $this->db->query($sql_count);
 311          list($count) = $this->db->fetchRow($count_res);
 312          
 313          return array($users, $profiles, $count);
 314      }
 315  }
 316  ?>


[ Xoops]     [PhpNuke]     [PostNuke]     [Joomla]    [Drupal]    [E107]    [NucleusCms]
[Php-Fusion]     [PhpBB]     [WordPress]     [Typo3]
Generated: Mon Oct 27 11:51:45 2008
Open Source related documentation for developers.