Code Monkey home page Code Monkey logo

vmg-chosen-member's Introduction

VMG Chosen Member

Fieldtype for ExpressionEngine 2 + 3

Note: if you're using ExpressionEngine 2, download VMG Chosen Member version 2.2.1 here.

VMG Chosen Member is a fieldtype for allowing the selection of one or more members inside an entry. It's specifically designed for use on sites with a large amount of members, in cases where a regular <select> dropdown with thousands of <option>s would decrease publish page performance.

It includes autocomplete capabilities and the friendly selection/listing of large numbers of members using a modified version of the Chosen JavaScript plugin. VMG Chosen Member also offers various methods of using the selected members within your templates.

VMG Chosen Member can be used alone, within Matrix, Low Variables, and Better Workflow.

Installation

  • Upload system/user/addons/vmg_chosen_member to system/user/addons
  • Upload themes/user/vmg_chosen_member to themes/user
  • Install the fieldtype by going to Add-Ons → Fieldtypes
  • Ensure that both the Fieldtype and Module are installed
  • See Importing Old Member Selections below if you are converting from a different field type that contains pipe-delimited member IDs.

Upgrading

  • Back up your database
  • Upload system/user/addons/vmg_chosen_member to system/user/addons
  • Upload themes/user/vmg_chosen_member to themes/user
  • Go to Add-Ons > Modules and click the "Run Module Updates" button

Importing Old Member Selections

If you are upgrading to VMG Chosen Member from a different field type that contains pipe-delimited member IDs, you can have those selection automatically imported in to VMG Chosen Member's data structure by following the steps below:

  • Ensure the desired fields have been switched to the VMG Chosen Member field type.
  • Go to Add-Ons > Modules > VMG Chosen Member
  • Click the "Convert old field data" button, and your previous selections will be automatically imported.

Usage

Single Variable Tag

{custom_field}

Outputs the pipe (|) delimited list of member IDs.

Parameters

  • member_id = "1|2|3"
    Limit returned members to those specified.
  • group_id = "1|2|3"
    While you can limit selections to specific member groups in the field's settings, this parameter allows you to further limit results on output.
  • orderby = "email"
    The orderby parameter sets the display order of the output.
  • sort = "asc"
    The sort order will be applied if you specify an orderby parameter.
  • limit = "1"
    The limit parameter will set the number of results that will be returned.
  • backspace = "0"
    Remove X number of characters from the final tag output.

Variable Tag Pair

{custom_field}
	<h2>{cm_screen_name}</h2>
	<p>Email: {cm_email}</p>
	<p>Some custom member field: {cm_some_custom_member_field}</p>
{/custom_field}

Outputs member data for the selected members and provides access to all data tags.
Note: A prefix of "cm_" is added by default, but can be manually changed or set to empty if desired.

Parameters

  • All parameters from the Single Tag Pair plus:
  • prefix = "cm_"
    Set to "cm_" by default
    By providing a prefix, all data tags will be parsed prepended with the string of your choosing. This can be helpful for avoiding naming collisions.
  • backspace = "0"
    Remove X number of characters from the final tag output.
  • disable = "member_data"
    Setting this to member_data will bypass the loading of custom member fields.

:total_members Tag

{chosen_member_field:total_members}

Outputs the total number of members selected within the field.

Associated Entries

To view Channel Entries that a member has been selected in (via a VMG Chosen Member field), you can use the {exp:vmg_chosen_member:assoc_entries} tag.

NOTE: As of v2.0, this tag mimics the functionality of a Channel Entries loop. To disable this, and simply return a pipe-delimited list of entry IDs, set display_entries="no".

{!-- Standard usage --}
{exp:vmg_chosen_member:assoc_entries
	field="chosen_member_field"
	member_id="1|2|3"
}

	<ul>
		{chosen_member_field prefix="cmf_"}

			<li>
				<h3>{cmf_screen_name}</h3>
				<img src="/path/to/avatars/{cmf_avatar_filename}"/>
			</li>

		{/chosen_member_field}
	</ul>

{/exp:vmg_chosen_member:assoc_entries}

{!-- Example of using display_entries="no" --}
{exp:vmg_chosen_member:assoc_entries
	field="chosen_member_field"
	member_id="1|2|3"
	prefix="cm_"
	display_entries="no"
}

	Pipe-delimited list of related entry IDs: {cm_entry_ids}

{/exp:vmg_chosen_member:assoc_entries}

Parameters

  • {exp:vmg_chosen_member:assoc_entries} can take nearly all of {exp:channel:entries}’ tag parameters, as well as the following:
  • field = "chosen_member_field"
    The VMG Chosen Member field you would like to search. If your VMG Chosen Member field is within a Matrix field, you would set the name of the parent Matrix field.
  • col = "my_matrix_col"
    If your VMG Chosen Member field is within a Matrix field, you would set the name of the Matrix column here.
  • member_id = "1|2|3"
    Member IDs that you would like to search for.
  • display_entries = "yes"
    Set to "yes" by default
    If "yes", this tag will mimic a Channel Entries loop. Otherwise, it returns a variable called {entry_ids} containing a pipe delimited list of all relevant entry IDs.
  • prefix = "cm_"
    Set to "cm_" by default
    If display_entries = "no", the {entry_ids} single variable will be parsed prepended with the string of your choosing. This can be helpful for avoiding naming collisions.

