36 public $attributes = Array();
45 parent::__construct();
62 $name = strtolower($name);
63 if (!isset($this->attributes[$name])) {
64 $this->attributes[$name] =
'';
66 if ($this->attributes[$name] == $value)
return FALSE;
67 $this->attributes[$name] = $value;
86 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
87 $content_link = Array(
'asset' => &$table,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
88 $content_type =
new $type();
89 $content_type->setAttrValue(
'name',
'Row '.($rowid+1).
' Cell '.($cellid+1));
90 $this->attributes[
'linkid'] = $content_type->create($content_link);
91 if (!$this->attributes[
'linkid'])
return FALSE;
92 $this->attributes[
'content_type'] = $type;
114 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($this->attributes[
'linkid'], $table->id);
115 if (!$content_type = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code'])) {
119 if (!$content_type->setAttrValue(
'name',
'Row '.($new_rowid+1).
' Cell '.($new_cellid+1))) {
123 if (!$content_type->saveAttributes())
return FALSE;
140 if (!$table->deleteLink($this->attributes[
'linkid'])) {
146 $this->attributes = Array();
162 if (empty($this->attributes[
'colspan']))
return 1;
163 return ((
int) $this->attributes[
'colspan'] > 0) ? (int) $this->attributes[
'colspan'] : 1;
176 if (empty($this->attributes[
'rowspan']))
return 1;
177 return ((
int) $this->attributes[
'rowspan'] > 0) ? (int) $this->attributes[
'rowspan'] : 1;
195 if (!isset($this->attributes[
'linkid']))
return;
197 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($this->attributes[
'linkid'], $table->id);
199 $content_type = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
201 $content_type = NULL;
203 $content_prefix = $prefix.
'_content_type_'.$this->attributes[
'content_type'].
'_'.$this->attributes[
'linkid'];
206 foreach ($this->attributes as $name => $val) {
207 if ($val ==
'')
continue;
208 if ($name ==
'linkid')
continue;
209 if ($name ==
'content_type')
continue;
212 if ($name ==
'colspan' && $editing && $table->
writeAccess(
'content')) {
215 if (strtolower($name) ==
'nowrap') {
216 if ($val) echo
' nowrap';
218 echo
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
222 echo
' style="margin: 2px; vertical-align:top;" id="'.$content_prefix.
'_cell"';
226 if (is_null($content_type)) {
227 echo translate(
'content_type_not_found', $link[
'minorid']);
229 $content_edit = $content_type->getEditFns();
230 if (!empty($prefix)) {
231 $content_edit->paintBackend($content_type, $content_prefix);
234 $content_edit->paint($content_type, $editing, $generating);
235 $cell_content = ob_get_contents();
239 $cell_content = preg_replace(
"/^/",
"\t\t\t", $cell_content);
240 $cell_content = preg_replace(
"/\n/",
"\n\t\t\t", $cell_content);
244 echo
"\n\t\t</td>\n";
263 $attribute_list =
'';
266 foreach ($this->attributes as $name => $val) {
267 if ($val ==
'')
continue;
268 if (strtolower($name) ==
'nowrap') {
269 if ($val) $attribute_list .=
' nowrap';
271 if (strtolower($name) ==
'colspan') {
274 $attribute_list .=
' '.$name.
'="'.str_replace(
'"',
'"', $val).
'"';
276 if ($name ==
'dir') $dir_attribute = $val;
281 Bodycopy_Edit_Fns::printBodycopyIcon(
"bodycopy_edit_table_cell_properties('$prefix', $tableid, $rowid, $cellid);",
'Edit Cell '.($cellid + 1).
' - '.($rowid+1).
'\'s Properties
', (($attribute_list) ? 'Current Properties :<br>
'.$attribute_list : ''), 'cell_properties
', '[Edit Cell Properties]
');
283 $link = $GLOBALS['SQ_SYSTEM
']->am->getLinkById($this->attributes['linkid
'], $table->id);
285 $content_type = $GLOBALS['SQ_SYSTEM
']->am->getAsset($link['minorid
'], $link['minor_type_code
']);
287 $content_type = NULL;
290 // set the dir attribute to one inherited from above if there is no specified for cell
291 if (empty($dir_attribute) && isset($this->_tmp['dir_attr
'])) {
292 $dir_attribute = $this->_tmp['dir_attr
'];
295 if (!is_null($content_type)) {
296 $content_edit = $content_type->getEditFns();
297 $content_prefix = $prefix.'_content_type_
'.$this->attributes['content_type
'].'_
'.$this->attributes['linkid
'];
298 if (method_exists($content_edit,'setDirAttr') && !empty($dir_attribute)) {
299 $content_edit->setDirAttr($dir_attribute);
301 $content_edit->paintBackendIcons($content_type, $content_prefix);
321 public function paintCellBackendStatusIcons(Bodycopy_Table $table, $prefix, $tableid, $rowid, $cellid)
323 $link = $GLOBALS['SQ_SYSTEM
']->am->getLinkById($this->attributes['linkid
'], $table->id);
325 $content_type = $GLOBALS['SQ_SYSTEM
']->am->getAsset($link['minorid
'], $link['minor_type_code
']);
327 $content_type = NULL;
330 if (!is_null($content_type)) {
331 $content_edit = $content_type->getEditFns();
332 $content_prefix = $prefix.'_content_type_
'.$this->attributes['content_type
'].'_
'.$this->attributes['linkid
'];
333 $content_edit->paintBackendStatusIcons($content_type, $content_prefix);
338 }//end paintCellBackendStatusIcons()
354 public function processCell(Bodycopy_Table $table, $prefix, $tableid, $rowid, $cellid, Array $bc_saved)
358 // update the contentType
359 $link = $GLOBALS['SQ_SYSTEM
']->am->getLinkById($this->attributes['linkid
'], $table->id);
360 if (empty($link)) return FALSE;
361 $content_type = $GLOBALS['SQ_SYSTEM
']->am->getAsset($link['minorid
'], $link['minor_type_code
']);
362 $content_edit = $content_type->getEditFns();
363 $content_prefix = $prefix.'_content_type_
'.$this->attributes['content_type
'].'_
'.$this->attributes['linkid
'];
364 if ($content_edit->processBackend(Array(), $content_type, $content_prefix)) {
367 if (!$content_type->saveAttributes()) return FALSE;
369 if (isset($bc_saved[$prefix][$tableid]['rows
'][$rowid]['cells
'][$cellid]['attributes
'])) {
370 foreach ($bc_saved[$prefix][$tableid]['rows
'][$rowid]['cells
'][$cellid]['attributes
'] as $name => $value) {
371 if ($name == 'type
') {
372 // changing the content type of this cell
373 if ($this->_updateCellType($table, $value)) {
378 if ($this->setAttribute($name, $value)) {
397 protected function _updateCellType(Bodycopy_Table $table, $new_type='')
400 // dont change anything if the new type id blank
401 $new_type = trim($new_type);
402 if (empty($new_type)) return FALSE;
404 // get the contentType
405 $link = $GLOBALS['SQ_SYSTEM
']->am->getLinkById($this->attributes['linkid
'], $table->id);
406 if (empty($link)) return FALSE;
407 $content_type = $GLOBALS['SQ_SYSTEM
']->am->getAsset($link['minorid
'], $link['minor_type_code
']);
409 // if the new type is the same as the current, change nothing
410 $current_type = get_class_lower($content_type);
411 if ($current_type == $new_type) return FALSE;
413 // morph the content type to the new type
415 $morphed = $content_type->morph('content_type
');
416 if (!$morphed) return FALSE;
419 $content_type = $morphed->morph($new_type);
420 if (!$content_type) return FALSE;
422 $this->setAttribute('content_type
', $new_type);
426 }//end _updateCellType()
437 public function printBackendJsData($cellid)
441 case <?php echo $cellid?> :
442 retVal["attributes"] = '<?php echo var_serialise($this->attributes, TRUE)?>
';
446 }//end printBackendJsData()
457 public function setDirAttr($dir_attribute)
459 $this->_tmp['dir_attr
'] = $dir_attribute;