-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0] Plg parentassociations #17881
[4.0] Plg parentassociations #17881
Changes from 1 commit
93316f8
4b84f8a
ee85e1a
8abb641
c0260e2
95ca61c
a9c17f9
4042619
0d76dcb
a74c77c
eec4a61
44412c3
cb73dc6
501ed15
2340d12
78801f5
26ac16b
e6e9114
3c46478
bedfca9
3511d68
9ec58f5
6aba9f7
5b760b4
0424019
38825cc
4eb770a
2168e1e
0c1d977
b21e025
239c66a
ff4e41d
c5f3b63
8bd1af9
f2dd35d
538442b
d3555e8
542522f
e291013
82fe241
57bf3c7
23ba4a4
bc8b651
0a527e8
45798f7
39f1cd2
6ad1f44
e1814dd
fa2d94c
47f444e
a9c6fdf
48a8b27
b7a819a
a0e7ad2
a7a1377
6a55daa
2049c8a
eccae50
9fda340
a64fbf0
d8becf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
/** | ||
* @version $Id: articleassociations.php revision date lasteditedby $ | ||
* @package Joomla | ||
* @subpackage Content | ||
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | ||
* @license GNU/GPL, see LICENSE.php | ||
* @version $Id: articleassociations.php revision date lasteditedby $ | ||
* @package Joomla | ||
* @subpackage Content | ||
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. | ||
* @license GNU/GPL, see LICENSE.php | ||
* Joomla! is free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
|
@@ -13,7 +13,7 @@ | |
*/ | ||
|
||
// no direct access | ||
defined( '_JEXEC' ) or die; | ||
defined('_JEXEC') or die; | ||
|
||
class plgContentarticleassociations extends JPlugin | ||
{ | ||
|
@@ -41,14 +41,19 @@ public function onContentAfterSave($context, $article, $isNew) | |
|
||
// If not parent exists, add it | ||
if ($this->getParentCount($id) !== 1) | ||
{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove trailing whitespace |
||
$query = $this->db->getQuery(true); | ||
$columns = array('id', 'parentid', 'approved'); | ||
$values = array($id, 0, 1); | ||
$query | ||
->insert($this->db->quoteName('#__item_associations')) | ||
->columns($this->db->quoteName($columns)) | ||
->values(implode(',', $values)); | ||
$columns = array( | ||
'id', | ||
'parentid', | ||
'approved' | ||
); | ||
$values = array( | ||
$id, | ||
0, | ||
1 | ||
); | ||
$query->insert($this->db->quoteName('#__item_associations'))->columns($this->db->quoteName($columns))->values(implode(',', $values)); | ||
|
||
$this->db->setQuery($query)->execute(); | ||
} | ||
|
@@ -58,7 +63,7 @@ public function onContentAfterSave($context, $article, $isNew) | |
|
||
public function onContentAfterSaveAssociations($context, $article, $isNew) | ||
{ | ||
$id = $article->id; | ||
$id = $article->id; | ||
// Get a db connection. | ||
// Create a new query object. | ||
$query = $this->db->getQuery(true); | ||
|
@@ -74,30 +79,28 @@ public function onContentAfterSaveAssociations($context, $article, $isNew) | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove empty line |
||
// if slave article is edit | ||
if ((int) $this->getParentId($id) !== 0) | ||
{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove trailing whitespace |
||
$query = $this->db->getQuery(true); | ||
$fields = array( | ||
$this->db->quoteName('approved') . ' =0' | ||
); | ||
|
||
$conditions = array($this->db->quoteName('id') . ' = ' . $this->db->quote($id)); | ||
$conditions = array( | ||
$this->db->quoteName('id') . ' = ' . $this->db->quote($id) | ||
); | ||
$query->update($this->db->quoteName('#__item_associations'))->set($fields)->where($conditions); | ||
$this->db->setQuery($query)->execute(); | ||
} | ||
|
||
// if master article is edit | ||
|
||
$query->clear() | ||
->select(array('#__item_associations.id')) | ||
->from($this->db->quoteName('#__item_associations')) | ||
->join('INNER', $this->db->quoteName('#__associations') . ' ON (' . $this->db->quoteName('#__associations.id') . ' = ' . $this->db->quoteName('#__item_associations.id') . ')') | ||
->where($this->db->quoteName('#__associations.key') . ' =' . $this->db->quote($result),'AND') | ||
->where($this->db->quoteName('#__item_associations.parentid') . ' = 0'); | ||
$query->clear()->select(array('#__item_associations.id')) | ||
->from($this->db->quoteName('#__item_associations'))->join('INNER', $this->db->quoteName('#__associations') . ' ON (' . $this->db->quoteName('#__associations.id') . ' = ' . $this->db->quoteName('#__item_associations.id') . ')')->where($this->db->quoteName('#__associations.key') . ' =' . $this->db->quote($result), 'AND')->where($this->db->quoteName('#__item_associations.parentid') . ' = 0'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put query clauses on separate lines, as Travis will start moaning about line length |
||
$this->db->setQuery($query); | ||
$liste1 = $this->db->loadRowList(); | ||
|
||
if ($result && strcmp($this->getParentId($id), "0") == 0) | ||
{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove trailing whitespace |
||
$db = JFactory::getDbo(); | ||
$query = $this->db->getQuery(true); | ||
$query->select($this->db->quoteName(array('id'))); | ||
|
@@ -106,21 +109,20 @@ public function onContentAfterSaveAssociations($context, $article, $isNew) | |
$this->db->setQuery($query); | ||
$list = $this->db->loadRowList(); | ||
foreach ($list as $res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add new line before |
||
{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove trailing whitespace |
||
foreach ($res as $association_id) | ||
{ | ||
|
||
if ($id != $association_id) | ||
{ | ||
|
||
|
||
$query = $this->db->getQuery(true); | ||
$fields = array( | ||
$this->db->quoteName('approved') . ' =0', | ||
$this->db->quoteName('parentid') . ' =' . $this->db->quote($id) | ||
); | ||
|
||
$conditions = array($this->db->quoteName('id') . ' =' . $this->db->quote($association_id)); | ||
$conditions = array( | ||
$this->db->quoteName('id') . ' =' . $this->db->quote($association_id) | ||
); | ||
$query->update($this->db->quoteName('#__item_associations'))->set($fields)->where($conditions); | ||
$this->db->setQuery($query); | ||
$res = $this->db->execute(); | ||
|
@@ -140,26 +142,20 @@ public function onContentAfterSaveAssociations($context, $article, $isNew) | |
|
||
public function getParentCount($id) | ||
{ | ||
$query = $this->db->getQuery(true) | ||
->select(COUNT($this->db->quoteName(array('parentid')))) | ||
->from($this->db->quoteName('#__item_associations')) | ||
->where($this->db->quoteName('id') . ' = ' . (int) $id); | ||
$query = $this->db->getQuery(true)->select(COUNT($this->db->quoteName(array('parentid')))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put query clauses on separate lines |
||
->from($this->db->quoteName('#__item_associations'))->where($this->db->quoteName('id') . ' = ' . (int) $id); | ||
$this->db->setQuery($query); | ||
$parentid = $this->db->loadResult(); | ||
|
||
return (int) $parentid; | ||
} | ||
|
||
|
||
public function getParentId($id) | ||
{ | ||
$query = $this->db->getQuery(true) | ||
->select($this->db->quoteName(array('parentid'))) | ||
->from($this->db->quoteName('#__item_associations')) | ||
->where($this->db->quoteName('id') . ' = ' . (int) $id); | ||
$query = $this->db->getQuery(true)->select($this->db->quoteName(array('parentid'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put query clauses on separate lines |
||
->from($this->db->quoteName('#__item_associations'))->where($this->db->quoteName('id') . ' = ' . (int) $id); | ||
$this->db->setQuery($query); | ||
$parentid = $this->db->loadResult(); | ||
|
||
return (int) $parentid; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove empty lines |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure these are aligned