Returns all relevant entries. If display_entries = "no", outputs the prefixed {entry_ids} tag.

Usage with Channel Form / SafeCracker

In order to correctly render the Chosen field within Channel Form or SafeCracker, you will need to ensure that the field assets are loaded. Simply include the following tag somewhere on your page:

{exp:vmg_chosen_member:init_ft type="css|js"}

Note that you can pass a type parameter to render the CSS, JS, or both.

Support for other fieldtypes/add-ons

VMG Chosen Member can be used within Matrix, Low Variables, and Better Workflow.

Compatibility

VMG Chosen Member has been tested to work on ExpressionEngine 3.3+ with PHP 5.6+.

Warranty/License

There's no warranty of any kind. If you find a bug, please report it or submit a pull request with a fix. It's provided completely as-is; if something breaks, you lose data, or something else bad happens, the author(s) and owner(s) of this add-on are in no way responsible.

This add-on is owned by Vector Media Group, Inc. You can modify it and use it for your own personal or commercial projects, but you can't redistribute it.

vmg-chosen-member's People

Contributors

andparsons avatar lukewilkins avatar mrw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vmg-chosen-member's Issues

Will it work on EE 6.x

@lukewilkins Sorry to contact you this way. Just wondering if this plugin will work in EE 6.x. We use it extensively on our 2.x site which we are now finally upgrading to 6.x.

Thanks

Error, no Matrix installed

When using this:

{exp:vmg_chosen_member:assoc_entries
prefix="cm_"
field="initiative_member"
member_id="{logged_in_member_id}"
}
{cm_entry_ids}
{/exp:vmg_chosen_member:assoc_entries}

in ExpressionEngine 2.5.5, i get this:

Error Number: 1146

Table 'ee2_llb.exp_matrix_cols' doesn't exist

SELECT cf.field_id AS field_id, mc.col_id, IF(mc.col_id IS NULL, cf.field_name, mc.col_name) AS field_name FROM (exp_channel_fields AS cf) LEFT JOIN exp_matrix_cols AS mc ON mc.field_id = cf.field_id WHERE ((cf.field_type = 'vmg_chosen_member' || cf.field_type = 'matrix') AND cf.field_name = 'initiative_member')

Filename: third_party/vmg_chosen_member/mod.vmg_chosen_member.php

Line Number: 201

Without proper knowledge of your code it seems like your assoc_entries() function don't check for fieldtype like get_results() does.

Searching field types set to VMG Chosen Member in the Control Panel

I’m using VMG Chosen Member as a Field Type so administrators can easily add Members of a custom Member Group ‘Customers’ to different Channel Entries.
This is fine, but when in the Control Panel I cannot search or filter on this Field Type. I have set the VMG Chosen Member (Customer) to be searchable but this doesn’t make a difference.

This is a major issue for my client, as they will need to be able to search and filter entries in the CP by ‘Customer’.

Is this is an actual issue or something else I could do to get around it?

Field has lost its format…

After updating at the end of June, when a new version was posted, I have now noticed that the field has lost its features, and is a simple selected multi-select field with no search, etc.

