/** * Saves a new or existing profile. * * @since 1.0 * @access public * @param null * * @author Mark Lee <*****@*****.**> */ public function store() { // Check for request forgeries! ES::checkToken(); $pid = $this->input->get('id', 0, 'int'); $cid = $this->input->get('cid', 0, 'int'); $post = $this->input->getArray('post'); // Determines if this is a new profile type $isNew = !$pid ? true : false; // Get the current task $task = $this->getTask(); $isCopy = $task == 'savecopy' ? true : false; // Load the profile type. $profile = ES::table('Profile'); if ($cid && $isCopy) { $profile->load($cid); //reset the pid $post['id'] = $cid; } else { $profile->load($pid); } // Bind the posted data. $profile->bind($post); // Get the current task since we need to know what to do after the storing is successful. $this->view->task = $task; // Bind the user group's that are associated with the profile. $gid = $this->input->get('gid', '', 'default'); // This is a minimum requirement to create a profile. if (!$gid) { $this->view->setMessage('COM_EASYSOCIAL_PROFILES_FORM_ERROR_SELECT_GROUP', SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__, $profile); } // Bind user groups for this profile. $profile->bindUserGroups($gid); // Validate the profile field. $valid = $profile->validate(); // If there's errors, just show the error. if ($valid !== true) { $this->view->setMessage($profile->getError(), SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__, $profile); } // Try to store the profile. if (!$profile->store()) { $this->view->setMessage($profile->getError(), SOCIAL_MSG_ERROR); return $this->view->store($profile); } // Bind the access $profile->bindAccess($post['access']); // If this profile is default, we need to ensure that the rest of the profiles are not default any longer. if ($profile->default) { $profile->makeDefault(); } // Store the avatar for this profile. $file = $this->input->files->get('avatar', ''); // Try to upload the profile's avatar if required if (!empty($file['tmp_name'])) { $profile->uploadAvatar($file); } // Get fields data separately as we need allowraw here $postfields = JRequest::getVar('fields', $default = null, $hash = 'POST', $type = 'none', $mask = JREQUEST_ALLOWRAW); // Set the fields for this profile type. if (!empty($postfields)) { $fieldsData = FD::json()->decode($postfields); $fieldsLib = FD::fields(); $fieldsLib->saveFields($profile->id, SOCIAL_TYPE_PROFILES, $fieldsData, array('copy' => $task === 'savecopy')); // After saving fields, we have to reset all the user's completed fields count in this profile FD::model('Users')->resetCompletedFieldsByProfileId($profile->id); } // Set the privacy for this profile type if (isset($post['privacy'])) { $privacyLib = FD::privacy(); $resetMap = $privacyLib->getResetMap('all'); $privacy = $post['privacy']; $ids = $post['privacyID']; $requireReset = isset($post['privacyReset']) ? true : false; $data = array(); if (count($privacy)) { foreach ($privacy as $group => $items) { foreach ($items as $rule => $val) { $id = $ids[$group][$rule]; $id = explode('_', $id); $obj = new stdClass(); $obj->id = $id[0]; $obj->mapid = $id[1]; $obj->value = $val; $obj->reset = false; //check if require to reset or not. $gr = strtolower($group . '.' . $rule); if ($gr != 'field.joomla_username' && $gr != 'field.joomla_email' && $gr != 'field.joomla_timezone' && $gr != 'field.joomla_fullname') { $gr = str_replace('_', '.', $gr); } if ($requireReset && in_array($gr, $resetMap)) { $obj->reset = true; } $data[] = $obj; } } } $privacyModel = FD::model('Privacy'); $privacyModel->updatePrivacy($profile->id, $data, SOCIAL_PRIVACY_TYPE_PROFILES); } // If this is a save as copy if ($isCopy && $pid) { $profile->copyAvatar($pid); } $message = 'COM_EASYSOCIAL_PROFILES_PROFILE_CREATED_SUCCESSFULLY'; if (!$isNew) { $message = 'COM_EASYSOCIAL_PROFILES_PROFILE_UPDATED_SUCCESSFULLY'; } if ($isCopy) { $message = 'COM_EASYSOCIAL_PROFILES_PROFILE_COPIED_SUCCESSFULLY'; } // Set message. $this->view->setMessage($message, SOCIAL_MSG_SUCCESS); return $this->view->call(__FUNCTION__, $profile); }
/** * Suggests a list of groups for a user. * * @since 1.3 * @access public * @param string * @return */ public function suggest() { // Check for request forgeries ES::checkToken(); ES::requireLogin(); // Get the search query $search = $this->input->get('search', '', 'word'); // Get exclusion list $exclusion = $this->input->get('exclusion', array(), 'array'); // Determines if the user is an admin $options = array('unpublished' => false, 'exclusion' => $exclusion); if ($this->my->isSiteAdmin()) { $options['unpublished'] = true; } // Load up the groups model $model = ES::model('Groups'); $groups = $model->search($search, $options); return $this->view->call(__FUNCTION__, $groups); }