/** * @return \yii\db\ActiveQuery */ public function getTask() { return $this->hasOne(Tasks::className(), ['id' => 'tasks_id']); }
public function actionCloseTask($tasks_id) { if ($tasks_id != Tasks::find()->where(['state' => 1])->one()->id) { Yii::$app->getSession()->setFlash('error', 'Возникли проблемы. Попробуйте позже'); } else { $task = Tasks::find()->where(['id' => $tasks_id])->one(); $task->state = 0; $task->save(); (new CertificatesHelper())->createExcels($task->id); } return $this->redirect(['/certificates/requests', 'tasks_id' => $tasks_id]); }
public function createCompaniesZip($tasks_id) { $task = Tasks::findOne($tasks_id); foreach ($task->requests as $request) { $name = $this->translit($request->company->name) . '_' . $tasks_id . '.zip'; $zip = new ZipArchive(); $destination = 'uploads/certificates/companies_zip/' . $name; if ($zip->open($destination, ZipArchive::CREATE) !== true) { return false; } foreach ($request->requestedCertificates as $requested_certificate) { $wagons = preg_split('/[\\s,]+/', $requested_certificate->wagons); foreach ($wagons as $wagon) { if ($lost = CertificatesLost::find()->where(['tasks_id' => $tasks_id, 'wagon' => $wagon, 'certificates_id' => $requested_certificate->certificate->id])->one()) { $lost->delete(); } if (!$zip->addFile('uploads/certificates/certificates_txt/' . $requested_certificate->certificate->code . '_' . $wagon . '.txt', $requested_certificate->certificate->code . '_' . $wagon . '.txt')) { $lost = new CertificatesLost(); $lost->tasks_id = $tasks_id; $lost->wagon = $wagon; $lost->certificates_id = $requested_certificate->certificate->id; $lost->save(); } } } $zip->close(); if (file_exists($destination)) { $this->writeFilePath($destination, $name, 'companies-zip', $tasks_id); } } $this->clearCertificatesTxtFolder(); }