Your IP : 216.73.216.48
<?php
namespace app\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use vendor\custom\MCrypt;
class FtpConnections extends \yii\db\ActiveRecord {
public static function tableName() {
return '{{%ftp_connections}}';
}
public function behaviors() {
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'date_added',
'updatedAtAttribute' => NULL,
],
];
}
public function rules() {
return [
[['member_id', 'type', 'host', 'port', 'username', 'password'], 'required'],
[['member_id'], 'integer'],
[['host', 'username', 'password', 'dir'], 'string', 'max' => 255],
[['port'], 'string', 'max' => 5]
];
}
public function attributeLabels() {
return [
'connection_id' => Yii::t('app', 'ID на връзката'),
'member_id' => Yii::t('app', 'ID на потребителя'),
'type' => Yii::t('app', 'Вид'),
'host' => Yii::t('app', 'Хост'),
'username' => Yii::t('app', 'Потребител'),
'password' => Yii::t('app', 'Парола'),
'port' => Yii::t('app', 'Порт'),
'dir' => Yii::t('app', 'Директория'),
];
}
public function addConnection($memberID, $type, $host, $username, $password, $port, $dir) {
$this->member_id = $memberID;
$this->type = $type;
$this->host = $host;
$this->username = $username;
$this->password = MCrypt::mcEncrypt($password, Yii::$app->params['mcrypt']['encryption_key']);
$this->port = $port;
$this->dir = $dir;
return $this->save();
}
public function editConnection($serverInfo) {
$serverInfo->password = MCrypt::mcEncrypt($serverInfo->password, Yii::$app->params['mcrypt']['encryption_key']);
return $serverInfo->save();
}
public function deleteConnection($serverInfo) {
return $serverInfo->delete();
}
public function getMemberConnections($memberID) {
if ($memberID) {
$connections = $this->find()->where(['member_id' => $memberID]);
return $connections;
}
}
public function getFtpConnection($connectionID) {
return $this->findOne($connectionID);
}
public function getLatestFtpConnectionsCount() {
$ftpConnectionsCount = $this->find()->where('`date_added` > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 10 DAY))')->count();
return $ftpConnectionsCount;
}
public function deleteFtpConnection($connectionInfo) {
return $connectionInfo->delete();
}
public function getMember() {
return $this->hasOne(Members::className(), ['member_id' => 'member_id']);
}
}