File uid in FAL file upload field hook - typo3

I've extended ExtendedFileUtilityProcessDataHookInterface and created a hook for FAL file upload field.
class tx_bibusdocuments_fileUploadHook implements TYPO3\CMS\Core\Utility\File\ExtendedFileUtilityProcessDataHookInterface {
public function processData_postProcessAction($action, array $cmdArr, array $result, \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility $parentObject){}
}
When I print the "$result" array, I got an array like this;
Array
(
[0] => Array
(
[0] => TYPO3\CMS\Core\Resource\File Object
(
[metaDataLoaded:protected] =>
[metaDataProperties:protected] => Array
(
)
[indexingInProgress:protected] =>
[updatedProperties:protected] => Array
(
)
[indexerService:protected] =>
[properties:protected] => Array
(
[size] => 198218
[modification_date] => 1408449118
[creation_date] => 1408449118
[mime_type] => application/pdf
[name] => HomeTest.pdf
[identifier] => /user_upload/test.pdf
[identifier_hash] => 2bc8d0c4ed9f8a87fb9913af5dcd3977e0102027
[storage] => 1
[folder_hash] => e32a309fabc28dd85f053b65c5bd0da99860eb02
[type] => 5
[sha1] => 8a46595222d30c9cb4bcc48a4901d3e0f05e25ad
[extension] => pdf
[missing] => 0
[uid] => 139856
)
)
)
)
How can I get uid and name of the file from this $result array?

We can iterate the result array like this way;
public function processData_postProcessAction($action, array $cmdArr, array $result, \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility $parentObject){
$files = array_pop( $result );
if ( !is_array( $files ) ) {
return;
}
foreach ( $files as $file ) {
$fileUid .= $file->getUid(); // Uid of the file
$fileName .= $file->getName(); // Name of the file
}
}

Related

yii2 mongodb - how to find element in collection subarray

Array from collection looks like this.
$result = $collection->find();
Array
(
[0] => Array
(
[_id] => MongoDB\BSON\ObjectId Object
(
[oid] => 5c52b90454851c44aa2987e2
)
[name] => Array
(
[date] => 2019-01-31 10:59:48
[value] => DESKTOP-TODTF5E
)
[network_addresses] => Array
(
[0] => Array
(
[ip_1] => 12.21.134
[ip_2] => 50
[mac] => xx:xx:xx:xx:xx:xx
)
[1] => Array
(
[ip_1] => 192.168.0
[ip_2] => 2
[mac] => yy:yy:yy:yy:yy:yy
)
)
)
)
I can find if some mac exist in specific row of sub array like this:
$result = $collection->find(["network_addresses.0.mac" =>
"xx:xx:xx:xx:xx:xx"]);
But I need to check if certain mac exists in any row of subarray, so instead of row index 0 I need to put some asterix or something.
How to do that ?
$query = (new Query)->select(["name"])
->from(['db_name','collection_name'])
->where(["network_addresses" => [ '$elemMatch' =>['mac' => "xx:xx:xx:xx:xx:xx"]]]);
$results = $query->all();

how to remove <script> tag?

I want to remove a script tag and tried this code:
enter image description here
function mythemename_js_alter(&$javascript,AttachedAssetsInterface $assets){
unset($javascript['/public:/languages/en_QSlF4vrel7qmkEG5lSj1NjAbhdL7GHx1GMl9HN4CFmo.js']);
}
But the script tag is still here.
1.print_r($javascript);
2.find the js location;
3.unset($javascript['path of what you found']);**
For example :
The script src is /public:/languages/en_QSlF4vrel7qmkEG5lSj1NjAbhdL7GHx1GMl9HN4CFmo.js
I found this :
[core/modules/locale/locale.translation.js] =>
Array ( [group] => -100 [type] => external
[data] =>/public://languages/en_QSlF4vrel7qmkEG5lSj1NjAbhdL7GHx1GMl9HN4CFmo.js
[version] => -1
[minified] =>
[weight] => -17.996
[cache] => 1
[preprocess] => 1
[attributes] => Array ( )
[browsers] => Array ( )
[scope] => footer )
Then use unset($javascript['core/modules/locale/locale.translation.js']);

Fetch protected data from object zend

