Commit d4119a2c authored by Олег Гиммельшпах's avatar Олег Гиммельшпах

Merge branch 'master' of git.task-on.com:ktask/task-on.com

parents 1fe4f14b 25bc7081
......@@ -7,6 +7,9 @@ return [
'name' => [
'type' => 'text'
],
'subject' => [
'type' => 'text'
],
'template' => [
'type' => 'textarea'
]
......
......@@ -11,6 +11,7 @@ use Yii;
* @property string $name
* @property string $template
* @property string $created_at
* @property string $subject
*/
class MessageTemplate extends \common\components\ActiveRecordModel
{
......@@ -48,10 +49,10 @@ class MessageTemplate extends \common\components\ActiveRecordModel
public function rules()
{
return [
[['name', 'template'], 'required'],
[['name', 'template', 'subject'], 'required'],
[['template'], 'string'],
[['created_at'], 'safe'],
[['name'], 'string', 'max' => 255],
[['name', 'subject'], 'string', 'max' => 255],
];
}
......@@ -65,6 +66,7 @@ class MessageTemplate extends \common\components\ActiveRecordModel
'name' => 'Название',
'template' => 'Шаблон',
'created_at' => 'Дата создания',
'subject' => 'Тема сообщения'
];
}
}
......@@ -19,6 +19,7 @@ use yii\grid\GridView;
'id',
'name',
'subject',
[
'attribute' => 'template',
'format' => 'html',
......
<?php
namespace common\modules\school\models;
use Yii;
use common\modules\school\models\Lessons;
/**
* This is the model class for table "testings_questions_image".
*
* @property integer $id
* @property integer $question_id
* @property string $filename
*/
class LessonImage extends \common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'school_lessons_image';
}
public function name()
{
return 'Документы для уроков';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['lesson_id', 'filename'], 'required'],
[['lesson_id'], 'integer'],
[['filename'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'lesson_id' => 'Урок',
'filename' => 'Документ',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
];
}
public function getLesson()
{
return $this->hasOne(Lessons::className(), ['id' => 'lesson_id']);
}
public function getUrl()
{
return Yii::$app->params['frontUrl'] . Lessons::IMAGES_FOLDER . $this->filename;
}
}
......@@ -17,6 +17,9 @@ class Lessons extends \common\components\ActiveRecordModel
{
const PAGE_SIZE = 10;
const IMAGES_FOLDER = '/uploads/lessons_docs/';
public $filesUpload;
/**
* @inheritdoc
*/
......@@ -41,6 +44,7 @@ class Lessons extends \common\components\ActiveRecordModel
[['video_id'], 'string', 'max' => 100],
[['course_id', 'number'], 'integer'],
[['text'], 'safe'],
[['filesUpload'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif, rar, ai, ppt, doc, docx'],
];
}
......@@ -99,4 +103,57 @@ class Lessons extends \common\components\ActiveRecordModel
return false;
}
}
public function getFiles()
{
return $this->hasMany(LessonImage::className(), ['lesson_id' => 'id']);
}
public function getPath()
{
return Yii::getAlias('@frontend/web') . self::IMAGES_FOLDER;
}
public function upload()
{
if ($this->validate())
{
if(!file_exists($this->getPath()))
{
mkdir($this->getPath(), 0777, true);
}
foreach ($this->filesUpload as $file)
{
$filename = date('dmYHis-') . uniqid() . '.' . $file->extension;
$file->saveAs($this->getPath() . $filename);
$image = new LessonImage;
$image->lesson_id = $this->id;
$image->filename = $filename;
$image->save();
}
return true;
}
else
{
return false;
}
}
public function deleteFiles()
{
if($this->files)
{
foreach ($this->files as $file)
{
if(file_exists($this->getPath() . $file->filename))
{
unlink($this->getPath() . $file->filename);
}
$file->delete();
}
}
}
}
......@@ -50,6 +50,10 @@ class DefaultController extends BaseController
$trigger->initAction($message);
}
}
/** @var TriggerSchedule $model */
$model=TriggerSchedule::findOne($message->getPrimaryKey());
$model->checked=1;
$model->save();
}
}
}
......@@ -30,7 +30,7 @@ return [
],
'message_template_id' => [
'type' => 'dropdownlist',
'items' => array('1' => 'first template', '2' => 'second template')
'items' => \yii\helpers\ArrayHelper::map(\common\modules\messageTemplate\models\MessageTemplate::find()->all(), 'id', 'name')
],
'timeout' => [
'type' => 'text',
......
<?php
namespace common\modules\users\models;
use common\components\UnisenderAPI;
use common\modules\messageTemplate\controllers\TemplateAdminController;
use common\modules\messageTemplate\models\MessageTemplate;
use common\modules\triggers\models\TriggerSchedule;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\Json;
use yii\web\IdentityInterface;
use yii\data\ActiveDataProvider;
use himiklab\sortablegrid\SortableGridBehavior;
use \common\components\validators\RuEmailValidator;
use \common\modules\messageTemplate\components\Templates;
use \common\modules\rbac\models\AuthItem;
use \common\modules\rbac\models\AuthAssignment;
......@@ -538,5 +544,56 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
{
return (bool)static::find()->where('email = :email', [':email'=>$email])->count();
}
/**
* @param $template_id
*/
public function afterRegistration($template_id){
/** @var \DateTime $time_now */
$time_now=new \DateTime();
/** @var MessageTemplate $templateModel */
$templateModel = MessageTemplate::findOne($template_id);
/** @var Templates $template */
$template = new Templates($template_id, ['user_fio' => $this->fio]);
$email = $this->email;
$sender = new UnisenderAPI();
// Create the send list
$newList = $sender->createList();
$newListObject=Json::decode($newList);
if (array_key_exists('result', $newListObject) && array_key_exists('id', $newListObject['result'])) {
$newListId=$newListObject['result']['id'];
// Subscribe user to new List
$sender->subscribe(['list_ids' => $newListId, 'fields[email]' => $email, 'double_optin' => 1]);
// Create new message
$newMessage=$sender->createEmailMessage($this->fio, $email, $templateModel->subject, $template->getTemplate(), $newListId);
// Decode result
$newMessageObject=Json::decode($newMessage);
if (array_key_exists('result', $newMessageObject) && array_key_exists('message_id', $newMessageObject['result'])) {
// Get the message ID
$newMessageId=$newMessageObject['result']['message_id'];
// Create new campaign
$newCampaign = $sender->createCampaign($newMessageId);
// Parse the result
$newCampaignObject = Json::decode($newCampaign);
if (array_key_exists('result', $newCampaignObject) && array_key_exists('campaign_id', $newCampaignObject['result'])) {
$newCampaignId = $newCampaignObject['result']['campaign_id'];
$schedule = new TriggerSchedule();
$schedule->sended=1;
$schedule->checked=0;
$schedule->message_id=$newMessageId;
$schedule->message=$template->getTemplate();
$schedule->email=$email;
$schedule->time=$time_now->format('Y-m-d H:i:s');
$schedule->date_create=$time_now->format('Y-m-d H:i:s');
$schedule->list_id=$newListId;
$schedule->campaign_id=$newCampaignId;
if (!$schedule->save()) {
echo 'Письмо не было отправлено';
}
}
}
}
}
}
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160217_095148_create_school_lessons_image extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql')
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
// Структура таблицы `school_lessons_image`
$this->createTable('school_lessons_image', [
'id' => Schema::TYPE_PK,
'filename' => Schema::TYPE_STRING . '(50) NOT NULL',
'lesson_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
], $tableOptions);
$this->createIndex('FK_school_lessons_image_lessons', 'school_lessons_image', 'lesson_id');
}
public function safeDown()
{
$this->dropTable('school_lessons_image');
}
}
<?php
use yii\db\Migration;
class m160217_145619_add_subject_column_to_template extends Migration
{
public function up()
{
$this->addColumn(
'message_template',
'subject',
$this->string(255)->notNull()
);
}
public function down()
{
$this->dropColumn(
'message_template',
'subject'
);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment