Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
tool_mass_clone.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/assets/system/tool/tool.inc';
18 
31 class Tool_Mass_Clone extends Tool
32 {
33 
34 
41  function Tool_Mass_Clone($assetid=0)
42  {
43  $this->Tool($assetid);
44 
45  }//end constructor
46 
47 
58  public static function paintTool(&$o, $type_code)
59  {
60  $o->openSection(translate('mass_clone'));
61  $o->openField(translate('mass_clone_asset_to_clone'));
62  asset_finder('asset_to_clone', 0, call_user_func(Array($type_code, 'getClonableTypes')));
63  $err_msg = str_replace("'", "\'", translate('mass_clone_must_choose_asset'));
64  $o->addOnSubmit("if (document.getElementById('asset_to_clone[assetid]').value == 0) {
65  alert('$err_msg');
66  return false;
67  }");
68  $o->closeField();
69  $o->openField(translate('mass_clone_num_clones'));
70  int_text_box('number_of_clones', 1, FALSE, 3, 1, 128);
71  $o->closeField();
72  $o->openField('Parent for new clones');
73  asset_finder('clone_parent');
74  $err_msg = str_replace("'", "\'", translate('mass_clone_must_choose_parent'));
75  $o->addOnSubmit("if (document.getElementById('clone_parent[assetid]').value == 0) {
76  alert('$err_msg');
77  return false;
78  }");
79  $o->closeField();
80  $o->openField(translate('mass_clone_type_of_link'));
81  $link_types = get_link_type_names();
82  unset($link_types[SQ_LINK_NOTICE]);
83  combo_box('link_type', $link_types, FALSE, '');
84  $o->closeField();
85  $o->closeSection();
86 
87  }//end paintTool()
88 
89 
100  public static function processTool(&$o, $type_code)
101  {
102  if (!isset($_REQUEST['asset_to_clone']) || empty($_REQUEST['asset_to_clone']['assetid'])) {
103  trigger_localised_error('CORE0253', E_USER_WARNING);
104  return FALSE;
105  }
106  if (!isset($_REQUEST['clone_parent']) || empty($_REQUEST['clone_parent']['assetid'])) {
107  trigger_localised_error('CORE0254', E_USER_WARNING);
108  return FALSE;
109  }
110  if (empty($_REQUEST['number_of_clones'])) {
111  trigger_localised_error('CORE0255', E_USER_WARNING);
112  return FALSE;
113  }
114  if (empty($_REQUEST['link_type'])) {
115  trigger_localised_error('CORE0256', E_USER_WARNING);
116  return FALSE;
117  }
118  $vars = call_user_func(Array($type_code, 'getHipoRunningVars'), $type_code);
119  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
120  $hh->queueHipo('hipo_job_clone_assets', $vars);
121  $url = $hh->runQueuedJobs();
122  if (!empty($url)) $o->setRedirect($url);
123  return TRUE;
124 
125  }//end processTool()
126 
127 
135  public static function getClonableTypes()
136  {
137  return Array();
138 
139  }//end getClonableTypes()
140 
141 
151  public static function getHipoRunningVars($type_code)
152  {
153  $original_id = $_REQUEST['asset_to_clone']['assetid'];
154  $num_clones = $_REQUEST['number_of_clones'];
155  return Array(
156  'assets' => Array($original_id => Array('number_of_clones' => $num_clones)),
157  'to_parent_assetid' => $_REQUEST['clone_parent']['assetid'],
158  'to_parent_pos' => -1,
159  'link_type' => $_REQUEST['link_type'],
160  'value' => '',
161  'finalise_function' => Array($type_code, 'finaliseClone'),
162  );
163 
164  }//end getHipoRunningVars()
165 
166 
180  public static function finaliseClone(&$clone, &$running_vars)
181  {
182  // child classes can override
183 
184  }//end finaliseClone()
185 
186 
187 }//end class
188 ?>