Skip to content

Commit

Permalink
Merge pull request #21 from vector/ee3
Browse files Browse the repository at this point in the history
ExpressionEngine 3 compatibility
  • Loading branch information
mrw authored Sep 1, 2016
2 parents e453aff + 5157292 commit 7ca6807
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 46 deletions.
15 changes: 15 additions & 0 deletions ee2/third_party/vmg_chosen_member/addon.setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

// include config file
require_once PATH_THIRD.'vmg_chosen_member/config.php';

return array(
'author' => 'Luke Wilkins',
'author_url' => 'http://www.vectormediagroup.com',
'name' => 'VMG Chosen Member',
'description' => 'VMG Chosen Member is a fieldtype allowing the AJAX selection of one or more members inside an entry.',
'version' => VMG_CM_VERSION,
'namespace' => 'Vector\VmgChosenMember',
'docs_url' => 'https://github.com/vector/VMG-Chosen-Member',
'settings_exist' => true,
);
4 changes: 2 additions & 2 deletions ee2/third_party/vmg_chosen_member/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/

if ( ! defined('VMG_CM_VERSION'))
{
define('VMG_CM_VERSION', '2.2');
define('VMG_CM_VERSION', '3.0.1');
}

/**
Expand Down
93 changes: 72 additions & 21 deletions ee2/third_party/vmg_chosen_member/ft.vmg_chosen_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/
class Vmg_chosen_member_ft extends EE_Fieldtype
{
Expand Down Expand Up @@ -43,6 +43,17 @@ public function __construct()
$this->cache =& ee()->session->cache['vmg_chosen_member'];
}

/**
* Grid compatibility.
*
* @param $name
* @return bool
*/
public function accepts_content_type($name)
{
return ($name == 'channel' || $name == 'grid');
}

/**
* Display the field
*/
Expand Down Expand Up @@ -105,6 +116,14 @@ public function display_var_field($data)
return $this->display_field($data);
}

/**
* Display Grid Field
*/
function grid_display_field($data)
{
return $this->display_field($data);
}

/**
* Display Tag
*/
Expand Down Expand Up @@ -261,7 +280,7 @@ public function display_var_tag($data, $params = array(), $tagdata = false)
/**
* Display the fieldtype settings
*/
public function display_settings($data, $return_settings = false)
public function display_settings($data)
{
// Prep member all possible groups
$groups = $this->chosen_helper->getMemberGroups();
Expand All @@ -282,48 +301,80 @@ public function display_settings($data, $return_settings = false)
// Build up the settings array
$settings = array(
array(
'<strong>Allowed groups</strong>',
form_multiselect('allowed_groups[]', $member_groups, ( ! empty($data['allowed_groups']) ? $data['allowed_groups'] : array()))
'title' => 'Allowed groups',
'desc' => null,
'fields' => array(
'allowed_groups' => array(
'value'=> ( ! empty($data['allowed_groups']) ? $data['allowed_groups'] : array(5)),
'type' => 'checkbox',
'choices' => $member_groups,
),
),
),
array(
'<strong>Max selections allowed</strong><br/>Leave blank for no limit.',
form_input('max_selections', ( ! empty($data['max_selections']) ? $data['max_selections'] : ''))
'title' => 'Max selections allowed',
'desc' => 'Leave blank for no limit.',
'fields' => array(
'max_selections' => array(
'value'=> ( ! empty($data['max_selections']) ? $data['max_selections'] : ''),
'type' => 'text',
)
),
),
array(
'<strong>Placeholder text</strong><br/>Displayed if <i>"Max selections allowed"</i> does not equal 1.',
form_input(array('name' => 'placeholder_text', 'class' => 'fullfield'), ( ! empty($data['placeholder_text']) ? $data['placeholder_text'] : 'Begin typing a member\'s name...'))
'title' => 'Placeholder text',
'desc' => 'Displayed if <i>"Max selections allowed"</i> does not equal 1.',
'fields' => array(
'placeholder_text' => array(
'value'=> ( ! empty($data['placeholder_text']) ? $data['placeholder_text'] : 'Begin typing a member\'s name...'),
'type' => 'text',
),
),
),
array(
'<strong>Search fields</strong><br/>Determines which member fields will be searched.<br/><i>Defaults to Username &amp; Screen Name if no selections are made.</i>',
form_multiselect('search_fields[]', $search_fields, ( ! empty($data['search_fields']) ? $data['search_fields'] : array()))
'title' => 'Search fields',
'desc' => 'Determines which member fields will be searched.<br/><i>Defaults to Username &amp; Screen Name if no selections are made.</i>',
'fields' => array(
'search_fields' => array(
'value'=> ( ! empty($data['search_fields']) ? $data['search_fields'] : array('username', 'screen_name')),
'type' => 'checkbox',
'choices' => $search_fields,
),
),
),
);

// Just return settings if this is matrix or low variable
if ($return_settings) {
return $settings;
}

// Return standard settings as table rows
foreach ($settings as $setting) {
ee()->table->add_row($setting[0], $setting[1]);
}
return array(
'field_options' => array(
'label' => 'field_options',
'group' => 'vmg_chosen_member',
'settings' => $settings,
),
);
}

