/** * Searches for groups * * @since 1.3 * @access public * @param string * @return */ public function search($keyword, $options = array()) { $db = ES::db(); $sql = $db->sql(); $sql->select('#__social_clusters'); $sql->where('cluster_type', SOCIAL_TYPE_GROUP); $sql->where('title', '%' . $keyword . '%', 'LIKE'); // Determines if we should search for unpublished groups as well $unpublished = isset($options['unpublished']) && $options['unpublished'] ? true : false; if (!$unpublished) { $sql->where('state', SOCIAL_STATE_PUBLISHED); } // Determines if we should exclude specific group ids $exclusion = isset($options['exclusion']) && $options['exclusion'] ? $options['exclusion'] : false; if ($exclusion) { $exclusion = ES::makeArray($exclusion); $sql->where('id', $exclusion, 'NOT IN'); } $db->setQuery($sql); $result = $db->loadObjectList(); $groups = array(); if (!$result) { return $groups; } foreach ($result as $row) { $group = FD::group(); $group->bind($row); $groups[] = $group; } return $groups; }
/** * Updates a user profile * * @since 1.0 * @access public * @param string * @return */ public function updateUserProfile($uid, $profileId) { $map = ES::table('ProfileMap'); $exists = $map->load(array('user_id' => $uid)); if (!$exists) { $map->user_id = $uid; $map->state = SOCIAL_STATE_PUBLISHED; } $map->profile_id = $profileId; $state = $map->store(); if (!$state) { $this->setError($map->getError()); return $state; } $db = ES::db(); $sql = $db->sql(); $sql->update('#__social_fields_data', 'a'); $sql->leftjoin('#__social_fields', 'b'); $sql->on('a.field_id', 'b.id'); $sql->leftjoin('#__social_fields', 'c'); $sql->on('b.unique_key', 'c.unique_key'); $sql->leftjoin('#__social_fields_steps', 'd'); $sql->on('c.step_id', 'd.id'); $sql->set('a.field_id', 'c.id', false); $sql->where('a.uid', $uid); $sql->where('a.type', 'user'); $sql->where('d.type', 'profiles'); $sql->where('d.uid', $profileId); $db->setQuery($sql); $state = $db->query(); if ($state) { // Update fields privacy according to the new profile $sql = $db->sql(); // update `jos_social_privacy_items as a // left join jos_social_fields as b // on a.uid = bid and a.type = 'field' // left join jos_social_fields as c // on b.unique_key = c.unique_key // left join jos_social_fields_steps as d // on c.step_id = d.id // set a.uid = c.id // where a.user_id = $uid // and a.type = 'field' // and d.type = 'profiles' // and d.uid = $profileId; $sql->update('#__social_privacy_items', 'a'); $sql->leftjoin('#__social_fields', 'b'); $sql->on('a.uid', 'b.id'); $sql->leftjoin('#__social_fields', 'c'); $sql->on('b.unique_key', 'c.unique_key'); $sql->leftjoin('#__social_fields_steps', 'd'); $sql->on('c.step_id', 'd.id'); $sql->set('a.uid', 'c.id', false); $sql->where('a.user_id', $uid); $sql->where('('); $sql->where('a.type', 'field'); $sql->where('a.type', 'year', '=', 'OR'); $sql->where(')'); $sql->where('d.type', 'profiles'); $sql->where('d.uid', $profileId); $db->setQuery($sql); $state = $db->query(); } return $state; }