<?php 
namespace modules\activities\components;
use Yii;
use modules\activities\models\Activities;
/**
 * Activities Update Functions
 */
class Upgrade
{
    /**
     * <b>Activities</b>
     * Save all Jobs to trigger any model events or updates
     */
    public static function SaveAllJobs(){
        $activities = Activities::find();
        foreach($activities->each() as $job){
            $job->save(false);
        }
    }
    /**
     * <b>Activities</b>
     * Link all existing Uploads to Activities via Lookuptablebe
     */
    public static function CreateUploadLinks(){
        $activities = Activities::find();
        foreach($activities->each() as $job){
            $uploads = \backend\models\Uploadsbe::find()->where(['actid' => $job->id])->all();
            foreach($uploads as $upload){
                $lookup = New \backend\models\Lookuptablebe();
                $lookup->source = 'Activities';
                $lookup->sourceid = $job->id;
                $lookup->related = 'Uploads';
                $lookup->relatedid = $upload->id;
                $lookup->save();
            }
        }
    }
}