17 require_once SQ_INCLUDE_PATH.
'/asset.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
61 if (!parent::_createAdditional($link))
return FALSE;
64 $initial_path = strtolower($this->
attr(
'name'));
65 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
66 $valid_paths = make_valid_web_paths(Array($initial_path));
67 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $this->
id, TRUE);
83 protected function _getName($short_name=FALSE, $contextid=NULL)
86 if ($contextid === NULL) {
87 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
91 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
92 if (empty($values) === TRUE) {
93 return parent::_getName($short_name, $contextid);
95 return $values[$this->id];
153 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
154 $result = $cm->loadFromCache($this->
id, $this->
type(), $cache_key, FALSE);
158 if ($result === FALSE)
return FALSE;
160 $result = unserialize($result);
194 if (!empty($cache_key)) {
198 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
199 $r = $cm->saveToCache($this->
id, $this->
type(), $cache_key, serialize($result), FALSE);
224 public function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
242 public function setPermission($assetid, $data_source_record_setid, $permission, $granted)
280 public function getAssetInfo(Array $assetids, $type_code=Array(), $strict_type_code=TRUE, $field=
'')
283 foreach ($assetids as $assetid) {
284 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
285 $keywords = $asset->getAvailableKeywords();
287 if (!empty($field)) {
288 if ($field ===
'type_code') {
289 $info[$assetid] = $asset->type();
290 }
else if (isset($asset->{$field})) {
291 $info[$assetid] = $asset->{$field};
293 trigger_error(
'Invalid sort field for the asset type Data Source Record Set', E_USER_ERROR);
296 $info[$assetid] = Array(
297 'type_code' =>
'data_source_record_set',
298 'version' => $asset->version,
299 'name' => $asset->name,
300 'short_name' => $asset->short_name,
301 'status' => $asset->status,
304 'force_secure' =>
'0',
305 'created' => $asset->getKeywordReplacement(
'asset_created'),
306 'created_userid' => $asset->created_userid,
307 'updated' => $asset->getKeywordReplacement(
'asset_updated'),
308 'updated_userid' => $asset->updated_userid,
309 'published' => $asset->getKeywordReplacement(
'asset_published'),
310 'published_userid' => $asset->published_userid,
311 'status_changed' => $asset->getKeywordReplacement(
'asset_status_changed'),
312 'status_changed_userid' => $asset->status_changed_userid,
332 public function assetExists($assetids)
360 public function getLink($assetid, $link_type=NULL, $type_code=
'', $strict_type_code=TRUE, $value=NULL, $side_of_link=
'major', $exclusive=NULL)
378 public function getLinkById($linkid, $assetid=0, $side_of_link=
'major')
406 public function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)
433 public function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link=
'major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
449 public function getAllChildLinks($assetid, $link_type=0)
463 function getBinaryDataAttributes()
484 public function updateLink($linkid, $link_type=NULL, $value=NULL, $sort_order=NULL)
500 public function deleteAssetLink($linkid, $moving=FALSE)
523 public function createAssetLink(
Asset $major,
Asset $minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE)
551 public function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL)
553 if (!($link_types & SQ_LINK_TYPE_1)) {
557 if (!is_array($type_code)) {
558 if (empty($type_code)) {
559 $type_code = Array();
561 $type_code = Array($type_code);
564 $type_code_key = implode(
'-', $type_code);
567 if ($side_of_link ==
'major') {
568 if ($assetid == $this->
id) {
569 $result = $this->filterResultSet($this->getResultSet());
570 if (empty($result)) {
575 foreach ($result as $record) {
578 'majorid' => $this->
id,
579 'minorid' => $this->
id.
':'.$identity,
580 'minor_type_code' =>
'data_source_record_set',
582 'link_type' => SQ_LINK_TYPE_1,
583 'is_dependant' => FALSE,
584 'is_exclusive' => FALSE,
585 'sort_order' => $index,
622 public function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
628 if ($assetid == $this->
id) {
629 $links = $this->getLinks($this->
id, SQ_LINK_TYPE_1,
'data_source_record_set', TRUE,
'major', NULL);
631 if (!empty($links)) {
632 foreach ($links as $link) {
633 $children[$link[
'minorid']][0][
'type_code'] = $link[
'minor_type_code'];
656 public function getAsset($assetid, $type_code=
'', $mute_errors=FALSE, $return_null=FALSE)
658 $shadowid = explode(
':', $assetid);
659 $shadowid = array_pop($shadowid);
661 if (is_null($shadowid))
return $asset;
662 $result = $this->filterResultSet($this->getResultSet());
664 if (!empty($result)) {
665 if (isset($result[$shadowid])) {
666 $record = $result[$shadowid];
667 $record[
'shadow_asset_name'] = $this->attr(
'shadow_name');
668 $record[
'shadow_asset_id'] = $shadowid;
669 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'data_source_record_set');
674 if(is_null($asset)) {
675 return $return_null ? NULL : $this->_getDummyAsset($shadowid);
693 $record[
'shadow_asset_name'] =
'Unknown Data Source Record';
694 $record[
'shadow_asset_id'] = $shadowid;
695 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'data_source_record_set');
722 public function getParents($assetid, $type_code=
'', $strict_type_code=TRUE, $sort_by=NULL, $access=NULL)
725 $id_parts = explode(
':', $assetid);
726 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($id_parts[0]);
728 $parents[$this->id] = $this->type();
742 public function getAssetMapAssetInfo($assetid)
759 public function getLineageFromURL($assetid, $protocol, $url)
774 function filterResultSet($result)
776 if (!$this->attr(
'filter_enabled')) {
779 $filters = $this->getDatasourceFilters();
780 if (empty($filters)) {
784 $grouping_logic = $this->attr(
'filter_logic');
785 $filter_mode = $this->attr(
'filter_mode');
788 $hash = md5($this->attr(
'cache_key').$grouping_logic.$filter_mode.serialize($filters));
789 if (isset($this->tmp[$hash])) {
790 return $this->tmp[$hash];
792 $cached_result = $this->getCachedResultSet($hash);
793 if ($cached_result !== FALSE) {
794 $this->tmp[$hash] = $cached_result;
795 return $cached_result;
798 $filtered_result = Array();
799 foreach($result as $index => $recordset) {
800 $condition_matched = TRUE;
801 foreach($filters as $filter) {
802 $field_name = $filter[
'name'];
803 $field_value = $filter[
'value'];
804 $match_type = $filter[
'match_type'];
805 $match_case = $filter[
'match_case'];
806 if (!isset($recordset[$field_name])) {
810 $record_value = trim($recordset[$field_name]);
811 $condition_matched = FALSE;
812 switch($match_type) {
814 if ($match_case ==
'ignore_case') {
815 $condition_matched = stripos($record_value, $field_value) !== FALSE;
817 $condition_matched = strpos($record_value, $field_value) !== FALSE;
822 if ($match_case ==
'ignore_case') {
823 $condition_matched = strtolower($record_value) == strtolower($field_value);
825 $condition_matched = $record_value == $field_value;
830 $condition_matched = preg_match(
'/'.str_replace(
'/',
'\/',$field_value).
'/'.($match_case ==
'ignore_case' ?
'i' :
''), $record_value);
835 if (!$condition_matched && empty($record_value) && empty($field_value)) {
836 $condition_matched = TRUE;
839 if ($grouping_logic ==
'OR' && $condition_matched) {
841 }
else if ($grouping_logic ==
'AND' && !$condition_matched) {
847 if ($condition_matched && $filter_mode ==
'include') {
848 $filtered_result[] = $recordset;
849 }
else if (!$condition_matched && $filter_mode ==
'exclude') {
850 $filtered_result[] = $recordset;
856 $this->cacheResultSet($filtered_result, $hash);
857 $this->tmp[$hash] = $filtered_result;
859 return $filtered_result;
871 function getDatasourceFilters()
873 $filters = $this->attr(
'record_filters');
874 if (empty($filters)) {
879 $keyword_pattern =
'('.
'%%'.
'([a-zA-Z_\-0-9\.]+)'.
'%%'.
')';
881 foreach($filters as $index => $filter) {
882 if (empty($filter[
'name'])) {
886 $filter_val = $filter[
'value'];
887 preg_match_all (
'/'.$keyword_pattern.
'/', $filter_val, $matches, PREG_PATTERN_ORDER);
889 foreach($matches[2] as $keyword) {
890 $value = $this->getDynamicVariableValue($keyword);
891 $filter_val = str_replace(
'%%'.$keyword.
'%%', $value, $filter_val);
893 $filters[$index][
'value'] = $filter_val;
909 function getDynamicVariableValue($variable_name)
911 $dynamic_vars = $this->attr(
'dynamic_vars');
912 if (!isset($dynamic_vars[$variable_name]))
return '';
914 $parameter_map = $this->getAttribute(
'parameter_map');
915 $value = $parameter_map->getParameterValue($variable_name);
918 $value = array_get_index($dynamic_vars, $variable_name,
'');
933 function delete($release_lock)
935 if (parent::delete($release_lock)) {
936 $this->_deleteStoredContents();
951 function _deleteStoredContents()
954 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
955 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
957 $sql =
'DELETE FROM sq_shdw_ast_lnk WHERE minorid LIKE :minorid';
963 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
964 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();