-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from vector/ee3
ExpressionEngine 3 compatibility
- Loading branch information
Showing
8 changed files
with
136 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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 | ||
*/ | ||
|
@@ -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 | ||
*/ | ||
|
@@ -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(); | ||
|
@@ -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 & 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 & 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); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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') | ||
|
@@ -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', | ||
); | ||
} | ||
|
||
|
@@ -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', | ||
); | ||
} | ||
|
||
|
@@ -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), | ||
|
@@ -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]; | ||
|
@@ -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'])); | ||
} | ||
|
||
|
@@ -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) . ")"); | ||
|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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')) { | ||
|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters