public function actionIndex2() { $searchModel = new GradeSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (Yii::$app->request->post('hasEditable')) { $gradeId = Yii::$app->request->post('editableKey'); $grade = Grade::findOne($gradeId); $subject = Subject::findOne($grade->subject_subject_id); $out = Json::encode(['output' => '', 'message' => '']); $post = []; $posted = current($_POST['Grade']); $post['Grade'] = $posted; if ($grade->load($post)) { if ($grade->grade_approval_status == 'Approved') { $grade->grade_approved_by = Yii::$app->user->identity->username; } else { $grade->grade_approved_by = null; } if ($grade->takenStatus == null) { $grade->takenStatus = 'Not Taken'; } // $subjectTakenStatus = ArrayHelper::map(Subject::find() // ->where(['subject_id'=>$grade->subject_subject_id]) // ->all(),'subject_id','subject_taken_status'); $subject->subject_taken_status = $grade->takenStatus; $subject->save(); $grade->save(); } echo $out; return; } return $this->render('index2', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
protected function findModel($id) { if (($model = Subject::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function createScreeningPdf($hash) { $screening_entry_model = ScreeningEntry::findOne(['hash' => $hash]); $screening_form_model = ScreeningForm::findOne(['id' => $screening_entry_model->screening_form_id]); $subject_model = Subject::findOne(['id' => $screening_entry_model->subject_id]); $count = 1; //$permissions = \SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT ; $this->_font = 'Helvetica'; //class_exists('TCPDF', true); // trigger Composers autoloader to load the TCPDF class $pdf = new \FPDI(); $pdf->SetAutoPageBreak(true); // add a page $pdf->SetTopMargin(30); $pdf->AddPage(); $pdf->setSourceFile(\yii::$app->basePath . "/../letterhead-mini-header.pdf"); $tplIdx = $pdf->importPage(1); // use the imported page and place it at point 10,10 with a width of 100 mm $pdf->useTemplate($tplIdx, 0, 0); $pdf->SetFont($this->_font, '', 9); $pdf->SetXY(10, 6); $pdf->Cell(0, 3, 'Confidential - Participant screening form'); $pdf->SetFont($this->_font, '', 12); $pdf->SetXY(10, 14); $pdf->MultiCell(150, 3, yii::$app->DateComponent->timestampToUkDate($screening_entry_model->created_at), 0, 'R'); $pdf->MultiCell(100, 3, $screening_entry_model->screening_form_title, 0, ''); $pdf->Ln(); $pdf->SetFont($this->_font, '', 9); $pdf->Cell(100, 4, sprintf('Participant: %s %s (dob %s)', $screening_entry_model->subject->first_name, $screening_entry_model->subject->last_name, yii::$app->DateComponent->isoToUkDate($screening_entry_model->subject->dob))); $pdf->Cell(50, 4, sprintf('Identifier: %s', $screening_entry_model->subject->cubric_id), 0, '', 'R'); $pdf->Ln(); $pdf->Cell(100, 4, sprintf('Researcher: %s %s (project %s)', $screening_entry_model->researcher->first_name, $screening_entry_model->researcher->last_name, $screening_entry_model->project->code)); $pdf->Cell(50, 4, sprintf('Resource: %s', $screening_entry_model->resource_title), 0, '', 'R'); $pdf->SetXY(10, 38); $pdf->SetFont($this->_font, '', 12); $pdf->Cell(150, 4, sprintf('Responses')); $pdf->SetFont($this->_font, '', 9); $pdf->Ln(); foreach (yii::$app->screeningresponse->getResponses($hash) as $response) { if (strlen($response['caption']) > 0) { $pdf->Ln(); $pdf->MultiCell(180, 4, sprintf('%s ', $response['caption']), 0, 'U'); $count = 1; } $pdf->MultiCell(180, 4, sprintf('%s. %s ', $count, $response['content'])); $pdf->SetFont($this->_font, 'B', 9); if ($response['response'] === null) { $response['response'] = 'Not specified / Unknown.'; } $pdf->MultiCell(180, 4, sprintf('%s ', $response['response'])); $pdf->SetFont($this->_font, '', 9); $count++; $pdf->Ln(); } $pdf->Ln(); $pdf->SetFont($this->_font, '', 12); $pdf->Cell(180, 4, sprintf('Signatures')); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont($this->_font, '', 9); $pdf->Cell(100, 4, 'Participant '); $pdf->Cell(100, 4, 'Researcher '); $pdf->Ln(); $pdf->Ln(); $currentX = $pdf->GetX(); $currentY = $pdf->GetY(); $pdf->Image(sprintf('/tmp/subject-%s.png', $hash), $currentX, $currentY); $currentX = $pdf->GetX(); $pdf->Image(sprintf('/tmp/researcher-%s.png', $hash), $currentX + 100, $currentY); // now write some text above the imported page // NOW SET ScreeningEntry::progress_id = PUBLISHED so it cannot be edited again. // $pdfData = $pdf->Output('S'); // create a writer // create a Http writer //$writer = new \SetaPDF_Core_Writer_Http("fpdf-sign-demo.pdf", true); // load document by filename //$document = new \SetaPDF_Core_Document::loadByString($pdfData, $writer); //$document = new \SetaPDF_Core_Reader_File($pdf->Output(), $writer); $writer = new \SetaPDF_Core_Writer_File("/Users/Spiro/tmp/myPDF.pdf"); $document = \SetaPDF_Core_Document::loadByString($pdf->Output("S"), $writer); // let's prepare the temporary file writer: \SetaPDF_Core_Writer_TempFile::setTempDir("/tmp/"); // create a signer instance for the document $signer = new \SetaPDF_Signer($document); // add a field with the name "Signature" to the top left of page 1 $signer->addSignatureField(\SetaPDF_Signer_SignatureField::DEFAULT_FIELD_NAME, 1, \SetaPDF_Signer_SignatureField::POSITION_LEFT_BOTTOM, array('x' => 10, 'y' => 10), 180, 50); // set some signature properties $signer->setReason('Integrity'); $signer->setLocation('CUBRIC'); $signer->setContactInfo('+44 2920 703859'); // ccreate an OpenSSL module instance $module = new \SetaPDF_Signer_Signature_Module_OpenSsl(); // set the sign certificate $module->setCertificate(file_get_contents("/Users/spiro/Sites/projects/certs/certificate.pem")); // set the private key for the sign certificate $module->setPrivateKey(array(file_get_contents("/Users/spiro/Sites/projects/certs/key.pem"), "")); // create a Signature appearance $visibleAppearance = new \SetaPDF_Signer_Signature_Appearance_Dynamic($module); // choose a document to get the background from and convert the art box to an xObject $backgroundDocument = \SetaPDF_Core_Document::loadByFilename(Yii::getAlias('@frontend/web/img/cubric-logo.pdf')); $backgroundXObject = $backgroundDocument->getCatalog()->getPages()->getPage(1)->toXObject($document); // format the date $visibleAppearance->setShowFormat(\SetaPDF_Signer_Signature_Appearance_Dynamic::CONFIG_DATE, 'd-m-Y H:i:s'); // disable the distinguished name $visibleAppearance->setShow(\SetaPDF_Signer_Signature_Appearance_Dynamic::CONFIG_DISTINGUISHED_NAME, false); // set the background with 50% opacity $visibleAppearance->setGraphic($backgroundXObject, 0.5); //$visibleAppearance->setBackgroundLogo($backgroundXObject, .5); // sign/certify the document // define the appearance $signer->setAppearance($visibleAppearance); $signer->sign($module); if (file_exists(sprintf('/tmp/subject-%s.png', $hash))) { } // unlink(sprintf('/tmp/subject-%s.png' , $hash)); if (file_exists(sprintf('/tmp/researcher-%s.png', $hash))) { } // unlink(sprintf('/tmp/researcher-%s.png' , $hash)); return true; }
public function actionFinish($sig) { $screening_entry_model = ScreeningEntry::findOne(['hash' => $sig]); if ($screening_entry_model === null) { throw new \yii\web\HttpException(404, yii::t('app', 'Page cannot be found.')); } $subject_model = Subject::findOne(['id' => $screening_entry_model->subject_id]); Yii::$app->user->logout(); return $this->render('finish', ['cubric_identifier' => $subject_model->cubric_id]); }