FOF30\Model\DataModel::getAssetName PHP Method

getAssetName() public method

The default name is in the form table_name.id where id is the value of the primary key of the table.
public getAssetName ( ) : string
return string
    public function getAssetName()
    {
        $k = $this->getKeyName();
        // If there is no assetKey defined, stop here, or we'll get a wrong name
        if (!$this->_assetKey || !$this->{$k}) {
            throw new NoAssetKey();
        }
        return $this->_assetKey . '.' . (int) $this->{$k};
    }

Usage Example

コード例 #1
0
ファイル: Assets.php プロジェクト: Joal01/fof
 public function onBeforeDelete(DataModel &$model, $oid)
 {
     if (!$model->isAssetsTracked()) {
         return true;
     }
     $k = $model->getKeyName();
     // If the table is not loaded, let's try to load it with the id
     if (!$model->{$k}) {
         $model->load($oid);
     }
     // If I have an invalid assetName I have to stop
     $name = $model->getAssetName();
     // Do NOT touch JTable here -- we are loading the core asset table which is a JTable, not a FOF Table
     $asset = \JTable::getInstance('Asset');
     if ($asset->loadByName($name)) {
         // Since we are using JTable, there is no way to mock it and test for failures :(
         // @codeCoverageIgnoreStart
         if (!$asset->delete()) {
             throw new \Exception($asset->getError());
         }
         // @codeCoverageIgnoreEnd
     }
     return true;
 }