Index: branches/5.3.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r15698 -r15902 --- branches/5.3.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 15698) +++ branches/5.3.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 15902) @@ -1,6 +1,6 @@ getUploaderFields(); + $window_id = $this->Application->GetTopmostWid($this->Prefix); - foreach ($uploader_fields as $field) { - $formatter = $this->Application->recallObject($this->GetFieldOption($field, 'formatter')); - /* @var $formatter kUploadFormatter */ - - $changed_fields = array_merge($changed_fields, $formatter->processFlashUpload($this, $field, $id)); - } - - if ( $changed_fields ) { - $this->Update(null, array_unique($changed_fields)); - } + return $this->Prefix . '_file_pending_actions' . $window_id; } /** - * Removes any info about queued uploaded files + * Returns pending actions * - * @param int $id - * @return void + * @param mixed $id + * @return Array * @access public */ - public function resetUploads($id = NULL) + public function getPendingActions($id = null) { - $uploader_fields = $this->getUploaderFields(); - - foreach ($uploader_fields as $field) { - $this->Application->RemoveVar($this->getFileInfoVariableName($field, $id)); + if ( !isset($id) ) { + $id = $this->GetID(); } - } - /** - * Returns uploader fields - * - * @return Array - * @access public - */ - public function getUploaderFields() - { - $ret = Array (); + $pending_actions = $this->Application->RecallVar($this->_getPendingActionVariableName()); + $pending_actions = $pending_actions ? unserialize($pending_actions) : Array (); - foreach ($this->Fields as $field => $options) { - if ( !isset($options['formatter']) ) { - continue; - } + if ( is_numeric($id) ) { + // filter by given/current id + $ret = Array (); - $formatter = $this->Application->recallObject($options['formatter']); - /* @var $formatter kUploadFormatter */ - - if ( $formatter instanceof kUploadFormatter ) { - $ret[] = $field; + foreach ($pending_actions as $pending_action) { + if ( $pending_action['id'] == $id ) { + $ret[] = $pending_action; + } } + + return $ret; } - return $ret; + return $pending_actions; } /** - * Returns variable name, used to store pending file actions + * Sets new pending actions * - * @return string + * @param Array|null $new_pending_actions + * @param mixed $id + * @return void * @access public */ - public function getPendingActionVariableName() + public function setPendingActions($new_pending_actions = null, $id = null) { - $window_id = $this->Application->GetTopmostWid($this->Prefix); + if ( !isset($new_pending_actions) ) { + $new_pending_actions = Array (); + } - return $this->Prefix . '_file_pending_actions' . $window_id; - } - - /** - * Returns variable name, which stores file information for object/field/window combination - * - * @param string $field_name - * @param int $id - * @return string - * @access public - */ - public function getFileInfoVariableName($field_name, $id = NULL) - { if ( !isset($id) ) { $id = $this->GetID(); } - $window_id = $this->Application->GetTopmostWid($this->Prefix); + $pending_actions = Array (); + $old_pending_actions = $this->getPendingActions(true); - return $this->Prefix . '[' . $id . '][' . $field_name . ']_file_info' . $window_id; + if ( is_numeric($id) ) { + // remove old actions for this id + foreach ($old_pending_actions as $pending_action) { + if ( $pending_action['id'] != $id ) { + $pending_actions[] = $pending_action; + } + } + + // add new actions for this id + $pending_actions = array_merge($pending_actions, $new_pending_actions); + } + else { + $pending_actions = $new_pending_actions; + } + + // save changes + $var_name = $this->_getPendingActionVariableName(); + + if ( !$pending_actions ) { + $this->Application->RemoveVar($var_name); + } + else { + $this->Application->StoreVar($var_name, serialize($pending_actions)); + } } /**