/** * Factory method using an instance if {@link mlang_stash} as a data source * * @param mlang_stash $stash * @param stdClass $owner owner user data * @return local_amos_stash new instance */ public static function instance_from_mlang_stash(mlang_stash $stash, stdClass $owner) { if ($stash->ownerid != $owner->id) { throw new coding_exception('Stash owner mismatch'); } $new = new local_amos_stash(); $new->id = $stash->id; $new->name = $stash->name; $new->timecreated = $stash->timecreated; $stage = new mlang_stage(); $stash->apply($stage); list($new->strings, $new->languages, $new->components) = mlang_stage::analyze($stage); $stage->clear(); unset($stage); $new->components = explode('/', trim($new->components, '/')); $new->languages = explode('/', trim($new->languages, '/')); $new->owner = $owner; if ($stash->hash === 'xxxxautosaveuser' . $new->owner->id) { $new->isautosave = true; } else { $new->isautosave = false; } return $new; }