I have response and I want to fetch referenceId from it, the response is
Application_Model_User Object
(
[_data:protected] => Array
(
[id] => 2
[email] => test#gmail.com
[password] => ef1dca60798e10a51e3b6201ae7c40fbe2a10887
[salt] => 87fc83906190d1e29b60c5813065af068e16459d
[name] => test
[creationDate] => 2011-07-05
[lastTimeStamp] => 2016-06-03 09:13:53
[enabled] => 1
[loginHash] =>
[employeeNumber] => 0007
[userphoneNumber] => +546546546545
[jobTitle] => Business Manager
)
[_references:protected] => Array
(
[role] => Array
(
[referenceClass] => Application_Model_Role
[referenceId] => 4
[mapperClass] => Application_Model_RoleMapper
[mapper] =>
)
[organisation] => Array
(
[referenceClass] => Application_Model_Organisation
[referenceId] => 1
[mapperClass] => Application_Model_OrganisationMapper
[mapper] =>
)
)
)
How can I fetch ?
In .phtml file in ajax after
success: function(response){
var data = jQuery.parseJSON(response);
for (var i in data)
{
var referenceId = data[i]['referenceId'];
}
}
You can use a getter. You can create a method to return the referenceId.

Illuminate returns results in JSON - why?

I'm using Illuminate to access my database
<body>
<?php
$edges = Edge::all();
foreach ($edges as $key => $value) {
print $value;
}
?>
</body>
browser returns:
{"childID":"A","parentID":"C","updated_at":null,"created_at":null}{"childID":"B","parentID":"E","updated_at":null,"created_at":null}{"childID":"C","parentID":"D","updated_at":null,"created_at":null}{"childID":"C","parentID":"F","updated_at":null,"created_at":null}{"childID":"Y","parentID":"Z","updated_at":"2014-08-07 10:26:54","created_at":"2014-08-07 10:26:54"}
What's odd or unexpected for me at least is that my results are returned in JSON. If you could
shine some light on this, i.e. why this might be, or the reason is...I'd be grateful.
If I dump the results in the browser with:
<?php
print '<pre>';print_r($edges);
?>
produces:
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => Edge Object
(
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[original:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[fillable:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
[1] => Edge Object
(...)
...
)
In terms of the front-end results - I'm really only interested in the:
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
part of the object; only NOT in JSON; in plain text.

PHP- PDO get metadata from database

I want to get the metadata from a database with a table 'friends'
id name
1 Herbert
2 LG
3 Levins
Here is the code I was trying to get the data.
<?php
$dsn = 'mysql:host=localhost;dbname=postgre';
$username = 'root';
$password = '';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$db = new PDO($dsn, $username, $password, $options);
$stmt = $db->query("SELECT * FROM friends");
$cnt_columns = $stmt->columnCount();
for($i = 0; $i < $cnt_columns; $i++) {
$metadata = $stmt->getColumnMeta($i);
var_dump($metadata);
}
?>
When I execute the code:, it displays
array
'native_type' => string 'LONG' (length=4)
'pdo_type' => int 2
'flags' =>
array
empty
'table' => string 'friends' (length=7)
'name' => string 'id' (length=2)
'len' => int 11
'precision' => int 0
array
'native_type' => string 'VAR_STRING' (length=10)
'pdo_type' => int 2
'flags' =>
array
empty
'table' => string 'friends' (length=7)
'name' => string 'name' (length=4)
'len' => int 60
'precision' => int 0
Till here, it is giving the correct count of rows, but I need the result to display as it looks in the my database like
Output:
id name
1 Hebert
2 LG
3 Levins
How could I get all my fields as it is like a table in my database using metadata.
Use columnCount.
$stmt = $db->query("SELECT * FROM friends");
$cnt_columns = $stmt->columnCount();
for($i = 0; $i < $cnt_columns; $i++) {
$metadata = $stmt->getColumnMeta($i);
var_dump($metadata);
}
By the way, getColumnMeta is experimental. Not recommended to use. Why do you want to use it?
For the desired output, you don't need metadata. Just loop through the results:
$sql = "SELECT * FROM friends";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
// field names
if(count($result) > 0) {
foreach($result[0] as $k => $v) {
if(!is_int($k)) {
echo $k . "\t";
}
}
}
echo PHP_EOL;
// data
foreach ($result as $row) {
foreach($row as $k => $v) {
if(!is_int($k)) {
echo $row[$k] . "\t";
}
}
echo PHP_EOL;
}