Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_thumbnail.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/parameter_map/parameter_map.inc';
20 
33 {
34 
35 
54  public static function execute($settings, &$state)
55  {
56  if (empty($state['asset'])) {
57  // grab the asset if assetid is given, but not the asset.
58  if (empty($state['assetid'])) {
59  // Fail silently if no asset
60  return TRUE;
61  } else {
62  $state['asset'] = &$GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
63  }
64  }
65 
66  if (isset($settings['imageid']) && !empty($settings['imageid'])) {
67  $thumbnail = $GLOBALS['SQ_SYSTEM']->am->getAsset($settings['imageid']);
68  } else {
69  $parameter_map_value = array_get_index($settings, 'thumbnail', serialize(Array()));
70  $atr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
71  $assetid = $atr_parameter_map->getParameterValue('thumbnail');
72  if (!empty($assetid)) {
73  $thumbnail = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
74  } else {
75  // Fail silently if empty
76  return TRUE;
77  }
78  }
79 
80  // asset must be image (and fail silently)
81  if (!is_a($thumbnail, 'image')) return TRUE;
82 
83  // Set the thumbnail to the asset passed
84  // Delete any thumbnail links
85  $grab_link = $GLOBALS['SQ_SYSTEM']->am->getLink($state['assetid'], SQ_LINK_NOTICE, '', FALSE, 'thumbnail');
86 
87  if (is_array($grab_link) && isset($grab_link['linkid'])) {
88  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($grab_link['linkid']);
89  }
90 
91  // Create the new thumbnail link
92  $tmblink = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($state['asset'], $thumbnail, SQ_LINK_NOTICE, 'thumbnail');
93 
94  return Array(
95  'linkid' => $tmblink,
96  );
97 
98  }//end execute()
99 
100 
111  public static function getInterface($settings, $prefix, $write_access=FALSE)
112  {
113  // set defaults
114  $settings['thumbnail'] = array_get_index($settings, 'thumbnail', Array());
115 
116  $pmap = new Asset_Attribute_Parameter_Map();
117  $pmap->setParameter('thumbnail', 'Set new Thumbnail');
118  $pmap->setValue($settings['thumbnail']);
119 
120  // begin buffering basic options
121  ob_start();
122  // Save the prefix
123  $new_prefix = str_replace(array('[',']'), '_', $prefix);
124  hidden_field($prefix.'[new_prefix]', $new_prefix);
125 
126  echo $pmap->paint($new_prefix, !$write_access);
127  $basic_part_1 = ob_get_contents();
128  ob_end_clean();
129 
130  return translate('trigger_set_thumbnail', $basic_part_1);
131 
132  }//end getInterface()
133 
134 
146  public static function processInterface(&$settings, $request_data)
147  {
148  if (empty($request_data)) {
149  return translate('trigger_input_data_missing');
150  }
151 
152  // Get the prefix
153  $new_prefix = str_replace(array('[',']'), '_', array_get_index($request_data, 'new_prefix', ''));
154 
155  // check if the name, constrain, width and height are set
156  $pmap = new Asset_Attribute_Parameter_Map();
157  $pmap->process($new_prefix);
158  $settings['thumbnail'] = $pmap->value;
159 
160  return FALSE;
161 
162  }//end processInterface()
163 
164 
174  public static function getLocks($settings, &$state)
175  {
176  return Array($state['assetid'] => Array('all'));
177 
178  }//end getLocks()
179 
180 
181 }//end class
182 
183 ?>