<?php
//getting the tv object
$tvToOperateWith = $modx->getObject('modTemplateVar', $TVid) or die('could not get an object');
// removing file which is pointed by the tv
// trying to get media source parameters
$mediaSourceOfThisTv = $tvToOperateWith->getSource(); //is object, http://api.modx.com/revolution/2.2/db_core_model_modx_modtemplatevar.class.html#\modTemplateVar
$propertiesOfMS = $mediaSourceOfThisTv->getPropertyList(); //is array
$basePathMS = $propertiesOfMS['basePath'];
$basePath = $mediaSourceOfThisTv->getOption('base_path');
$pathToFileToBeRemoved = $basePath . $basePathMS . $tvToOperateWith->getValue($resID); //getting the value of tv which belongs to resource with ID == $resID
$modx->getService('fileHandler','modFileHandler');
$fileToBeRemoved = $modx->fileHandler->make($pathToFileToBeRemoved);
if (!is_object($fileToBeRemoved) || !($fileToBeRemoved instanceof modFile)) die('Not a file!');
if (!$fileToBeRemoved->remove()) {
die('Could not remove file.');
}
// file removed successfully, cleaning the TV
$tvToOperateWith->setValue($resID, '');
$tvToOperateWith->save();
return $pathToFileToBeRemoved;
$mediaSourceOfThisTv = $tvToOperateWith->getSource(); $propertiesOfMS = $mediaSourceOfThisTv->getPropertyList(); $basePathMS = $propertiesOfMS['basePath'];
$tvValue = $tv->getValue($resourceId); $source = $tv->getSource(); $finalPath = $source->getBasePath().'/'.ltrim($tvValue,'/');
$source->getBasePath()
gettype($source->getBasePath())
method_exists($source->getBasePath())
is_subclass_of($source, 'modFileMediaSources'); //returns true method_exists($source, 'getBases'); //returns true
$source->getBases();
[2012-04-18 07:14:09] (ERROR @ ...core/model/modx/sources/modfilemediasource.class.php : 39) PHP warning: Missing argument 1 for modFileMediaSource::getBases(), called in ...core/cache/includes/elements/modsnippet/44.include.cache.php on line 17 and defined
$path = $this->fileHandler->sanitizePath($path)
$source->initialize();
// before
$source->getBases('');
// and others $source->gets
$swingMS['crociere_listview_img'] = $modx->newObject('sources.modMediaSource');
$swingMS['crociere_listview_img']->fromArray(array(
'name' => 'Crociere ListView Path',
'description' => '',
'class_key' => 'sources.modFileMediaSource',
'properties'=>array('
a:3:{s:8:\"basePath\";
a:6:{s:4:\"name\";s:8:\"basePath\";s:4:\"desc\";s:23:\"prop_file.basePath_desc\";s:4:\"type\";s:9:\"textfield\";s:7:\"options\";
a:0:{}s:5:\"value\";s:57:\"assets/components/swingtime/images/crociere_listview_img/\";s:7:\"lexicon\";s:11:\"core:source\";}s:7:\"baseUrl\";
a:6:{s:4:\"name\";s:7:\"baseUrl\";s:4:\"desc\";s:22:\"prop_file.baseUrl_desc\";s:4:\"type\";s:9:\"textfield\";s:7:\"options\";
a:0:{}s:5:\"value\";s:57:\"assets/components/swingtime/images/crociere_listview_img/\";s:7:\"lexicon\";s:11:\"core:source\";}i:9;
a:6:{s:4:\"name\";i:9;s:4:\"desc\";s:0:\"\";s:4:\"type\";s:9:\"textfield\";s:7:\"options\";
a:0:{}s:5:\"value\";
a:9:{s:4:\"name\";N;s:4:\"desc\";s:0:\"\";s:5:\"xtype\";s:9:\"textfield\";s:7:\"options\";
a:0:{}s:5:\"value\";N;s:7:\"lexicon\";s:0:\"\";s:10:\"overridden\";i:2;s:10:\"desc_trans\";s:0:\"\";s:4:\"menu\";N;}s:7:\"lexicon\";N;}}')
),'',true);