OEModule\PASAPI\models\PasApiAssignment::findByResource PHP Méthode

findByResource() public méthode

Find or create association using resource details and lock.
public findByResource ( string $resource_type, string $resource_id, $internal_type = null ) : PasApiAssignment
$resource_type string
$resource_id string
Résultat PasApiAssignment
    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;
    }

Usage Example

Exemple #1
0
 /**
  * @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;
 }