Skip to content

Commit

Permalink
Merge pull request #19 from vector/bugfix/18
Browse files Browse the repository at this point in the history
Fix issue #18
  • Loading branch information
mrw authored Jul 11, 2016
2 parents bdeb3ec + 7f06570 commit 5157292
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ee2/third_party/vmg_chosen_member/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

/**
Expand Down
35 changes: 25 additions & 10 deletions ee2/third_party/vmg_chosen_member/helper.php
Original file line number Diff line number Diff line change
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 @@ -713,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 @@ -894,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();
}

}

0 comments on commit 5157292

Please sign in to comment.