/** * 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'); }
/** * execute * * @param \Form\Form $form */ public function update($form) { $object = new \LTI_Tool_Consumer($form->getFieldValue('key'), $this->getConfig()->getLtiDataConnector()); // Load object $object->name = $form->getFieldValue('name'); $object->secret = $form->getFieldValue('secret'); $object->enabled = $form->getFieldValue('enabled'); $object->protected = $form->getFieldValue('protected'); $object->css_path = $form->getFieldValue('css_path'); $object->updated = \Tk\Date::create()->getTimestamp(); // validate object if (!$object->name) { $form->addFieldError('name', 'Please supply a valid consumer name'); } if (!preg_match('/^[a-z0-9_-]{1,64}$/i', $object->getKey())) { $form->addFieldError('consumerKey', 'Invalid characters used in key field'); } if (!preg_match('/^[a-z0-9]{1,64}$/i', $object->secret)) { $form->addFieldError('secret', 'Invalid characters used in secret field'); } if ($form->hasErrors()) { if (!\Mod\Notice::hasMessages()) { \Mod\Notice::addError('The form contains errors.'); } return; } if (!$this->getConfig()->getLtiDataConnector()->Tool_Consumer_save($object)) { if (!\Mod\Notice::hasMessages()) { \Mod\Notice::addError('Error saving consumer to DB.'); } return; } //$this->getRedirectUrl()->set('key', $object->getKey())->redirect(); $this->getRedirectUrl()->redirect(); }