/** * Copies this record (no checks) (tab and its fields) * * @param null|TableInterface|self $object The object being copied otherwise create new object and add $this * @return self|boolean OBJECT: The new object copied successfully, FALSE: Failed to copy */ public function copy($object = null) { if ($object === null) { $object = clone $this; } // TODO: This algorithm below to determine the new name could be factored out as reusable: // Grab index of tab from tabs with same title $query = 'SELECT ' . $this->_db->NameQuote('title') . "\n FROM " . $this->_db->NameQuote($this->_tbl) . "\n WHERE " . $this->_db->NameQuote('title') . " REGEXP " . $this->_db->Quote('^' . preg_quote($object->title) . '( \\([0-9]+\\))?$'); $this->_db->setQuery($query); $titles = $this->_db->loadResultArray(); $count = count($titles); // Only increment if there's something to increment as the title could be changed before copy is called, which would be a 0 count: if ($count) { // Increment index by 1 based off similar tab title count: $index = $count + 1; // Loop through and make sure the index is unique; if not keep incrementing until it is: do { $changed = false; foreach ($titles as $v) { if ($v == $object->title . ' (' . $index . ')') { $index++; $changed = true; } } } while ($changed); $object->title = $object->title . ' (' . $index . ')'; } // We need to complete the copy before copying the field as we need the new tabid: $copied = parent::copy($object); if ($copied) { // Grab the tabs fields and loop through copying them with the new tab: $query = 'SELECT *' . "\n FROM " . $this->_db->NameQuote('#__comprofiler_fields') . "\n WHERE " . $this->_db->NameQuote('tabid') . " = " . (int) $this->tabid; $this->_db->setQuery($query); $fields = $this->_db->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable'); foreach ($fields as $field) { /** @var FieldTable $field */ if ($field->canCopy()) { $field->tabid = (int) $object->tabid; $field->copy(); } } } return $copied; }
/** * Copies this record (no checks) (field and its fieldvalues) * * @param null|TableInterface|self $object The object being copied otherwise create new object and add $this * @return self|boolean OBJECT: The new object copied successfully, FALSE: Failed to copy */ public function copy( $object = null ) { if ( $object === null ) { $object = clone $this; } //TODO: This algorithm below to determine the new name could be factored out as reusable: // Grab index of field from fields with same name $query = 'SELECT ' . $this->_db->NameQuote( 'name' ) . "\n FROM " . $this->_db->NameQuote( $this->_tbl ) . "\n WHERE " . $this->_db->NameQuote( 'name' ) . " REGEXP " . $this->_db->Quote( '^' . preg_quote( $object->name ) . '[0-9]*$' ) . "\n ORDER BY " . $this->_db->NameQuote( 'name' ); $this->_db->setQuery( $query ); $names = $this->_db->loadResultArray(); $count = count( $names ); // Only increment if there's something to increment as the name could be changed before copy is called, which would be a 0 count: if ( $count ) { // Increment index by 1 based off similar field name count: $index = ( $count + 1 ); // Loop through and make sure the index is unique; if not keep incrementing until it is: do { $changed = false; foreach ( $names as $v ) { if ( $v == ( $object->name . $index ) ) { $index++; $changed = true; } } } while ( $changed ); $object->name = $object->name . $index; $object->title = $object->title . ' (' . $index . ')'; } // Grab existing field values so they can be pushed to the copied field: $fieldValuesTable = new FieldValueTable( $this->_db ); $k = $this->_tbl_key; $object->_fieldvalues = $fieldValuesTable->getFieldValuesOfField( $object->$k ); return parent::copy( $object ); }
/** * Copies this record (no checks) (tab and its fields) * * @param null|TableInterface|self $object The object being copied otherwise create new object and add $this * @return self|boolean OBJECT: The new object copied successfully, FALSE: Failed to copy */ public function copy($object = null) { if ($object === null) { $object = clone $this; } // TODO: This algorithm below to determine the new name could be factored out as reusable: // Grab index of list from lists with same title $query = 'SELECT ' . $this->_db->NameQuote('title') . "\n FROM " . $this->_db->NameQuote($this->_tbl) . "\n WHERE " . $this->_db->NameQuote('title') . " REGEXP " . $this->_db->Quote('^' . preg_quote($object->title) . '[0-9]*$') . "\n ORDER BY " . $this->_db->NameQuote('title'); $this->_db->setQuery($query); $titles = $this->_db->loadResultArray(); $count = count($titles); // Only increment if there's something to increment as the title could be changed before copy is called, which would be a 0 count: if ($count) { // Increment index by 1 based off similar list title count: $index = $count + 1; // Loop through and make sure the index is unique; if not keep incrementing until it is: do { $changed = false; foreach ($titles as $v) { if ($v == $object->title . $index) { $index++; $changed = true; } } } while ($changed); $object->title = $object->title . ' (' . $index . ')'; } return parent::copy($object); }
/** * @param null|self $object * @return self|bool */ public function copy( $object = null ) { global $_CB_framework, $_PLUGINS; if ( $object === null ) { $object = clone $this; } $old = new self(); $old->load( (int) $object->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeCopyCategory', array( &$object, $old ) ); $copy = parent::copy( $object ); if ( ! $copy ) { return false; } // Copy the groups in this category: $query = 'SELECT *' . "\n FROM " . $this->getDbo()->NameQuote( '#__groupjive_groups' ) . "\n WHERE " . $this->getDbo()->NameQuote( 'category' ) . " = " . (int) $old->get( 'id' ); $this->getDbo()->setQuery( $query ); $groups = $this->getDbo()->loadObjectList( null, '\CB\Plugin\GroupJive\Table\GroupTable', array( $this->getDbo() ) ); /** @var GroupTable[] $groups */ foreach ( $groups as $group ) { $group->set( 'category', (int) $object->get( 'id' ) ); $group->copy(); } // Copy the canvas and logo: if ( $object->get( 'canvas' ) || $object->get( 'logo' ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; $oldPath = $basePath . '/' . (int) $old->get( 'id' ); $newPath = $basePath . '/' . (int) $object->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $object->get( 'id' ) ); CBGroupJive::copyDirectory( $oldPath, $newPath ); } } $_PLUGINS->trigger( 'gj_onAfterCopyCategory', array( $object, $old ) ); return $copy; }
/** * Copies this record (no checks) * canCopy should be called first to check if a copy is possible. * * @param null|TableInterface|self $object The object being copied otherwise create new object and add $this * @return self|boolean OBJECT: The new object copied successfully, FALSE: Failed to copy */ public function copy( $object = null ) { if ( $object === null ) { $object = clone $this; } if ( $object->get( 'system' ) ) { $object->set( 'system', 0 ); } return parent::copy( $object ); }
/** * @param null|self $object * @return self|bool */ public function copy( $object = null ) { global $_CB_framework, $_PLUGINS; if ( $object === null ) { $object = clone $this; } $old = new self(); $old->load( (int) $object->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeCopyGroup', array( &$object, $old ) ); $copy = parent::copy( $object ); if ( ! $copy ) { return false; } // Copy the canvas and logo: if ( $object->get( 'canvas' ) || $object->get( 'logo' ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; $oldPath = $basePath . '/' . (int) $old->get( 'category' ) . '/' . (int) $old->get( 'id' ); $newPath = $basePath . '/' . (int) $object->get( 'category' ) . '/' . (int) $object->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $object->get( 'category' ), $object->get( 'id' ) ); CBGroupJive::copyDirectory( $oldPath, $newPath ); } } $_PLUGINS->trigger( 'gj_onAfterCopyGroup', array( $object, $old ) ); return $copy; }