| Previous CloneSet | Next CloneSet | Back to Main Report |
| Clone Mass | Clones in CloneSet | Parameter Count | Clone Similarity | Syntax Category [Sequence Length] |
|---|---|---|---|---|
| 137 | 2 | 0 | 1.000 | class_member |
| Clone Abstraction | Parameter Bindings |
| Clone Instance (Click to see clone) | Line Count | Source Line | Source File |
|---|---|---|---|
| 1 | 137 | 643 | administrator/components/com_content/models/article.php |
| 2 | 137 | 710 | administrator/components/com_menus/models/item.php |
| ||||
/**
* Batch copy menu items to a new menu or parent.
*
* @param int The new menu or sub-item.
* @param array An array of row IDs.
*
* @return booelan True if successful, false otherwise and internal error is set.
*/
protected
function _batchCopy($value, $pks) {
// $value comes as {menutype}.{parent_id}
$parts= explode('.', $value);
$menuType= $parts[0];
$parentId= (int) JArrayHelper::getValue($parts, 1, 0);
$table= &$this->getTable();
$db= &$this->getDbo();
// Check that the parent exists
if ($parentId)
{
if (!$table->load($parentId))
{
if ($error= $table->getError())
{
// Fatal error
$this->setError($error);
return FALSE;
}
else
{
// Non-fatal error
$this->setError(JText::_('Menus_Batch_Move_parent_not_found'));
$parentId= 0;
}
}
}
// If the parent is 0, set it to the ID of the root item in the tree
if (empty($parentId))
{
if (!$parentId= $table->getRootId()) {
$this->setError($this->_db->getErrorMsg());
return FALSE;
}
}
// We need to log the parent ID
$parents= array();
// Calculate the emergency stop count as a precaution against a runaway loop bug
$db->setQuery(
'SELECT COUNT(id)'
. ' FROM #__menu');
$count= $db->loadResult();
if ($error= $db->getErrorMsg())
{
$this->setError($error);
return FALSE;
}
// Parent exists so we let's proceed
while (!empty($pks)
&& $count> 0) {
// Pop the first id off the stack
$pk= array_shift($pks);
$table->reset();
// Check that the row actually exists
if (!$table->load($pk))
{
if ($error= $table->getError())
{
// Fatal error
$this->setError($error);
return FALSE;
}
else
{
// Not fatal error
$this->setError(JText::sprintf('Menus_Batch_Move_row_not_found', $pk));
continue;
}
}
// Copy is a bit tricky, because we also need to copy the children
$db->setQuery(
'SELECT id'
. ' FROM #__menu'
. ' WHERE lft > '
. (int) $table->lft
. ' AND rgt < '
. (int) $table->rgt);
$childIds= $db->loadResultArray();
// Add child ID's to the array only if they aren't already there.
foreach ($childIds as $childId)
{
if (!in_array($childId, $pks)) {
array_push($pks, $childId);
}
}
// Make a copy of the old ID and Parent ID
$oldId= $table->id;
$oldParentId= $table->parent_id;
// Reset the id because we are making a copy.
$table->id = 0;
// If we a copying children, the Old ID will turn up in the parents list
// otherwise it's a new top level item
$table->parent_id = isset ($parents[$oldParentId])
? $parents[$oldParentId]
: $parentId;
$table->menutype = $menuType;
// TODO: Deal with ordering?
//$table->ordering = 1;
$table->level = NULL;
$table->lft = NULL;
$table->rgt = NULL;
// Store the row.
if (!$table->store()) {
$this->setError($table->getError());
return FALSE;
}
// Now we log the old 'parent' to the new 'parent'
$parents[$oldId]= $table->id;
$count --;
}
// Rebuild the hierarchy.
if (!$table->rebuildTree()) {
$this->setError($table->getError());
return FALSE;
}
// Rebuild the tree path.
if (!$table->rebuildPath($table->id)) {
$this->setError($table->getError());
return FALSE;
}
return TRUE;
}
|
| ||||
/**
* Batch copy menu items to a new menu or parent.
*
* @param int The new menu or sub-item.
* @param array An array of row IDs.
*
* @return booelan True if successful, false otherwise and internal error is set.
*/
protected
function _batchCopy($value, $pks) {
// $value comes as {menutype}.{parent_id}
$parts= explode('.', $value);
$menuType= $parts[0];
$parentId= (int) JArrayHelper::getValue($parts, 1, 0);
$table= &$this->getTable();
$db= &$this->getDbo();
// Check that the parent exists
if ($parentId)
{
if (!$table->load($parentId))
{
if ($error= $table->getError())
{
// Fatal error
$this->setError($error);
return FALSE;
}
else
{
// Non-fatal error
$this->setError(JText::_('Menus_Batch_Move_parent_not_found'));
$parentId= 0;
}
}
}
// If the parent is 0, set it to the ID of the root item in the tree
if (empty($parentId))
{
if (!$parentId= $table->getRootId()) {
$this->setError($this->_db->getErrorMsg());
return FALSE;
}
}
// We need to log the parent ID
$parents= array();
// Calculate the emergency stop count as a precaution against a runaway loop bug
$db->setQuery(
'SELECT COUNT(id)'
. ' FROM #__menu');
$count= $db->loadResult();
if ($error= $db->getErrorMsg())
{
$this->setError($error);
return FALSE;
}
// Parent exists so we let's proceed
while (!empty($pks)
&& $count> 0) {
// Pop the first id off the stack
$pk= array_shift($pks);
$table->reset();
// Check that the row actually exists
if (!$table->load($pk))
{
if ($error= $table->getError())
{
// Fatal error
$this->setError($error);
return FALSE;
}
else
{
// Not fatal error
$this->setError(JText::sprintf('Menus_Batch_Move_row_not_found', $pk));
continue;
}
}
// Copy is a bit tricky, because we also need to copy the children
$db->setQuery(
'SELECT id'
. ' FROM #__menu'
. ' WHERE lft > '
. (int) $table->lft
. ' AND rgt < '
. (int) $table->rgt);
$childIds= $db->loadResultArray();
// Add child ID's to the array only if they aren't already there.
foreach ($childIds as $childId)
{
if (!in_array($childId, $pks)) {
array_push($pks, $childId);
}
}
// Make a copy of the old ID and Parent ID
$oldId= $table->id;
$oldParentId= $table->parent_id;
// Reset the id because we are making a copy.
$table->id = 0;
// If we a copying children, the Old ID will turn up in the parents list
// otherwise it's a new top level item
$table->parent_id = isset ($parents[$oldParentId])
? $parents[$oldParentId]
: $parentId;
$table->menutype = $menuType;
// TODO: Deal with ordering?
//$table->ordering = 1;
$table->level = NULL;
$table->lft = NULL;
$table->rgt = NULL;
// Store the row.
if (!$table->store()) {
$this->setError($table->getError());
return FALSE;
}
// Now we log the old 'parent' to the new 'parent'
$parents[$oldId]= $table->id;
$count --;
}
// Rebuild the hierarchy.
if (!$table->rebuildTree()) {
$this->setError($table->getError());
return FALSE;
}
// Rebuild the tree path.
if (!$table->rebuildPath($table->id)) {
$this->setError($table->getError());
return FALSE;
}
return TRUE;
}
|
| |||
/**
* Batch copy menu items to a new menu or parent.
*
* @param int The new menu or sub-item.
* @param array An array of row IDs.
*
* @return booelan True if successful, false otherwise and internal error is set.
*/
protected
function _batchCopy($value,$pks) {
// $value comes as {menutype}.{parent_id}
$parts=explode('.',$value);
$menuType=$parts[0];
$parentId= (int) JArrayHelper::getValue($parts,1,0);
$table= &$this->getTable();
$db= &$this->getDbo();
// Check that the parent exists
if ($parentId) {
if (!$table->load($parentId)) {
if ($error=$table->getError()) {
// Fatal error
$this->setError($error);
return FALSE;
}
else {
// Non-fatal error
$this->setError(JText::_('Menus_Batch_Move_parent_not_found'));
$parentId=0;
}
}
}
// If the parent is 0, set it to the ID of the root item in the tree
if (empty($parentId)) {
if (!$parentId=$table->getRootId()) {
$this->setError($this->_db->getErrorMsg());
return FALSE;
}
}
// We need to log the parent ID
$parents=array();
// Calculate the emergency stop count as a precaution against a runaway loop bug
$db->setQuery('SELECT COUNT(id)'
. ' FROM #__menu');
$count=$db->loadResult();
if ($error=$db->getErrorMsg()) {
$this->setError($error);
return FALSE;
}
// Parent exists so we let's proceed
while (!empty($pks)
&& $count>0) {
// Pop the first id off the stack
$pk=array_shift($pks);
$table->reset();
// Check that the row actually exists
if (!$table->load($pk)) {
if ($error=$table->getError()) {
// Fatal error
$this->setError($error);
return FALSE;
}
else {
// Not fatal error
$this->setError(JText::sprintf('Menus_Batch_Move_row_not_found',$pk));
continue;
}
}
// Copy is a bit tricky, because we also need to copy the children
$db->setQuery('SELECT id'
. ' FROM #__menu'
. ' WHERE lft > '
. (int) $table->lft
. ' AND rgt < '
. (int) $table->rgt);
$childIds=$db->loadResultArray();
// Add child ID's to the array only if they aren't already there.
foreach ($childIds as $childId) {
if (!in_array($childId,$pks)) {
array_push($pks,$childId);
}
}
// Make a copy of the old ID and Parent ID
$oldId=$table->id;
$oldParentId=$table->parent_id;
// Reset the id because we are making a copy.
$table->id =0;
// If we a copying children, the Old ID will turn up in the parents list
// otherwise it's a new top level item
$table->parent_id = isset ($parents[$oldParentId])
? $parents[$oldParentId]
: $parentId;
$table->menutype =$menuType;
// TODO: Deal with ordering?
//$table->ordering = 1;
$table->level =NULL;
$table->lft =NULL;
$table->rgt =NULL;
// Store the row.
if (!$table->store()) {
$this->setError($table->getError());
return FALSE;
}
// Now we log the old 'parent' to the new 'parent'
$parents[$oldId]=$table->id;
$count --;
}
// Rebuild the hierarchy.
if (!$table->rebuildTree()) {
$this->setError($table->getError());
return FALSE;
}
// Rebuild the tree path.
if (!$table->rebuildPath($table->id)) {
$this->setError($table->getError());
return FALSE;
}
return TRUE;
}
|
| CloneAbstraction |
| Parameter Index | Clone Instance | Parameter Name | Value |
|---|---|---|---|
| None | |||