17 require_once SQ_CORE_PACKAGE_PATH.
'/bodycopy/bodycopy_container/bodycopy_container.inc';
18 require_once(dirname(__FILE__).
'/bodycopy_table_cell.inc');
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
62 $bc_data = $this->_tmp[
'bodycopy_create_data'];
63 unset($this->_tmp[
'bodycopy_create_data']);
65 if (!parent::_createAdditional($link))
return FALSE;
67 $num_rows = $bc_data[
'num_rows'];
68 $num_cols = $bc_data[
'num_cols'];
70 for ($i = 0; $i < $num_rows; $i++) {
72 $rows[$i][
'attributes'] = Array();
73 $rows[$i][
'cells'] = Array();
74 for ($x = 0; $x < $num_cols; $x++) {
75 $rows[$i][
'cells'][$x] =
new Bodycopy_Table_Cell();
77 $content_type = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'bodycopy_container',
'SQ_DEFAULT_CONTENT_TYPE');
78 if (!$rows[$i][
'cells'][$x]->setContentType($this, $content_type, $i, $x)) {
86 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id,
'attributes') || !$this->
saveAttributes()) {
103 if (SQ_IN_BACKEND || SQ_IN_LIMBO || !isset($this->_tmp[
'content_type'])) {
104 unset($this->_tmp[
'content_type']);
105 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'content_type', FALSE,
'major',
'', TRUE, TRUE);
106 if (is_array($link) && !empty($link)) {
107 foreach ($link as $id => $type_link) {
108 $this->_tmp[
'content_type'][$id] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($type_link[
'minorid'], $type_link[
'minor_type_code']);
109 if (is_null($this->_tmp[
'content_type'][$id])) {
110 echo translate(
'content_type_not_found', $type_link[
'minorid']);
115 $this->_tmp[
'content_type'] = $null;
118 return $this->_tmp[
'content_type'];
141 if ($name ==
'rows') {
142 parent::setAttrValue(
'rows', Array());
144 return parent::setAttrValue($name, $value);
159 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
160 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
161 if (!parent::remapAssetids($map)) {
162 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
163 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
167 $old_assetid = array_search($this->
id, $map);
170 if (isset($map[$this->
id])) {
171 $child_links = $GLOBALS[
'SQ_SYSTEM']->am->getAllChildLinks($this->
id, SQ_LINK_TYPE_2);
172 $new_clone = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($map[$this->
id]);
173 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($new_clone->id,
'attributes');
175 if (!$new_clone->remapTableLinks($map, $child_links)) {
176 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
177 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
181 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($new_clone->id,
'attributes');
182 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($new_clone);
185 if ($old_assetid === FALSE) {
186 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
187 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
191 $old_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($old_assetid, $this->
type());
192 $our_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_SIGNIFICANT,
'content_type', FALSE);
194 if (is_null($old_asset) || empty($our_links)) {
195 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
196 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
199 $rows = $this->
attr(
'rows');
201 for ($i = 0; $i < count($rows); $i++) {
203 for ($j = 0; $j < count($rows[$i][
'cells']); $j++) {
204 $old_linkid = $rows[$i][
'cells'][$j]->attributes[
'linkid'];
205 $old_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($old_linkid, $old_asset->id);
206 if (empty($old_link))
continue;
208 if (isset($map[$old_link[
'minorid']])) {
209 $new_assetid = $map[$old_link[
'minorid']];
211 foreach ($our_links as $our_link) {
212 if ($our_link[
'minorid'] == $new_assetid) {
213 $rows[$i][
'cells'][$j]->attributes[
'linkid'] = $our_link[
'linkid'];
223 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
224 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
227 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
228 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
246 $table_map = $this->
attr(
'rows');
247 $child_map = Array();
249 foreach ($child_links as $linkval) {
250 $child_map[$linkval[
'linkid']] = $linkval[
'assetid'];
254 foreach ($table_map as $rowid => $row) {
255 foreach ($row[
'cells'] as $cellid => $cell) {
256 if (in_array($cell->attributes[
'linkid'], array_keys($child_map))) {
258 $new_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($this->
id, $map[$child_map[$cell->attributes[
'linkid']]]);
259 $table_map[$rowid][
'cells'][$cellid]->attributes[
'linkid'] = $new_link[
'linkid'];