18 require_once SQ_CORE_PACKAGE_PATH.
'/designs/design/design.inc';
43 parent::__construct($assetid);
57 $links = parent::_getAllowedLinks();
58 $links[SQ_LINK_TYPE_1][
'file'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
59 $links[SQ_LINK_TYPE_2][
'file'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
60 $links[SQ_LINK_TYPE_3][
'file'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
86 public function prepareLink(
Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
88 if ($side_of_link ==
'minor' && $asset instanceof
Design) {
89 $value =
'customisation';
109 $delete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
110 if (empty($delete_link)) {
111 trigger_localised_error(
'CORE0155', E_USER_WARNING, $linkid);
115 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
116 $minor = $am->getAsset($delete_link[
'minorid'], $delete_link[
'minor_type_code']);
118 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
119 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
122 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
123 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
128 if ($delete_link[
'link_type'] == SQ_LINK_TYPE_2 && ($minor instanceof
File)) {
136 $file_link_ids = Array();
137 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($design->id, SQ_LINK_TYPE_2,
'file', FALSE);
138 foreach ($file_links as $link) {
139 $file_link_ids[$link[
'minorid']] = $link[
'linkid'];
141 $file_link_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($file_link_ids));
143 foreach ($file_link_info as $assetid => $info) {
144 if ($info[
'name'] == $minor->name) {
146 $new_minor = $am->getAsset($assetid);
147 if (!$this->
createLink($new_minor, SQ_LINK_TYPE_3,
'', NULL,
'1')) {
148 trigger_localised_error(
'CORE0162', E_USER_WARNING);
149 $am->forgetAsset($design);
150 $am->forgetAsset($new_minor);
151 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
152 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
155 $am->forgetAsset($new_minor);
159 $am->forgetAsset($design);
165 if ($delete_link[
'link_type'] == SQ_LINK_TYPE_2 && ($minor instanceof
Design_Css)) {
171 $css_link_ids = Array();
172 $css_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($design->id, SQ_LINK_TYPE_2,
'design_css', FALSE);
173 foreach ($css_links as $link) {
174 $css_link_ids[$link[
'minorid']] = $link[
'linkid'];
176 $css_link_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($css_link_ids));
178 foreach ($css_link_info as $info) {
179 if ($info[
'name'] == $minor->name) {
181 $new_minor = $am->getAsset($info[
'assetid']);
182 if (!$this->
createLink($new_minor, SQ_LINK_TYPE_3,
'', NULL,
'1')) {
183 trigger_localised_error(
'CORE0161', E_USER_WARNING);
184 $am->forgetAsset($design);
185 $am->forgetAsset($new_minor);
186 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
187 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
190 $am->forgetAsset($new_minor);
194 $am->forgetAsset($design);
197 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
198 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
219 $delete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
220 if (empty($delete_link)) {
221 trigger_localised_error(
'CORE0155', E_USER_WARNING, $linkid);
225 $am = $GLOBALS[
'SQ_SYSTEM']->am;
226 $minor = $am->getAsset($delete_link[
'minorid'], $delete_link[
'minor_type_code']);
228 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
229 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
231 if (!parent::deleteLink($linkid)) {
232 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
233 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
237 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
238 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
255 parent::linksUpdated();
256 unset($this->_tmp[
'parent_design']);
257 unset($this->_tmp[
'customised_areas']);
258 unset($this->_tmp[
'uncustomised_areas']);
271 if (empty($this->_tmp[
'parent_design'])) {
272 $parent_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'design', FALSE,
'customisation',
'minor');
277 $this->_tmp[
'parent_design'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_link[
'majorid'], $parent_link[
'major_type_code']);
280 return $this->_tmp[
'parent_design'];
293 if (!isset($this->_tmp[
'customised_areas'])) {
295 if (!is_null($parent)) {
298 $parents_links = $parent->getDesignAreaLink();
299 $this->_tmp[
'customised_areas'] = Array();
303 foreach ($our_links as $our_link) {
304 foreach ($parents_links as $parents_link) {
306 if ($our_link[
'value'] == $parents_link[
'value']) {
308 if ($parents_link[
'minorid'] == $our_link[
'minorid']) {
309 $this->_tmp[
'uncustomised_areas'][] = $our_link;
311 $this->_tmp[
'customised_areas'][] = $our_link;
320 if (!isset($this->_tmp[
'customised_areas'])) {
321 $this->_tmp[
'customised_areas'] = Array();
323 if (!isset($this->_tmp[
'uncustomised_areas'])) {
324 $this->_tmp[
'uncustomised_areas'] = Array();
327 return $this->_tmp[
'customised_areas'];
340 if (!isset($this->_tmp[
'uncustomised_areas'])) {
344 return $this->_tmp[
'uncustomised_areas'];
362 $am = $GLOBALS[
'SQ_SYSTEM']->am;
372 $parent_da_links = Array();
373 foreach ($tmp as $link) {
374 $parent_da_links[$link[
'value']] = $link;
378 $this_da_links = Array();
379 foreach ($tmp as $link) {
380 $this_da_links[$link[
'value']] = $link;
383 $remove_id_names = array_diff(array_keys($this_da_links), array_keys($parent_da_links));
384 $added_id_names = array_diff(array_keys($parent_da_links), array_keys($this_da_links));
387 foreach ($remove_id_names as $id_name) {
388 if (!$this->
deleteLink($this_da_links[$id_name][
'linkid'])) {
393 foreach ($added_id_names as $id_name) {
394 $da = $am->getAsset($parent_da_links[$id_name][
'minorid'], $parent_da_links[$id_name][
'minor_type_code'], TRUE);
395 if (is_null($da))
continue;
396 $this->
createLink($da, SQ_LINK_TYPE_3, $id_name, NULL,
'1');
402 foreach ($links as $link) {
403 $da = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
404 if (is_null($da))
continue;
407 if (is_null($parent_da))
continue;
408 foreach ($parent_da->vars as $name => $details) {
409 if (FALSE !== strpos($name,
'contents')) {
410 $da->setAttrValue($name, $parent_da->attr($name));
416 if (isset($da->vars[
'declared_vars'])) {
417 $da->mergeParentDeclaredVars($parent_da->attr(
'declared_vars'));
420 $da->saveAttributes();
446 public function paint(
Asset $ASSET, Array $FILE_URLS=Array(), Array $CSS_URLS=Array())
450 $file_link_ids = Array();
451 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'file', FALSE);
452 foreach ($file_links as $link) {
453 $file_link_ids[] = $link[
'minorid'];
455 $file_link_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_unique($file_link_ids));
456 $file_link_urls = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($file_link_ids));
458 foreach ($file_link_info as $minorid => $file_info) {
459 $file_url = $file_link_urls[$minorid];
460 if ($file_url ==
'') {
461 $file_url =
"Javascript: alert(js_translate('no_url_found', '".addslashes($file_info[
'name']).
"', '".addslashes($this->
attr(
'id_name')).
"'));";
462 }
else if ($this->
attr(
'static_url_versioning')){
463 $served_by_apache = strpos($file_url,
'/__data/') !== FALSE || (SQ_CONF_STATIC_ROOT_URL && strpos($file_url, SQ_CONF_STATIC_ROOT_URL.
'/') !== FALSE);
464 if ($served_by_apache) $file_url .=
'?v='.$file_info[
'version'];
466 $FILE_URLS[$file_info[
'name']] = $file_url;
470 $css_link_ids = Array();
471 $css_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'design_css', FALSE);
472 foreach ($css_links as $link) {
473 $css_link_ids[] = $link[
'minorid'];
476 $css_link_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_unique($css_link_ids));
477 $css_link_urls = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($css_link_ids));
479 foreach ($css_link_info as $minorid => $css_info) {
480 $css_url = $css_link_urls[$minorid];
481 if ($css_url ==
'') {
482 $css_url =
"Javascript: alert(js_translate('no_url_found', '".addslashes($file_info[
'name']).
"', '".addslashes($this->
attr(
'id_name')).
"'));";
483 }
else if ($this->
attr(
'static_url_versioning')){
484 $served_by_apache = strpos($css_url,
'/__data/') !== FALSE || (SQ_CONF_STATIC_ROOT_URL && strpos($css_url, SQ_CONF_STATIC_ROOT_URL.
'/') !== FALSE);
485 if ($served_by_apache) $css_url .=
'?v='.$css_info[
'version'];
487 $CSS_URLS[$css_info[
'name']] = $css_url;
490 return parent::paint($ASSET, $FILE_URLS, $CSS_URLS);