Exemple #1
0
 /** 
  * This function is used to update user's profiletype
  * and its associated data. 
  * @param $userid
  * @param $ptype
  * @param $template
  * @param $what
  * @return unknown_type
  */
 function updateUserProfiletypeData($userid, $ptype, $template, $what = 'ALL')
 {
     XiptError::assert($userid, XiptText::_("USERID {$userid} IS_NOT_VALID"), XiptError::ERROR);
     $uModel = XiptFactory::getInstance('Users', 'model');
     //store prev profiletype
     //IMP : must be first line, as we want to store prev profiletype
     $prevProfiletype = XiptLibProfiletypes::getUserData($userid, 'PROFILETYPE');
     if ($what == 'profiletype' || $what == 'ALL') {
         // trigger an API for before profile type updation
         $dispatcher = JDispatcher::getInstance();
         $userInfo['userid'] = $userid;
         $userInfo['oldPtype'] = $prevProfiletype;
         $userInfo['newPtype'] =& $ptype;
         /* we are sending refrence of new ptype
          * this should be validate before save 
          */
         $dispatcher->trigger('onBeforeProfileTypeChange', array($userInfo));
         // validate profile type, may be changed in event triggered
         if (XiptLibProfiletypes::validateProfiletype($ptype) == false) {
             $ptype = XiptLibProfiletypes::getDefaultProfiletype();
         }
         if (!$template) {
             $template = XiptLibProfiletypes::getProfileTypeData($ptype, 'template');
         }
         //set profiletype and template for user in #__xipt_users table
         $result = $uModel->save(array('userid' => $userid, 'profiletype' => $ptype, 'template' => $template), $userid);
         //set profiletype and template field in #__community_fields_values table
         // also change the user's type in profiletype field.
         XiptLibJomsocial::updateCommunityCustomField($userid, $template, TEMPLATE_CUSTOM_FIELD_CODE);
         XiptLibJomsocial::updateCommunityCustomField($userid, $ptype, PROFILETYPE_CUSTOM_FIELD_CODE);
         // trigger an API for after profile type updation
         /* send success result */
         //send the result as true
         $dispatcher->trigger('onAfterProfileTypeChange', array($ptype, $result));
     }
     $feature = array();
     $oldData = array();
     $newData = array();
     //set usertype acc to profiletype in #__user table
     if ($what == 'ALL' || $what == 'jusertype') {
         $feature[] = 'jusertype';
         $oldData['jusertype'] = self::getProfiletypeData($prevProfiletype, 'jusertype');
         $newData['jusertype'] = self::getProfiletypeData($ptype, 'jusertype');
     }
     //set user avatar in #__community_users table
     if ($what == 'ALL' || $what == 'avatar') {
         $feature[] = 'avatar';
         $oldData['avatar'] = self::getProfiletypeData($prevProfiletype, 'avatar');
         $newAvatar = self::getProfiletypeData($ptype, 'avatar');
         if (JString::stristr($newAvatar, 'components/com_community/assets/user.png')) {
             $newAvatar = '';
         }
         $newData['avatar'] = $newAvatar;
     }
     //set user watermark
     if ($what == 'ALL' || $what == 'watermark') {
         $feature[] = 'watermark';
         $oldData['watermark'] = self::getProfiletypeData($prevProfiletype, 'watermark');
         $newData['watermark'] = self::getProfiletypeData($ptype, 'watermark');
     }
     //assign the default group
     if ($what == 'ALL' || $what == 'group') {
         $feature[] = 'group';
         $oldData['group'] = self::getProfiletypeData($prevProfiletype, 'group');
         $newData['group'] = self::getProfiletypeData($ptype, 'group');
     }
     //set privacy data
     if ($what == 'ALL' || $what == 'privacy') {
         $feature[] = 'privacy';
         $pModel = XiptFactory::getInstance('profiletypes', 'model');
         $oldPrivacy = $pModel->loadParams($prevProfiletype, 'privacy');
         $newPrivacy = $pModel->loadParams($ptype, 'privacy');
         $oldData['privacy'] = $oldPrivacy;
         $newData['privacy'] = $newPrivacy;
     }
     self::updateUserProfiletypeFilteredData($userid, $feature, $oldData, $newData);
     return true;
 }