40 lines
1004 B
PHP
40 lines
1004 B
PHP
<?php
|
|
namespace app\models;
|
|
|
|
use yii\base\BaseObject;
|
|
|
|
/**
|
|
* Class ProjectsPartner
|
|
* @package app\models
|
|
* @property $id
|
|
* @property $project_id
|
|
* @property $partner_id
|
|
* @property \app\models\Partner $partner
|
|
*/
|
|
class ProjectsPartner extends _Base {
|
|
|
|
public function getPartner() {
|
|
return $this->hasOne(\app\models\register\Partner::class, ['id' => 'partner_id']);
|
|
}
|
|
public static function updateRecords($ids, $data) {
|
|
|
|
$related = self::find()->where([$data[1] => $data[2]])->all();
|
|
$remain = [];
|
|
foreach ($related as $cto) {
|
|
if(in_array($cto->id, $ids)) {
|
|
$remain[] = $cto->id;
|
|
} else {
|
|
$cto->delete();
|
|
}
|
|
}
|
|
foreach ($ids as $id) {
|
|
if(!in_array($id, $remain)) {
|
|
$newCto = new self();
|
|
$newCto->{$data[1]} = $data[2];
|
|
$newCto->{$data[0]} = $id;
|
|
$newCto->save();
|
|
}
|
|
}
|
|
}
|
|
}
|