/**
* Display the fieldtype cell settings
*/
public function display_cell_settings($data)
{
return $this->display_settings($data, true);
return $this->display_settings($data);
}

/**
* Display Variable Settings
*/
public function display_var_settings($data)
{
return $this->display_settings($data, true);
return $this->display_settings($data);
}

/**
* Display Grid Settings
*/
function grid_display_settings($data)
{
return $this->display_settings($data);
}

/**
Expand Down
55 changes: 38 additions & 17 deletions ee2/third_party/vmg_chosen_member/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/
class ChosenHelper
{
Expand Down Expand Up @@ -296,13 +296,8 @@ public function cleanUp()
}

// Remove old Matrix records (if Matrix is installed)
$matrix_check = (boolean) ee()->db->select('ft.fieldtype_id')
->from('exp_fieldtypes AS ft')
->where('ft.name', 'matrix')
->get()
->num_rows();

if ($matrix_check)
if ($this->checkMatrix())
{
$matrix_data = ee()->db->select('vcm.row_id')
->from('vmg_chosen_member AS vcm')
Expand Down Expand Up @@ -467,8 +462,8 @@ public function includeAssets()
public function buildCss()
{
return array(
ee()->config->item('theme_folder_url') . 'third_party/vmg_chosen_member/chosen/chosen.css',
ee()->config->item('theme_folder_url') . 'third_party/vmg_chosen_member/vmg_chosen_member.css',
ee()->config->item('theme_folder_url') . 'user/vmg_chosen_member/chosen/chosen.css',
ee()->config->item('theme_folder_url') . 'user/vmg_chosen_member/vmg_chosen_member.css',
);
}

Expand All @@ -479,8 +474,8 @@ public function buildCss()
public function buildJs()
{
return array(
ee()->config->item('theme_folder_url') . 'third_party/vmg_chosen_member/chosen/chosen.jquery.js',
ee()->config->item('theme_folder_url') . 'third_party/vmg_chosen_member/vmg_chosen_member.js',
ee()->config->item('theme_folder_url') . 'user/vmg_chosen_member/chosen/chosen.jquery.js',
ee()->config->item('theme_folder_url') . 'user/vmg_chosen_member/vmg_chosen_member.js',
);
}

Expand Down Expand Up @@ -543,7 +538,7 @@ public function initData(&$obj)
}

$obj->ft_data = array(
'entry_id' => $this->getSetting($obj, 'entry_id', 0, true),
'entry_id' => $this->getSetting($obj, 'content_id', 0, true),
'field_name' => $this->getSetting($obj, 'cell_name', 'field_name'),
'field_id' => $this->getSetting($obj, 'field_id', 0, true),
'row_id' => $this->getSetting($obj, 'row_id', 0, true),
Expand Down Expand Up @@ -572,7 +567,9 @@ public function initData(&$obj)
public function getSetting(&$obj, $name, $fallback, $literal_fallback = false)
{
// Try to locate the setting
if (isset($obj->settings[$name])) {
if (method_exists($obj, $name)) {
return $obj->$name();
} elseif (isset($obj->settings[$name])) {
return $obj->settings[$name];
} elseif (isset($obj->row[$name])) {
return $obj->row[$name];
Expand Down Expand Up @@ -661,6 +658,10 @@ public function fieldSettings($field_id, $col_id = 0, $var_id = 0)
}

if (isset($settings['setting_data'])) {
if ($json = json_decode($settings['setting_data'], true)) {
return $json;
}

return unserialize(base64_decode($settings['setting_data']));
}

Expand Down Expand Up @@ -707,10 +708,17 @@ public function memberAutoComplete($settings, $search_fields, $search_fields_whe
*/
public function convertFieldName($field_name, $column_name = false)
{
ee()->db->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", false)
->from('channel_fields AS cf')
->join('matrix_cols AS mc', 'mc.field_id = cf.field_id', 'left')
->where("((cf.field_type = 'vmg_chosen_member' || cf.field_type = 'matrix') AND cf.field_name = " . ee()->db->escape($field_name) . ")");

if ($this->checkMatrix()) {
ee()->db->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", false)
->join('matrix_cols AS mc', 'mc.field_id = cf.field_id', 'left');
} else {
ee()->db->select("cf.field_id AS field_id, NULL as col_id, cf.field_name AS field_name", false);
}

ee()->db->from('channel_fields AS cf');

ee()->db->where("((cf.field_type = 'vmg_chosen_member' || cf.field_type = 'matrix') AND cf.field_name = " . ee()->db->escape($field_name) . ")");

if ( ! empty($column_name)) {
ee()->db->where("(cf.field_type = 'matrix' AND mc.col_type = 'vmg_chosen_member' AND mc.col_name = " . ee()->db->escape($column_name) . ")");
Expand Down Expand Up @@ -888,4 +896,17 @@ private function saveAssociation($entry)
return true;
}

/**
* Checks if Matrix is installed
* @return boolean
*/
private function checkMatrix()
{
return (boolean) ee()->db->select('ft.fieldtype_id')
->from('exp_fieldtypes AS ft')
->where('ft.name', 'matrix')
->get()
->num_rows();
}

}
9 changes: 6 additions & 3 deletions ee2/third_party/vmg_chosen_member/mcp.vmg_chosen_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/
class Vmg_chosen_member_mcp
{
Expand All @@ -21,7 +21,7 @@ class Vmg_chosen_member_mcp
*/
public function __construct()
{
$this->_base_url = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=vmg_chosen_member';
$this->_base_url = 'index.php?/cp/addons/settings/vmg_chosen_member';

// Load our helper
if ( ! class_exists('ChosenHelper') || ! is_a($this->chosen_helper, 'ChosenHelper')) {
Expand All @@ -45,7 +45,10 @@ public function index()
// Convert data from standard fields
$this->chosen_helper->convertStandardFieldData();

ee()->session->set_flashdata('message_success', 'Successfully built VMG Chosen Member data!');
ee('CP/Alert')->makeBanner('Success!')
->asSuccess()
->withTitle('Successfully built VMG Chosen Member data!')
->defer();

return ee()->functions->redirect($this->_base_url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/
class Vmg_chosen_member {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @package VMG Chosen Member
* @author Luke Wilkins <[email protected]>
* @copyright Copyright (c) 2011-2015 Vector Media Group, Inc.
* @copyright Copyright (c) 2011-2016 Vector Media Group, Inc.
*/
class Vmg_chosen_member_upd
{
Expand Down
2 changes: 1 addition & 1 deletion ee2/third_party/vmg_chosen_member/views/cp_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<input type="hidden" value="yes" name="convert_data_go" />
<p style="font-weight:bold;">Click "Convert old field data" to automatically parse old field data in to VMG Chosen Member.</p>
<p>This is needed when switching to VMG Chosen Member from a different field type that stores pipe-delimited member IDs.</p>
<?php echo form_submit(array('name' => 'submit', 'value' => 'Convert old field data', 'class' => 'submit'));?>
<?php echo form_submit(array('name' => 'submit', 'value' => 'Convert old field data', 'class' => 'btn action'));?>
<?php echo form_close()?>

0 comments on commit 7ca6807

Please sign in to comment.