Skip to content

Instantly share code, notes, and snippets.

@litzinger
Created February 16, 2012 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litzinger/1844814 to your computer and use it in GitHub Desktop.
Save litzinger/1844814 to your computer and use it in GitHub Desktop.
Matrix and Playa diffs for hooks
diff -rupN /Users/litzinger/Dropbox/add-ons/_others/Matrix2.2.4/ee2/third_party/matrix/ft.matrix.php matrix/ft.matrix.php
--- /Users/litzinger/Dropbox/add-ons/_others/Matrix2.2.4/ee2/third_party/matrix/ft.matrix.php 2012-01-24 11:17:48.000000000 -0600
+++ matrix/ft.matrix.php 2012-02-15 21:11:48.000000000 -0600
@@ -1494,7 +1494,20 @@ class Matrix_ft extends EE_Fieldtype {
$this->EE->db->limit($max_rows);
}
- $query = $this->EE->db->get('matrix_data')->result_array();
+ // -------------------------------------------
+ // 'matrix_display_query' hook
+ // - Override the SQL query
+ //
+ if ($this->EE->extensions->active_hook('matrix_display_field'))
+ {
+ $query = $this->EE->extensions->call('matrix_display_field', $this, array('field_id' => $field_id, 'entry_id' => $entry_id));
+ }
+ else
+ {
+ $query = $this->EE->db->get('matrix_data')->result_array();
+ }
+ //
+ // -------------------------------------------
// is this a clone?
$clone = ($this->EE->input->get('clone') == 'y');
@@ -1935,6 +1948,17 @@ class Matrix_ft extends EE_Fieldtype {
$row_data['entry_id'] = $this->settings['entry_id'];
$row_data['field_id'] = $field_id;
+ // -------------------------------------------
+ // 'matrix_save' hook
+ // - Add additional values to $row_data
+ //
+ if ($this->EE->extensions->active_hook('matrix_save'))
+ {
+ $row_data = $this->EE->extensions->call('matrix_save', $this, $this->settings['entry_id'], $row_data);
+ }
+ //
+ // -------------------------------------------
+
// insert the row
$this->EE->db->insert('matrix_data', $row_data);
Binary files /Users/litzinger/Dropbox/add-ons/_others/Playa4.1.0.3/Playa4/ee2/third_party/playa/.DS_Store and playa/.DS_Store differ
diff -rupN /Users/litzinger/Dropbox/add-ons/_others/Playa4.1.0.3/Playa4/ee2/third_party/playa/ft.playa.php playa/ft.playa.php
--- /Users/litzinger/Dropbox/add-ons/_others/Playa4.1.0.3/Playa4/ee2/third_party/playa/ft.playa.php 2011-11-17 15:11:06.000000000 -0600
+++ playa/ft.playa.php 2012-01-29 14:34:17.000000000 -0600
@@ -1354,12 +1354,23 @@ class Playa_ft extends EE_Fieldtype {
$where['parent_col_id'] = $this->col_id;
$where['parent_row_id'] = $this->row_id;
}
-
+
+ // -------------------------------------------
+ // 'playa_display_field' hook
+ // - Override the SQL query
+ //
+ if ($this->EE->extensions->active_hook('playa_display_field'))
+ {
+ $where = $this->EE->extensions->call('playa_display_field', $this, $where);
+ }
+ //
+ // -------------------------------------------
+
$rels = $this->EE->db->select('child_entry_id')
->where($where)
->order_by('rel_order')
->get('playa_relationships');
-
+
foreach ($rels->result() as $rel)
{
$vars['selected_entry_ids'][] = $rel->child_entry_id;
@@ -1925,7 +1936,7 @@ class Playa_ft extends EE_Fieldtype {
'parent_col_id' => $this->settings['col_id'],
'parent_row_id' => $this->settings['row_id']
);
-
+
// save the changes
$keywords = $this->_save_rels($selections, $data);
@@ -1940,6 +1951,17 @@ class Playa_ft extends EE_Fieldtype {
private function _save_rels($selections, $data)
{
$r = '';
+
+ // -------------------------------------------
+ // 'playa_save' hook
+ // - Update the $data array for the where selection
+ //
+ if ($this->EE->extensions->active_hook('playa_save'))
+ {
+ $data = $this->EE->extensions->call('playa_save', $this, $selections, $data);
+ }
+ //
+ // -------------------------------------------
// Delete existing relationships
$this->EE->db->where($data)
diff -rupN /Users/litzinger/Dropbox/add-ons/_others/Playa4.1.0.3/Playa4/ee2/third_party/playa/mod.playa.php playa/mod.playa.php
--- /Users/litzinger/Dropbox/add-ons/_others/Playa4.1.0.3/Playa4/ee2/third_party/playa/mod.playa.php 2011-11-17 15:11:06.000000000 -0600
+++ playa/mod.playa.php 2012-01-29 15:42:49.000000000 -0600
@@ -394,6 +394,17 @@ class Playa
. ($row_ids ? implode(',', $row_ids) : '*') . '|'
. ($filter_ids['child'] ? str_replace('|', ',', $filter_ids['child']) : '*')
. ($filter_ids['parent'] ? str_replace('|', ',', $filter_ids['parent']) : '*');
+
+ // -------------------------------------------
+ // 'playa_cache_key' hook
+ // - Update the cache key
+ //
+ if ($this->EE->extensions->active_hook('playa_cache_key'))
+ {
+ $cache_key = $this->EE->extensions->call('playa_cache_key', $this, $cache_key);
+ }
+ //
+ // -------------------------------------------
// find the rels if they aren't already cached
if (! isset($this->cache['rels'][$cache_key]))
@@ -456,7 +467,7 @@ class Playa
$where[] = "rel.{$col}_entry_id".($not ? ' NOT' : '').' IN ('.$entry_ids.')';
}
}
-
+
if (isset($where))
{
$sql .= ' WHERE '.implode(' AND ', $where);
@@ -468,7 +479,21 @@ class Playa
}
// get the relationships
- $rels = $this->EE->db->query($sql);
+
+ // -------------------------------------------
+ // 'playa_data_query' hook
+ // - Override the SQL query
+ //
+ if ($this->EE->extensions->active_hook('playa_data_query'))
+ {
+ $rels = $this->EE->extensions->call('playa_data_query', $this, $sql, $where);
+ }
+ else
+ {
+ $rels = $this->EE->db->query($sql);
+ }
+ //
+ // -------------------------------------------
// cache them in case an identical request comes later
$this->cache['rels'][$cache_key] = $rels;
<?php
/* ===========================================================
Matrix Support
============================================================ */
public function matrix_data_query($matrix, $params, $sql)
{
// Modify the query Matrix was about to use and insert our changes
$modified_sql = str_replace('AND entry_id', 'AND uhura_status = "'. $this->EE->uhura->status .'" AND uhura_lang_id = '. $this->EE->uhura->lang_id .' AND entry_id', $sql);
$query = $this->EE->db->query($modified_sql);
// If no rows were found, and fallback is set, then query default language instead.
if($this->settings['display_fallback'] AND $query->num_rows() == 0)
{
$modified_sql = str_replace('AND entry_id', 'AND uhura_status = "'. $this->EE->uhura->status .'" AND uhura_lang_id = '. $this->EE->uhura->default_language .' AND entry_id', $sql);
$query = $this->EE->db->query($modified_sql);
}
// return a query result
return $query;
}
public function matrix_display_field($matrix, $params)
{
$compiled_select = $this->EE->db->_compile_select();
$str_find = array('WHERE', 'ORDER BY');
$str_replace = array('FROM exp_matrix_data WHERE', 'AND uhura_lang_id = '. $this->EE->uhura->lang_id .' AND uhura_status = "'. $this->EE->uhura->status .'" ORDER BY');
$str_replace_fallback = array('FROM exp_matrix_data WHERE', 'AND uhura_lang_id = '. $this->EE->uhura->default_language .' AND uhura_status = "'. $this->EE->uhura->status .'" ORDER BY');
$modified_sql = str_replace($str_find, $str_replace, $compiled_select);
$query = $this->EE->db->query($modified_sql);
// If no rows were found, and fallback is set, then query default language instead.
if($this->settings['display_fallback'] AND $query->num_rows() == 0)
{
$modified_sql = str_replace($str_find, $str_replace_fallback, $compiled_select);
$query = $this->EE->db->query($modified_sql);
}
// Make sure its reset since we aren't doing an explicit ->get()
$this->EE->db->_reset_select();
// return a query result
return $query->result_array();
}
public function matrix_save($matrix, $entry_id, $data)
{
$save_status = $this->EE->input->post('save_status');
$data['uhura_status'] = $save_status;
$data['uhura_lang_id'] = $this->EE->uhura->lang_id;
return $data;
}
/* ===========================================================
Playa Support
============================================================ */
function playa_cache_key($playa, $cache_key)
{
return $cache_key . '|uhura_lang_id:'. $this->EE->uhura->lang_id .'|uhura_status:'. $this->EE->uhura->status;
}
function playa_data_query($playa, $sql, $where)
{
$modified_sql = str_replace('ORDER BY', ' AND uhura_lang_id = '. $this->EE->uhura->lang_id .' AND uhura_status = "'. $this->EE->uhura->status .'" ORDER BY', $sql);
$query = $this->EE->db->query($modified_sql);
// If no rows were found, and fallback is set, then query default language instead.
if($this->settings['display_fallback'] AND $query->num_rows() == 0)
{
$modified_sql = str_replace('ORDER BY', ' AND uhura_lang_id = '. $this->EE->uhura->default_language .' AND uhura_status = "'. $this->EE->uhura->status .'" ORDER BY', $sql);
$query = $this->EE->db->query($modified_sql);
}
// return a query result
return $query;
}
function playa_display_field($playa, $where)
{
// If Persistent Playa is set, which in most cases it will be, always
// go to default language, but change the status.
if ($this->settings['persistent_relationships'])
{
$where['uhura_status'] = $this->EE->uhura->status;
$where['uhura_lang_id'] = $this->EE->uhura->default_language;
return $where;
}
$where['uhura_status'] = $this->EE->uhura->status;
$where['uhura_lang_id'] = $this->EE->uhura->lang_id;
$rels = $this->EE->db->select('child_entry_id')
->where($where)
->order_by('rel_order')
->get('playa_relationships');
if ($rels->num_rows() == 0)
{
$where['uhura_status'] = $this->EE->uhura->status;
$where['uhura_lang_id'] = $this->EE->uhura->default_language;
}
return $where;
}
function playa_save($playa, $selections, $data)
{
$save_status = $this->EE->input->post('save_status');
$data['uhura_status'] = $save_status;
$data['uhura_lang_id'] = $this->EE->uhura->lang_id;
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment