public function delete() { if ($this->pdfBgImage) { // TODO: Delete the image \Tk\Path::rmdir($this->getConfig()->getDataPath() . $this->pdfBgImage); } return parent::delete(); }
/** * execute * * @param \Form\Form $form */ public function update($form) { /* @var $object \coa\Db\CoaSetup */ $object = $form->getObject(); /* @var $file \Form\Field\File */ $file = $form->getField('pdfBgImage'); if ($object instanceof \Tk\Db\Model) { $form->loadObject($object); $form->addFieldErrors($object->getValidator()->getErrors()); } if ($form->hasErrors()) { if (!\Mod\Notice::hasMessages()) { \Mod\Notice::addError('The form contains errors.'); } return; } $object->save(); if ($file && $file->hasFile()) { $path = $object->getBasePath(); \Tk\Path::rmdir($this->getConfig()->getDataPath() . $path); $file->moveUploadedFile($this->getConfig()->getDataPath() . $path . '/' . $file->getFileName()); $object->pdfBgImage = $path . '/' . $file->getFileName(); $object->save(); } \Mod\Notice::addSuccess('Form submission successful'); }