Could this be to do with the themes? (they haven't been updated in the latest release)

I am on EE v2.8.1

See image below…

image

Many thanks
G

Update: Also, on a new entry, it is not picking up any members. It is a blank Multi-select field

image

Not working in Grid / EE3

If you try to define a CM field within a grid definition there are a three warnings given in the grid definition box, but you can define the field. However the field itself is not functional when you try and enter data in a channel entry.

The warnings are:

Warning

Invalid argument supplied for foreach()

ee/EllisLab/ExpressionEngine/View/_shared/form/fieldset.php, line 23
Warning

array_keys() expects parameter 1 to be array, null given

ee/EllisLab/ExpressionEngine/View/_shared/form/fieldset.php, line 49
Warning

Invalid argument supplied for foreach()

ee/EllisLab/ExpressionEngine/View/_shared/form/fieldset.php, line 101

Is this field meant to work within Grid? I realise it is not explicitly listed in MD file, but I see that it set to work within Matrix. Would be handy if it was working in Grid - if not possible perhaps modifying to remove field from Grid options... ?

Backspace not working

I can't seem to get backspace to work in my template. Do I need to set the style="linear" or something?

In my template:
{cf_c_member backspace="2"}{cm_screen_name}, {/cf_c_member}

Member Field Defaulting To Entire List

Hi there,

I'm encountering an issue where in creating a new entry with a VMG Chosen Member field, all members from the allowed group are selected by default. The member group as over 1,000 members so this makes it impractical to use. If I edit an existing entry in the same channel, I can choose members and add them one by one.

I've tried to find a setting or an option to change this, but I'm not seeing anything. Any help would be appreciated, thanks!

Screenshot

screen shot 2016-08-30 at 3 05 13 pm

Channel form

Hi, After updating to EE 2.8 (and channel forms), the field isn't populating on a Channel Form – I'm using Stash variable to stash the member_id in the "course_reps_member" Chosen Member field (which is hidden to the user). None of my code has changed and was working fine before the upgrade.

The member_id is populating in the value attribute (as below), but when I submit, and then go to control panel and check the new entry, the Chosen Member is blank.

This is my code rendered in channel form, with member_id 1748:

<div class="vmg-chosen-member-container">
    <select id="vmg_chosen_member_114_0_0_0" name="course_reps_member[]" class="vmg-chosen-member" rel="114_0_0_0">
        <option value="1748" selected="selected">1748</option>
    </select>
    <input type="hidden" id="vmg_chosen_member_114_0_0_0_field_id" value="114">
    <input type="hidden" id="vmg_chosen_member_114_0_0_0_col_id" value="0">
    <input type="hidden" id="vmg_chosen_member_114_0_0_0_var_id" value="0">
    <input type="hidden" id="vmg_chosen_member_114_0_0_0_max_selections" value="">
    <input type="hidden" id="vmg_chosen_member_114_0_0_0_placeholder_text" value="Begin typing a member's name...">
    <input type="hidden" class="vmg_chosen_member_json_url" value="http://my-domain/?ACT=31&amp;field_id=114&amp;col_id=0&amp;var_id=0">
</div>

Member still shown in single tag when member changed group

Thanks for this nice add-on. I limited selection to a single member group. With two members selected, the tagpair correctly will not show info for the member that has been moved to a different member group. The single tag however still outputs both members 3|4

JS error when Matrix not installed

I don't have Matrix installed and I get a JS error when the addon tries to access the undefined Matrix object.

Matrix.bind("vmg_chosen_member", "display", function(cell){

/themes/third_party/vmg_chosen_member/vmg_chosen_member.js LINE 22

Error Displaying Associated Entries

Hey there,

I'm currently using the ee3 branch in a new installation of ExpressionEngine 3.3.3. We have a bunch of entries from an old site that I was able to bring in to the new one and everything looks good on the backend. When I try to display associated entries for a given member on the frontend though, I get the error below:

Exception Caught

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db215353_ee.exp_matrix_cols' doesn't exist:
SELECT cf.field_id AS field_id, mc.col_id, IF(mc.col_id IS NULL, cf.field_name, mc.col_name) AS field_name FROM (exp_channel_fields AS cf) LEFT JOIN exp_matrix_cols AS mc ON mc.field_id = cf.field_id WHERE ((cf.field_type = 'vmg_chosen_member' || cf.field_type = 'matrix') AND cf.field_name = 'allowed_users') AND cf.field_type = 'vmg_chosen_member'

mysqli_connection.php:119

We're currently not using any matrix fields - not sure why it's looking for one. Here's the basic template:

{exp:vmg_chosen_member:assoc_entries
    field="allowed_users"
    member_id="120"
    channel="reports-client-projects"
    display_entries="yes"
}

   <li>{title}</li>

{/exp:vmg_chosen_member:assoc_entries}`

I would expect this to display a list of all entries in channel reports-client-projects where member ID 120 is selected in field allowed_users but instead get the error above.

I saw that there was an issue similar a few years ago for an older build – not sure if it's related?

Appreciate the help!
Shaun

Using Chosen Member for multiple authors

here is an example how VMG chosen member can be used to select several members who may edit an entry (multi-author). e.g. this needs allowing members to edit entries authored by others, but with chosen member we can limit who sees the embedded channel form.

{exp:channel entries url_title="segment_3" }
  {if chosen_field:author_or_chosen=="yes"}
    {embed="group/safecracker" entry_id="{entry_id}"}
  {/if}
{/exp:channel:entries}

Added a method replace_author_or_chosen:

    function replace_author_or_choosen($field_data, $params, $tagdata = FALSE)
    {
        // user is author
        $current = $this->EE->session->userdata('member_id');
        if($current == $this->row('author_id')) return 'yes';
        // no other members chosen
        if ($field_data =='') return 'no';
        // is current user chosen?
        $list = explode('|', $this->replace_tag($field_data, $params, FALSE));
        $list[] = $this->row('author_id');
        return (in_array($current, $list)) ? 'yes' : 'no';
    }

nb. this is a proof of concept, i need to check that there is no way to circumvent basic security with safecracker/channel form (e.g. post data not catched for wrong entries)

MSM

I can get it work in a SMS environnement.. ?!.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.