Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_status.inc
1 <?php
29 {
30 
35  var $status_tag = 0;
36 
41  var $owner = null;
42 
43 
49  function Asset_Status($owner)
50  {
51  $this->owner = $owner;
52  $this->MySource_Object();
53 
54  }//end constructor
55 
56 
64  public static function getDescription()
65  {
66  return 'Unknown Status';
67 
68  }//end getDescription()
69 
70 
78  function getAvailableStatii()
79  {
80  return Array();
81 
82  }//end getAvailableStatii()
83 
84 
92  {
93  return NULL;
94 
95  }//end getStatusChangeMessage()
96 
97 
108  function processStatusChange($new_status, $update_parent=true)
109  {
110  // we need write access to do any changes
111  if (!$this->owner->readAccess()) {
112  trigger_localised_error('SYS0309', E_USER_WARNING, $this->owner->name, $this->owner->id);
113  return false;
114  }
115 
116  // if the new status is the same as our status, we can handle this
117  if ($new_status == $this->status_tag) return true;
118 
119  // do we need to check if the new status is valid?
120  if ($GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_STATUS_INTEGRITY)) {
121 
122  // make sure we can actually set this status
123  $valid_statii = $this->getAvailableStatii();
124  if (!isset($valid_statii[$new_status])) {
125  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
126 
127  $code = strtolower((string)get_bit_names('SQ_STATUS_', $new_status));
128  $status_code = 'asset_status_'.$code;
129  require_once SQ_INCLUDE_PATH.'/asset_status/'.$status_code.'.inc';
130  eval('$desc = '.$status_code.'::getDescription();');
131 
132  trigger_localised_error('SYS0250', E_USER_WARNING, $desc, $this->owner->name, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->owner->type(), 'name'), $this->owner->id, $this->getDescription(), $GLOBALS['SQ_SYSTEM']->user->name, $GLOBALS['SQ_SYSTEM']->user->id);
133 
134  return false;
135  }
136  }
137 
138  // we are now certain that we will be changing the status that we were asked to
139  // lets fire the trigger event 'trigger_event_before_status_change' to the triggers
140  // know we will next be changing the status. Last chance to stop before we GO GO GO !!
141  $event_data = Array(
142  'old_status' => $this->status_tag,
143  'new_status' => $new_status,
144  'allow_unrestricted' => isset($this->owner->_tmp['allow_unrestricted']) ? $this->owner->_tmp['allow_unrestricted'] : NULL,
145  );
146 
147  // if the broadcast returns FALSE, dont go ahead with changing the status
148  // NOTE : it is likely to return FALSE only if the trigger is blocking
149  // in other cases the asset status change will still go ahead in full swing
150  if (!$GLOBALS['SQ_SYSTEM']->broadcastTriggerEvent('trigger_event_before_status_change', $this->owner, $event_data)) {
151  return FALSE;
152  }
153 
154  return TRUE;
155 
156  }//end processStatusChange()
157 
158 
159 }//end class
160 
161 ?>