public findByResource ( string $resource_type, string $resource_id, $internal_type = null ) : |
||
$resource_type | string | |
$resource_id | string | |
return |
public function findByResource($resource_type, $resource_id, $internal_type = null)
{
$this->lock($resource_type, $resource_id);
if (is_null($internal_type)) {
$internal_type = 'OEModule\\PASAPI\\resources\\' . $resource_type;
}
$record = $this->findByAttributes(array('resource_type' => $resource_type, 'resource_id' => $resource_id));
if (!$record) {
$record = new static();
$record->resource_type = $resource_type;
$record->resource_id = $resource_id;
// assuming all models are in the root namespace at this point
$record->internal_type = '\\' . $internal_type;
}
return $record;
}
/** * @return PasApiAssignment */ public function getAssignment() { if (!$this->assignment && $this->id) { $finder = new PasApiAssignment(); $this->assignment = $finder->findByResource(static::$resource_type, $this->id, static::$model_class); } return $this->assignment; }