From 9523ed7475dc205b36802120434395dd123abad7 Mon Sep 17 00:00:00 2001 From: iIronside Date: Mon, 14 Nov 2022 13:48:31 +0300 Subject: [PATCH 1/2] update header from pdf format --- .../controllers/ResumeTemplateController.php | 1 + .../card/controllers/UserCardController.php | 45 ++++++-- .../card/models/ResumeTemplateSearch.php | 7 +- .../card/views/resume-template/_form.php | 103 ++++++------------ .../card/views/resume-template/_search.php | 4 + .../card/views/resume-template/index.php | 7 ++ .../card/views/resume-template/view.php | 11 +- .../modules/card/views/user-card/resume.php | 2 +- common/models/ResumeTemplate.php | 8 +- common/models/UserCard.php | 11 +- ...0_133204_add_header_to_resume_template.php | 42 +++++++ ..._template_id_column_to_user_card_table.php | 27 +++++ 12 files changed, 182 insertions(+), 86 deletions(-) create mode 100644 console/migrations/m221110_133204_add_header_to_resume_template.php create mode 100644 console/migrations/m221111_124753_add_resume_template_id_column_to_user_card_table.php diff --git a/backend/modules/card/controllers/ResumeTemplateController.php b/backend/modules/card/controllers/ResumeTemplateController.php index d464d6e..7e1ebbb 100644 --- a/backend/modules/card/controllers/ResumeTemplateController.php +++ b/backend/modules/card/controllers/ResumeTemplateController.php @@ -2,6 +2,7 @@ namespace backend\modules\card\controllers; +use common\classes\Debug; use Yii; use backend\modules\card\models\ResumeTemplate; use backend\modules\card\models\ResumeTemplateSearch; diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 97a601f..67e2a88 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -249,7 +249,7 @@ class UserCardController extends Controller } private function generateText(UserCard $userCard) { - $resumeTemplate = ResumeTemplate::findOne($userCard->resumeTemplateId); + $resumeTemplate = ResumeTemplate::findOne($userCard->resume_template_id); $resumeText = $resumeTemplate->template_body; foreach (ResumeTemplate::$fieldSignatureDbName as $fieldSignature => $fieldDbName ) { @@ -278,24 +278,55 @@ class UserCardController extends Controller public function actionDownloadResumePdf($id) { - $model = UserCard::findOne($id); + $userCard = UserCard::findOne($id); + $resumeTemplate = ResumeTemplate::findOne($userCard->resume_template_id); - $pdf = new Pdf(); // or new Pdf(); - $mpdf = $pdf->api; // fetches mpdf api - $mpdf->SetHeader('Resume ' . $model->fio . '||Generated by ITGuild.info At: ' . date("d/m/Y")); // call methods or set any properties + if (empty($resumeTemplate->header_text)) { + $headerText = 'Generated by ITGuild.info At: ' . date("d/m/Y"); + } else { + $headerText = $resumeTemplate->header_text; + } + + $pdf = new Pdf(); + $mpdf = $pdf->api; + + if (!pathinfo($resumeTemplate->header_image, PATHINFO_EXTENSION)) { + $mpdf->SetHeader($headerText); + } else { + $imagePath = Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image; + $mpdf->setAutoTopMargin='stretch'; + $mpdf->SetHTMLHeader( + "
+

$headerText

+
" + ); + } $mpdf->SetFooter('{PAGENO}'); - $mpdf->WriteHtml($model->resume_text); // call mpdf write html - echo $mpdf->Output("Resume - {$model->fio}", 'D'); // call the mpdf api output as needed + $mpdf->WriteHTML("
$userCard->resume_text
"); + $mpdf->Output("Resume - {$userCard->fio}", 'D'); // call the mpdf api output as needed + exit; } public function actionDownloadResumeDocx($id) { $model = UserCard::findOne($id); + $resumeTemplate = ResumeTemplate::findOne($model->resume_template_id); $pw = new \PhpOffice\PhpWord\PhpWord(); + +// $header = $section->createHeader(); +// $header->addImage('/home/dev238/projects/aegis/images/Logo_.jpg',['align'=>'right']); + // (B) ADD HTML CONTENT $section = $pw->addSection(); + + +// $section->addImage( Yii::getAlias('@frontend') . '/media/upload/guild.png', ['width' => '200', 'height' => '200', 'align' => 'center',]); + + + // $header = $section->addHeader(); +// $header->addImage('frontend/web/media/upload/guild.png', ['align' => 'left']); $resumeText = str_replace(array('
', '
', '
'), ' ', $model->resume_text); \PhpOffice\PhpWord\Shared\Html::addHtml($section, $resumeText, false, false); diff --git a/backend/modules/card/models/ResumeTemplateSearch.php b/backend/modules/card/models/ResumeTemplateSearch.php index d6b174d..cb0ab36 100644 --- a/backend/modules/card/models/ResumeTemplateSearch.php +++ b/backend/modules/card/models/ResumeTemplateSearch.php @@ -18,7 +18,7 @@ class ResumeTemplateSearch extends ResumeTemplate { return [ [['id', 'status'], 'integer'], - [['title', 'created_at', 'updated_at', 'template_body'], 'safe'], + [['title', 'created_at', 'updated_at', 'template_body', 'header_text', 'header_image'], 'safe'], ]; } @@ -65,8 +65,9 @@ class ResumeTemplateSearch extends ResumeTemplate ]); $query->andFilterWhere(['like', 'title', $this->title]) - ->andFilterWhere(['like', 'template_body', $this->template_body]); - + ->andFilterWhere(['like', 'template_body', $this->template_body]) + ->andFilterWhere(['like', 'header_text', $this->header_text]) + ->andFilterWhere(['like', 'header_image', $this->header_image]); return $dataProvider; } } diff --git a/backend/modules/card/views/resume-template/_form.php b/backend/modules/card/views/resume-template/_form.php index fc4627e..cd43c4e 100644 --- a/backend/modules/card/views/resume-template/_form.php +++ b/backend/modules/card/views/resume-template/_form.php @@ -1,7 +1,9 @@ + field($model, 'header_text')->textInput(['maxlength' => true]) ?> + +
+
+ +
+ 'ru', + 'controller' => 'elfinder', + // вставляем название контроллера, по умолчанию равен elfinder + 'filter' => 'image', + // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con.. + 'name' => 'ResumeTemplate[header_image]', + 'id' => 'resumeTemplateHeader_img', + 'template' => '
{input}{button}
', + 'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'], + 'buttonOptions' => ['class' => 'btn btn-primary'], + 'value' => $model->header_image, + 'buttonName' => 'Выбрать изображение', + ]); + ?> +
+
'btn btn-success']) ?>
@@ -49,74 +74,16 @@ use yii\widgets\ActiveForm; - - ФИО - ${fio} - - - Паспорт - ${passport} - - - Электронная почта - ${email} - - - Пол - ${gender} - - - Резюме - ${resume} - - - Зароботная плата - ${salary} - - - Позиция - ${position_id} - - - Город - ${city} - - - Ссылка ВК - ${link_vk} - - - Ссылка Телграм - ${link_telegram} - - - Резюме текст - ${vc_text} - - - Уровень - ${level} - - - Резюме текст - ${vc_text} - - - Резюме короткий текст - ${vc_text_short} - - - Лет опыта - ${years_of_exp} - - - Спецификация - ${specification} - - - Навыки - ${skills} - + $signature) { + echo " + + $fieldNames + $signature + + "; + } + ?> diff --git a/backend/modules/card/views/resume-template/_search.php b/backend/modules/card/views/resume-template/_search.php index fa02275..77a3fe2 100644 --- a/backend/modules/card/views/resume-template/_search.php +++ b/backend/modules/card/views/resume-template/_search.php @@ -27,6 +27,10 @@ use yii\widgets\ActiveForm; field($model, 'template_body') ?> + field($model, 'header_text') ?> + + field($model, 'header_image') ?> +
'btn btn-primary']) ?> 'btn btn-default']) ?> diff --git a/backend/modules/card/views/resume-template/index.php b/backend/modules/card/views/resume-template/index.php index d966389..fdaec80 100644 --- a/backend/modules/card/views/resume-template/index.php +++ b/backend/modules/card/views/resume-template/index.php @@ -33,6 +33,13 @@ $this->params['breadcrumbs'][] = $this->title; } ], + 'created_at', + 'updated_at', + + //'template_body:ntext', + //'header_text', + //'header_image', + ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/backend/modules/card/views/resume-template/view.php b/backend/modules/card/views/resume-template/view.php index c946e81..5f2aade 100644 --- a/backend/modules/card/views/resume-template/view.php +++ b/backend/modules/card/views/resume-template/view.php @@ -40,7 +40,16 @@ $this->params['breadcrumbs'][] = $this->title; 'filter' => StatusHelper::statusList(), 'value' => StatusHelper::statusLabel($model->status), ], - 'template_body:ntext' + 'header_text', + [ + 'attribute'=>'header_image', + 'value'=>$model->header_image, + 'format' => ['image',['width'=>'100','height'=>'100']], + ], + [ + 'attribute' => 'template_body', + 'format' => 'raw' + ], ], ]) ?> diff --git a/backend/modules/card/views/user-card/resume.php b/backend/modules/card/views/user-card/resume.php index 5bfef32..3c41e79 100644 --- a/backend/modules/card/views/user-card/resume.php +++ b/backend/modules/card/views/user-card/resume.php @@ -29,7 +29,7 @@ $this->params['breadcrumbs'][] = 'Резюме'; ?> id); ?> - field($model, 'resumeTemplateId')->dropDownList( + field($model, 'resume_template_id')->dropDownList( ResumeTemplate::find()->where(['status' => StatusHelper::STATUS_ACTIVE])->select(['title', 'id'])->indexBy('id')->column(), ['prompt' => 'Выберите']) ?> diff --git a/common/models/ResumeTemplate.php b/common/models/ResumeTemplate.php index a303f60..7aea051 100644 --- a/common/models/ResumeTemplate.php +++ b/common/models/ResumeTemplate.php @@ -16,6 +16,8 @@ use yii\helpers\ArrayHelper; * @property string $updated_at * @property int $status * @property string $template_body + * @property string $header_text + * @property string $header_image */ class ResumeTemplate extends \yii\db\ActiveRecord { @@ -87,7 +89,7 @@ class ResumeTemplate extends \yii\db\ActiveRecord [['created_at', 'updated_at'], 'safe'], [['status'], 'integer'], [['template_body'], 'string'], - [['title'], 'string', 'max' => 255], + [['title', 'header_text', 'header_image'], 'string', 'max' => 255], ]; } @@ -102,7 +104,9 @@ class ResumeTemplate extends \yii\db\ActiveRecord 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'status' => 'Статус', - 'template_body' => 'Template Body' + 'template_body' => 'Template Body', + 'header_text' => 'Текст в верхнем контикуле', + 'header_image' => 'Картинка в верхнем контикуле', ]; } } diff --git a/common/models/UserCard.php b/common/models/UserCard.php index f396c07..45d306e 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -39,9 +39,11 @@ use yii\helpers\ArrayHelper; * @property string $test_task_getting_date * @property string $test_task_complete_date * @property string $resume_text + * @property int $resume_template_id * * @property FieldsValue[] $fieldsValues * @property ProjectUser[] $projectUsers + * @property ResumeTemplate $resumeTemplate * @property Position $position * @property Status $status0 * @property Achievement[] $achievements @@ -59,7 +61,7 @@ class UserCard extends \yii\db\ActiveRecord const SCENARIO_GENERATE_RESUME_TEXT = 'generate_resume_text'; const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text'; - public $resumeTemplateId; +// public $resumeTemplateId; /** * @return string[] @@ -117,9 +119,10 @@ class UserCard extends \yii\db\ActiveRecord [['salary'], 'string', 'max' => 100], [['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], - ['resumeTemplateId', 'required', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT], - ['resumeTemplateId', 'integer', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT], + ['resume_template_id', 'required', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT], + ['resume_template_id', 'integer', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT], ['resume_text', 'required', 'on' => self::SCENARIO_UPDATE_RESUME_TEXT], +// [['resume_template_id'], 'exist', 'skipOnError' => true, 'targetClass' => ResumeTemplate::className(), 'targetAttribute' => ['resume_template_id' => 'id'], 'on' => self::SCENARIO_GENERATE_RESUME_TEXT], ]; } @@ -154,7 +157,7 @@ class UserCard extends \yii\db\ActiveRecord 'specification' => 'Спецификация', 'test_task_getting_date' => 'Дата получения тестового', 'test_task_complete_date' => 'Дата выполнения тестового', - 'resumeTemplateId' => 'Шаблон резюме', + 'resume_template_id' => 'Шаблон резюме', 'resume_text' => 'Резюме сгенерированный текст' ]; } diff --git a/console/migrations/m221110_133204_add_header_to_resume_template.php b/console/migrations/m221110_133204_add_header_to_resume_template.php new file mode 100644 index 0000000..f85e289 --- /dev/null +++ b/console/migrations/m221110_133204_add_header_to_resume_template.php @@ -0,0 +1,42 @@ +addColumn('resume_template', 'header_text', $this->string()); + $this->addColumn('resume_template', 'header_image', $this->string()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('resume_template', 'header_text'); + $this->dropColumn('resume_template', 'header_image'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m221110_133204_add_header__to_resume_template cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m221111_124753_add_resume_template_id_column_to_user_card_table.php b/console/migrations/m221111_124753_add_resume_template_id_column_to_user_card_table.php new file mode 100644 index 0000000..747524b --- /dev/null +++ b/console/migrations/m221111_124753_add_resume_template_id_column_to_user_card_table.php @@ -0,0 +1,27 @@ +addColumn('user_card','resume_template_id', $this->integer()); + $this->addForeignKey('resume_template_user_card', 'user_card', 'resume_template_id', 'resume_template', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('resume_template_user_card', 'user_card'); + $this->dropColumn('user_card', 'resume_template_id'); + } +} From 0f8aa34b4f2265926eb77dd9f3bdfa61493c679c Mon Sep 17 00:00:00 2001 From: iIronside Date: Mon, 14 Nov 2022 15:11:46 +0300 Subject: [PATCH 2/2] update header from docx format --- .../card/controllers/UserCardController.php | 21 +++++++++++-------- .../card/views/resume-template/_form.php | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 67e2a88..7c1211c 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -312,21 +312,24 @@ class UserCardController extends Controller $model = UserCard::findOne($id); $resumeTemplate = ResumeTemplate::findOne($model->resume_template_id); + $imagePath = Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image; + if (empty($resumeTemplate->header_text)) { + $headerText = 'Generated by ITGuild.info At: ' . date("d/m/Y"); + } else { + $headerText = $resumeTemplate->header_text; + } + $pw = new \PhpOffice\PhpWord\PhpWord(); - -// $header = $section->createHeader(); -// $header->addImage('/home/dev238/projects/aegis/images/Logo_.jpg',['align'=>'right']); - // (B) ADD HTML CONTENT $section = $pw->addSection(); + $header = $section->addHeader(); + if (pathinfo($resumeTemplate->header_image, PATHINFO_EXTENSION)) { + $header->addImage($imagePath, ['width' => 70, 'height' => 30, 'align' => 'left']); + } + $header->addText($headerText, array('bold' => false), array('space' => array('before' => 0, 'after' => 280))); -// $section->addImage( Yii::getAlias('@frontend') . '/media/upload/guild.png', ['width' => '200', 'height' => '200', 'align' => 'center',]); - - - // $header = $section->addHeader(); -// $header->addImage('frontend/web/media/upload/guild.png', ['align' => 'left']); $resumeText = str_replace(array('
', '
', '
'), ' ', $model->resume_text); \PhpOffice\PhpWord\Shared\Html::addHtml($section, $resumeText, false, false); diff --git a/backend/modules/card/views/resume-template/_form.php b/backend/modules/card/views/resume-template/_form.php index cd43c4e..4c436b9 100644 --- a/backend/modules/card/views/resume-template/_form.php +++ b/backend/modules/card/views/resume-template/_form.php @@ -36,7 +36,7 @@ use yii\widgets\ActiveForm; field($model, 'header_text')->textInput(['maxlength' => true]) ?>
-
+