17 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
58 public static function execute($settings, &$state)
61 if (empty($settings[
'fieldid'][
'assetid'])) {
64 $fieldid = $settings[
'fieldid'][
'assetid'];
66 if (empty($settings[
'totalid'][
'assetid'])) {
69 $totalid = $settings[
'totalid'][
'assetid'];
76 if (!empty($state[
'immediate_parents'])) {
77 foreach ($state[
'immediate_parents'] as $parentid => $type_code) {
79 $comment_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($parentid, SQ_SC_LINK_ALL,
'comment');
84 if ($state[
'event'][
'name'] ===
'trigger_event_before_asset_deleted') {
86 $assetdeleted = $state[
'assetid'];
89 foreach ($comment_links as $link_info) {
91 if ($link_info[
'minorid'] === $assetdeleted)
continue;
92 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_info[
'minorid']);
93 $rating = $asset->attr(
'rating');
95 if ($rating ===
'-1')
continue;
99 $sumofratings += $rating;
103 if ($numofratings > 0) {
105 $avgofratings = (int) ($sumofratings/$numofratings);
107 $parentdata[$parentid] = $avgofratings;
111 $parentdata[$parentid] = 0;
115 $mm =& $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
119 'value' => $avgofratings,
124 'value' => $numofratings,
130 $schemaid = $GLOBALS[
'SQ_SYSTEM']->am->getParents($fieldid,
'metadata_schema');
132 $schemas = $mm->getSchemas($parentid, TRUE);
134 if (array_intersect($schemas, array_keys($schemaid)) !== Array()) {
135 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
136 $success = $mm->setMetadata($parentid, $metadata);
138 $fieldid_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fieldid);
139 $totalid_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($totalid);
142 if ($fieldid_field->attr(
'is_contextable') && $totalid_field->attr(
'is_contextable')) {
143 $mm->generateContentFile($parentid);
145 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
146 foreach ($all_contexts as $contextid => $context_data) {
147 $mm->generateContentFile($parentid, FALSE, $contextid);
151 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
154 $success_results = Array(
155 'fieldid' => $fieldid,
156 'totalid' => $totalid,
157 'parentdata' => $parentdata,
163 return $success_results;
181 public static function getInterface($settings, $prefix, $write_access=FALSE)
183 $fieldid = array_get_index($settings,
'fieldid',
'0');
184 $totalid = array_get_index($settings,
'totalid',
'0');
188 echo translate(
'trigger_avg_comment_rating_metadata_field');
191 'metadata_field_text' =>
'I',
193 if (isset($fieldid[
'assetid'])) {
194 $field_selected_asset = $fieldid[
'assetid'];
196 $field_selected_asset = 0;
198 echo asset_finder($prefix.
'[fieldid]', $field_selected_asset, $type_code);
200 if (empty($fieldid[
'assetid'])) {
201 echo
'<b>['.translate(
'no_asset_selected').
']</b>';
203 echo get_asset_tag_line($fieldid[
'assetid']);
209 echo translate(
'trigger_total_comment_rating_metadata_field');
212 'metadata_field_text' =>
'I',
214 if (isset($totalid[
'assetid'])) {
215 $total_selected_asset = $totalid[
'assetid'];
217 $total_selected_asset = 0;
219 echo asset_finder($prefix.
'[totalid]', $total_selected_asset, $type_code);
221 if (empty($totalid[
'assetid'])) {
222 echo
'<b>['.translate(
'no_asset_selected').
']</b>';
224 echo get_asset_tag_line($totalid[
'assetid']);
229 return ob_get_clean();
248 $fieldid = array_get_index($request_data,
'fieldid',
'');
249 if (empty($fieldid))
return FALSE;
250 $settings[
'fieldid'] = $fieldid;
253 $totalid = array_get_index($request_data,
'totalid',
'');
254 if (empty($totalid))
return FALSE;
255 $settings[
'totalid'] = $totalid;
271 public static function getLocks($settings, &$state)