public function saveEssay() { $essay = new Essays(); $essay->text = htmlentities($this->text, ENT_NOQUOTES); $essay->user_id = Yii::$app->user->id; $essay->create_date = date("Y-m-d H:i:s"); $photo = UploadedFile::getInstancesByName('photo'); if (isset($photo[0]) && $photo[0]->tempName) { $photo_name = uniqid() . '.' . $photo[0]->getExtension(); $essay->photo_path = $photo_name; if ($essay->validate()) { $photo[0]->saveAs(Essays::ESSAY_PHOTO_PATH . $photo_name); } } return $essay->save(); }
public function updatePhotoEssay() { $essay = Essays::findOne($this->essay_id); $photo = UploadedFile::getInstance($this, 'photo'); if (!empty($essay) && isset($photo) && $photo->tempName && in_array($photo->getExtension(), self::$valid_exts) && $photo->size < self::MAX_SIZE) { $photo_name = uniqid() . '.' . $photo->getExtension(); $essay->photo_path = $photo_name; $this->photo_path = $photo_name; if ($photo->saveAs(Essays::ESSAY_PHOTO_PATH . $photo_name) && $essay->save()) { return true; } } return false; }
public static function addSocialVote($type, $id, $essay_id) { $essay = \app\models\Essays::findOne($essay_id); if (!empty($essay) && $essay->canVote()) { $vote = \app\models\Votes::find()->where(["type" => $type, "soc_id" => $id, "essay_id" => $essay_id])->one(); if (empty($vote)) { $nvote = new \app\models\Votes(); $nvote->type = $type; $nvote->soc_id = $id; $nvote->essay_id = $essay_id; $nvote->save(); return ["status" => "success", "text" => ""]; } else { return ["status" => "error", "text" => "За эту работу уже голосовали с вашего аккаунта"]; } } else { return ["status" => "error", "text" => "Уже нельзя голосовать за эту работу"]; } }
/** * @return \yii\db\ActiveQuery */ public function getEssay() { return $this->hasOne(Essays::className(), ['id' => 'essay_id']); }
?> , </b> <b style="font-size:16px;"> <?php echo $essay['city']; ?> , <?php echo app\models\User::getYearsOld($essay['birth_date']); ?> года </b> </p> <p> <?php echo Essays::getPhoto($essay['photo_path']) ? "<img src=" . Essays::getPhoto($essay['photo_path']) . ">" : ""; ?> <?php echo $essay['text']; ?> </p> </div> <?php } ?> </div> <a class="carousel-control left" href="#adminCarousel" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="carousel-control right" href="#adminCarousel" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span>
public function actionEssayphoto() { $essayForm = new \app\models\EssayPhotoForm(); if (Yii::$app->request->isAjax && $essayForm->load(Yii::$app->request->post())) { if ($essayForm->updatePhotoEssay()) { return json_encode(["status" => "ok", "text" => "фото успешно добавлено", "imgSrc" => Essays::getPhoto($essayForm->photo_path)]); } else { return json_encode(["status" => "error", "text" => "не получилось добавить фото, возможно неверный формат, только: jpg, png, jpeg, размер файла максимум: 3MB"]); } } return json_encode(["status" => "error", "text" => "неверный запрос"]); }
?> </p> </div> <div class="text-esse <?php echo Essays::getPhoto($essay['photo_path']) ? '' : 'without-foto'; ?> "> <div class="fleft"> <p><?php echo $essay['text']; ?> </p> </div> <div class="fright"> <?php echo Essays::getPhoto($essay['photo_path']) ? "<img src='" . Essays::getPhoto($essay['photo_path']) . "' alt='Фото победителя' >" : ""; ?> </div> </div> <div class="opros-esse"> <a href="#openwins" class="href-esse open_essay">Читать полностью</a> <a href="#auto-soc" class="href-esse essay_vote">Проголосовать за работу</a> </div> </div> </div> </div> <?php } ?> </div> </div>
if (count($weeks)) { ?> <div class="table"> <h3>Победители промежуточных этапов</h3> <table class="table-part"> <thead> <tr> <td>Период</td> <td>Победитель</td> <td>Ссылка на работу</td> </tr> </thead> <tbody> <?php foreach ($weeks as $week) { $winner = \app\models\Essays::getWeekWeener($week['id']); if (!empty($winner)) { ?> <tr data-essay-id="<?php echo $winner['essay_id']; ?> "> <td>Неделя <?php echo $week['id']; ?> </td> <td><?php echo $winner['firstname']; ?> , <?php echo app\models\User::getYearsOld($winner['birth_date']);