diff --git a/include/class.faq.php b/include/class.faq.php index a20060729ac804fe4284778fbe2424ba2002bffd..20474c7331078190ecf8fed65cc755db21dd96b3 100644 --- a/include/class.faq.php +++ b/include/class.faq.php @@ -149,8 +149,8 @@ class FAQ extends VerySimpleModel { function setNotes($text) { $this->notes = $text; } /* For ->attach() and ->detach(), use $this->attachments() (nolint) */ - function attach($file) { return $this->_attachments->add($file); } - function detach($file) { return $this->_attachments->remove($file); } + function attach($file) { return $this->attachments->add($file); } + function detach($file) { return $this->attachments->remove($file); } function publish() { $this->setPublished(1); diff --git a/include/class.forms.php b/include/class.forms.php index d65136a569aac97045ba5e578da18cc9ee883b1e..efa445efc3829969f2931cfec366ddd6532e28ed 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2087,10 +2087,10 @@ class FileUploadField extends FormField { $ids = array(); // Handle deletes foreach ($this->attachments->getAll() as $f) { - if (!in_array($f['id'], $value)) - $this->attachments->delete($f['id']); + if (!in_array($f->id, $value)) + $this->attachments->delete($f->id); else - $ids[] = $f['id']; + $ids[] = $f->id; } // Handle new files foreach ($value as $id) { @@ -2115,7 +2115,8 @@ class FileUploadField extends FormField { $links = array(); foreach ($this->getFiles() as $f) { $links[] = sprintf('<a class="no-pjax" href="%s">%s</a>', - Format::htmlchars($f['download_url']), Format::htmlchars($f['name'])); + Format::htmlchars($f->file->getDownloadUrl()), + Format::htmlchars($f->file->name)); } return implode('<br/>', $links); } @@ -2123,7 +2124,7 @@ class FileUploadField extends FormField { function toString($value) { $files = array(); foreach ($this->getFiles() as $f) { - $files[] = $f['name']; + $files[] = $f->file->name; } return implode(', ', $files); } @@ -2714,13 +2715,7 @@ class FileUploadWidget extends Widget { foreach ($this->value ?: array() as $fid) { $found = false; foreach ($attachments as $f) { - if ($f['id'] == $fid) { - $files[] = $f; - $found = true; - break; - } - } - if (!$found && ($file = AttachmentFile::lookup($fid))) { + $file = $f->file; $files[] = array( 'id' => $file->getId(), 'name' => $file->getName(),