mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
This is a combination of 33 commits.
- Squashed Pull request #1730 - Squashed Pull request #1741 - Squashed Pull request #1742 - Squash merge branch 4.0 - Squashed Pull request #1744 - Squashed Pull request #1746 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed Pull request #1758 - Avoid using imagine/imagine alias as it is causing install issues - Squashed merge branch 4.0 - Squashed Pull request #1763 - Squashed merge branch 4.0 - Squash of 6 commits - Squashed merge branch 4.0 - This is a combination of 2 commits. - Squashed Pull request #1775 - Squashed Pull request #1777 - Squashed Pull request #1779 - Squashed Pull request #1780 - Squashed Pull request #1782 - Adds a Pull request template - Squased Pull request #1783 - Squash Pull request #1786 - Squashed Pull request #1796 - Squashed merge branch 4.0 - Squash Pull request #1791 - Squashed merge branch 4.0 - Squashed Pull request #1808 - Squashed Pull request #1811 - Squashed Pull request #1809
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
@@ -20,11 +20,8 @@ use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\StatusChangedEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaTokens;
|
||||
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
|
||||
use Alchemy\Phrasea\Filesystem\FilesystemService;
|
||||
use Alchemy\Phrasea\Media\ArrayTechnicalDataSet;
|
||||
use Alchemy\Phrasea\Media\FloatTechnicalData;
|
||||
use Alchemy\Phrasea\Media\IntegerTechnicalData;
|
||||
use Alchemy\Phrasea\Media\StringTechnicalData;
|
||||
use Alchemy\Phrasea\Media\TechnicalData;
|
||||
use Alchemy\Phrasea\Media\TechnicalDataSet;
|
||||
use Alchemy\Phrasea\Metadata\Tag\TfBasename;
|
||||
@@ -42,7 +39,6 @@ use MediaVorus\MediaVorus;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
|
||||
|
||||
|
||||
class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
{
|
||||
const CACHE_ORIGINAL_NAME = 'originalname';
|
||||
@@ -52,7 +48,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
const CACHE_SHA256 = 'sha256';
|
||||
const CACHE_SUBDEFS = 'subdefs';
|
||||
const CACHE_GROUPING = 'grouping';
|
||||
const CACHE_STATUS = 'status';
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
@@ -82,6 +77,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
private $collection_id;
|
||||
private $mime;
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $status;
|
||||
private $subdefs;
|
||||
private $type;
|
||||
@@ -92,7 +91,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
private $created;
|
||||
/** @var string */
|
||||
private $original_name;
|
||||
/** @var TechnicalDataSet */
|
||||
/** @var TechnicalDataSet|null */
|
||||
private $technical_data;
|
||||
/** @var string */
|
||||
private $uuid;
|
||||
@@ -110,7 +109,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->reference = RecordReference::createFromDataboxIdAndRecordId($sbas_id, $record_id);
|
||||
$this->number = (int) $number;
|
||||
$this->number = (int)$number;
|
||||
|
||||
if ($load) {
|
||||
$this->load();
|
||||
@@ -141,6 +140,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$this->created = $record->getCreated();
|
||||
$this->base_id = $record->getBaseId();
|
||||
$this->collection_id = $record->getCollectionId();
|
||||
$this->status = $record->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +201,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public function setNumber($number)
|
||||
{
|
||||
$this->number = (int) $number;
|
||||
$this->number = (int)$number;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -370,8 +370,19 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
* Return record collection
|
||||
*
|
||||
* @return \collection
|
||||
* @deprecated use {@link self::getCollection} instead.
|
||||
*/
|
||||
public function get_collection()
|
||||
{
|
||||
return $this->getCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return collection to which the record belongs to.
|
||||
*
|
||||
* @return \collection
|
||||
*/
|
||||
public function getCollection()
|
||||
{
|
||||
return \collection::getByCollectionId($this->app, $this->getDatabox(), $this->collection_id);
|
||||
}
|
||||
@@ -460,7 +471,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public function move_to_collection(collection $collection, appbox $appbox)
|
||||
{
|
||||
if ($this->get_collection()->get_base_id() === $collection->get_base_id()) {
|
||||
if ($this->getCollection()->get_base_id() === $collection->get_base_id()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -517,54 +528,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->sha256;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_status()
|
||||
{
|
||||
if (!$this->status) {
|
||||
$this->status = $this->retrieve_status();
|
||||
}
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
protected function retrieve_status()
|
||||
{
|
||||
try {
|
||||
$data = $this->get_data_from_cache(self::CACHE_STATUS);
|
||||
} catch (Exception $e) {
|
||||
$data = false;
|
||||
}
|
||||
|
||||
if (false !== $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$status = $this->getDataboxConnection()->fetchColumn(
|
||||
'SELECT BIN(status) as status FROM record WHERE record_id = :record_id',
|
||||
[':record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
if (false === $status) {
|
||||
throw new Exception('status not found');
|
||||
}
|
||||
|
||||
$status = str_pad($status, 32, '0', STR_PAD_LEFT);
|
||||
|
||||
$this->set_data_to_cache($status, self::CACHE_STATUS);
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function has_subdef($name)
|
||||
{
|
||||
return in_array($name, $this->get_available_subdefs());
|
||||
return in_array($name, $this->get_available_subdefs(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,17 +545,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->subdefs[$name];
|
||||
}
|
||||
|
||||
if (!in_array($name, $this->get_available_subdefs())) {
|
||||
if (!in_array($name, $this->get_available_subdefs(), false)) {
|
||||
throw new Exception_Media_SubdefNotFound(sprintf("subdef `%s` not found", $name));
|
||||
}
|
||||
|
||||
if (!$this->subdefs) {
|
||||
$this->subdefs = [];
|
||||
}
|
||||
$subdefs = $this->getMediaSubdefRepository()->findOneByRecordIdAndName($this->getRecordId(), $name);
|
||||
|
||||
$substitute = ($name !== 'document');
|
||||
|
||||
return $this->subdefs[$name] = new media_subdef($this->app, $this, $name, $substitute);
|
||||
return $subdefs ?: new media_subdef($this->app, $this, $name, ($name !== 'document'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,15 +569,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
if (isset($availableSubdefs['document'])) {
|
||||
|
||||
$mime_ok = !$mimes || in_array($availableSubdefs['document']->get_mime(), (array) $mimes);
|
||||
$devices_ok = !$devices || array_intersect($availableSubdefs['document']->getDevices(), (array) $devices);
|
||||
$mime_ok = !$mimes || in_array($availableSubdefs['document']->get_mime(), (array)$mimes, false);
|
||||
$devices_ok = !$devices || array_intersect($availableSubdefs['document']->getDevices(), (array)$devices);
|
||||
|
||||
if ($mime_ok && $devices_ok) {
|
||||
$subdefs['document'] = $availableSubdefs['document'];
|
||||
}
|
||||
}
|
||||
|
||||
$searchDevices = array_merge((array) $devices, (array) databox_subdef::DEVICE_ALL);
|
||||
$searchDevices = array_merge((array)$devices, (array)databox_subdef::DEVICE_ALL);
|
||||
|
||||
$type = $this->isStory() ? 'image' : $this->getType();
|
||||
|
||||
@@ -641,7 +603,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($mimes && !in_array($subdef->get_mime(), (array) $mimes)) {
|
||||
if ($mimes && !in_array($subdef->get_mime(), (array)$mimes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -656,13 +618,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public function get_subdefs()
|
||||
{
|
||||
if (!$this->subdefs) {
|
||||
$this->subdefs = [];
|
||||
if (null !== $this->subdefs) {
|
||||
return $this->subdefs;
|
||||
}
|
||||
|
||||
$subdefs = $this->get_available_subdefs();
|
||||
foreach ($subdefs as $name) {
|
||||
$this->get_subdef($name);
|
||||
$this->subdefs = [];
|
||||
|
||||
foreach ($this->getMediaSubdefRepository()->findByRecordIdsAndNames([$this->getRecordId()]) as $subdef) {
|
||||
$this->subdefs[$subdef->get_name()] = $subdef;
|
||||
}
|
||||
|
||||
foreach (['preview', 'thumbnail'] as $name) {
|
||||
if (!isset($this->subdefs[$name])) {
|
||||
$this->subdefs[$name] = new media_subdef($this->app, $this, $name, true, []);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->subdefs;
|
||||
@@ -673,6 +642,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
protected function get_available_subdefs()
|
||||
{
|
||||
if (null !== $this->subdefs) {
|
||||
return array_keys($this->subdefs);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $this->get_data_from_cache(self::CACHE_SUBDEFS);
|
||||
} catch (\Exception $e) {
|
||||
@@ -683,18 +656,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
$rs = $this->getDataboxConnection()->fetchAll(
|
||||
'SELECT name FROM subdef WHERE record_id = :record_id',
|
||||
['record_id' => $this->getRecordId()]
|
||||
);
|
||||
$subdefs = array_keys($this->get_subdefs());
|
||||
|
||||
$subdefs = ['preview', 'thumbnail'];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$subdefs[] = $row['name'];
|
||||
}
|
||||
|
||||
$subdefs = array_unique($subdefs);
|
||||
$this->set_data_to_cache($subdefs, self::CACHE_SUBDEFS);
|
||||
|
||||
return $subdefs;
|
||||
@@ -716,13 +679,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public function get_technical_infos($data = '')
|
||||
{
|
||||
if (!$this->technical_data && !$this->mapTechnicalDataFromCache()) {
|
||||
$this->technical_data = [];
|
||||
$rs = $this->fetchTechnicalDataFromDb();
|
||||
if (null === $this->technical_data) {
|
||||
$sets = $this->app['service.technical_data']->fetchRecordsTechnicalData([$this]);
|
||||
|
||||
$this->mapTechnicalDataFromDb($rs);
|
||||
|
||||
$this->set_data_to_cache($this->technical_data, self::CACHE_TECHNICAL_DATA);
|
||||
$this->setTechnicalDataSet(reset($sets));
|
||||
}
|
||||
|
||||
if ($data) {
|
||||
@@ -736,12 +696,21 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->technical_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TechnicalDataSet $dataSet
|
||||
* @internal
|
||||
*/
|
||||
public function setTechnicalDataSet(TechnicalDataSet $dataSet)
|
||||
{
|
||||
$this->technical_data = $dataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return caption_record
|
||||
*/
|
||||
public function get_caption()
|
||||
{
|
||||
return new caption_record($this->app, $this, $this->getDatabox());
|
||||
return new caption_record($this->app, $this);
|
||||
}
|
||||
|
||||
public function getCaption(array $fields = null)
|
||||
@@ -758,7 +727,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$collection = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$values = array_map(function(caption_Field_Value $fieldValue) {
|
||||
$values = array_map(function (caption_Field_Value $fieldValue) {
|
||||
return $fieldValue->getValue();
|
||||
}, $field->get_values());
|
||||
|
||||
@@ -857,7 +826,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
}
|
||||
|
||||
if (count($fields_to_retrieve) > 0) {
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine);
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve);
|
||||
$titles = [];
|
||||
foreach ($retrieved_fields as $value) {
|
||||
foreach ($value['values'] as $v) {
|
||||
@@ -904,6 +873,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated use {@link self::getId} instead.
|
||||
*/
|
||||
public function get_serialize_key()
|
||||
{
|
||||
@@ -1066,16 +1036,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
}
|
||||
|
||||
$record = $this;
|
||||
$wanted_subdefs = array_map(function(databox_subdef $subDef) {
|
||||
$wanted_subdefs = array_map(function (databox_subdef $subDef) {
|
||||
return $subDef->get_name();
|
||||
}, array_filter($subDefDefinitions, function(databox_subdef $subDef) use ($record) {
|
||||
}, array_filter(iterator_to_array($subDefDefinitions), function (databox_subdef $subDef) use ($record) {
|
||||
return !$record->has_subdef($subDef->get_name());
|
||||
}));
|
||||
|
||||
|
||||
$missing_subdefs = array_map(function(media_subdef $subDef) {
|
||||
$missing_subdefs = array_map(function (media_subdef $subDef) {
|
||||
return $subDef->get_name();
|
||||
}, array_filter($this->get_subdefs(), function(media_subdef $subdef) {
|
||||
}, array_filter($this->get_subdefs(), function (media_subdef $subdef) {
|
||||
return !$subdef->is_physically_present();
|
||||
}));
|
||||
|
||||
@@ -1096,26 +1066,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @return record_adapter
|
||||
*/
|
||||
public function set_binary_status($status)
|
||||
{
|
||||
$connection = $this->getDataboxConnection();
|
||||
|
||||
$connection->executeUpdate(
|
||||
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id= :record_id',
|
||||
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||
|
||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function dispatch($eventName, RecordEvent $event)
|
||||
{
|
||||
$this->app['dispatcher']->dispatch($eventName, $event);
|
||||
@@ -1255,12 +1205,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
}
|
||||
|
||||
$connection = $this->getDataboxConnection();
|
||||
$sql = 'DELETE FROM technical_datas WHERE record_id = :record_id';
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':record_id' => $this->getRecordId()]);
|
||||
$stmt->closeCursor();
|
||||
$connection->executeUpdate('DELETE FROM technical_datas WHERE record_id = :record_id', [
|
||||
':record_id' => $this->getRecordId(),
|
||||
]);
|
||||
|
||||
$sqlValues = [];
|
||||
|
||||
foreach ($document->readTechnicalDatas($mediavorus) as $name => $value) {
|
||||
if (is_null($value)) {
|
||||
continue;
|
||||
@@ -1271,21 +1221,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$value = 0;
|
||||
}
|
||||
}
|
||||
$sqlValues[] = join(',', array(
|
||||
'null',
|
||||
$connection->quote($this->getRecordId()),
|
||||
$connection->quote($name),
|
||||
$connection->quote($value),
|
||||
));
|
||||
$sqlValues[] = [$this->getRecordId(), $name, $value];
|
||||
}
|
||||
$sql = "INSERT INTO technical_datas (id, record_id, name, value)"
|
||||
. " VALUES (" . join('),(', $sqlValues) . ")";
|
||||
;
|
||||
$stmt = $connection->prepare($sql);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->closeCursor();
|
||||
if ($sqlValues) {
|
||||
$connection->transactional(function (Connection $connection) use ($sqlValues) {
|
||||
$statement = $connection->prepare('INSERT INTO technical_datas (record_id, name, value) VALUES (?, ?, ?)');
|
||||
array_walk($sqlValues, [$statement, 'execute']);
|
||||
});
|
||||
}
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_TECHNICAL_DATA);
|
||||
|
||||
@@ -1357,8 +1301,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
$ftodel = [];
|
||||
foreach ($this->get_subdefs() as $subdef) {
|
||||
if (!$subdef->is_physically_present())
|
||||
if (!$subdef->is_physically_present()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($subdef->get_name() === 'thumbnail') {
|
||||
$this->app['phraseanet.thumb-symlinker']->unlink($subdef->getRealPath());
|
||||
@@ -1366,11 +1311,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
$ftodel[] = $subdef->getRealPath();
|
||||
$watermark = $subdef->getWatermarkRealPath();
|
||||
if (file_exists($watermark))
|
||||
if (file_exists($watermark)) {
|
||||
$ftodel[] = $watermark;
|
||||
}
|
||||
$stamp = $subdef->getStampRealPath();
|
||||
if (file_exists($stamp))
|
||||
if (file_exists($stamp)) {
|
||||
$ftodel[] = $stamp;
|
||||
}
|
||||
}
|
||||
|
||||
$origcoll = $this->collection_id;
|
||||
@@ -1500,16 +1447,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
public function delete_data_from_cache($option = null)
|
||||
{
|
||||
switch ($option) {
|
||||
case self::CACHE_STATUS:
|
||||
$this->status = null;
|
||||
break;
|
||||
switch ($option)
|
||||
{
|
||||
case self::CACHE_SUBDEFS:
|
||||
$this->subdefs = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$databox = $this->getDatabox();
|
||||
|
||||
$databox->delete_data_from_cache($this->get_cache_key($option));
|
||||
@@ -1540,7 +1484,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
/**
|
||||
* @todo de meme avec stories
|
||||
* @return Array
|
||||
* @return \Alchemy\Phrasea\Model\Entities\Basket[]
|
||||
*/
|
||||
public function get_container_baskets(EntityManager $em, User $user)
|
||||
{
|
||||
@@ -1560,8 +1504,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public static function get_records_by_originalname(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10)
|
||||
{
|
||||
$offset_start = (int) ($offset_start < 0 ? 0 : $offset_start);
|
||||
$how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many);
|
||||
$offset_start = (int)($offset_start < 0 ? 0 : $offset_start);
|
||||
$how_many = (int)(($how_many > 20 || $how_many < 1) ? 10 : $how_many);
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT record_id FROM record WHERE originalname = :original_name COLLATE %s LIMIT %d, %d',
|
||||
@@ -1694,7 +1638,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
public function hasChild(\record_adapter $record)
|
||||
{
|
||||
return $this->get_children()->offsetExists($record->get_serialize_key());
|
||||
return $this->getChildren()->offsetExists($record->getId());
|
||||
}
|
||||
|
||||
public function appendChild(\record_adapter $record)
|
||||
@@ -1786,17 +1730,36 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $this->reference->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->set_binary_status($status);
|
||||
$this->getDataboxConnection()->executeUpdate(
|
||||
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id=:record_id',
|
||||
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
||||
);
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||
$this->status = str_pad($status, 32, '0', STR_PAD_LEFT);
|
||||
// modification date is now unknown, delete from cache to reload on another record
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getStatusBitField()
|
||||
{
|
||||
return bindec($this->get_status());
|
||||
return bindec($this->getStatus());
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
@@ -1823,6 +1786,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
'created' => $this->created->format(DATE_ISO8601),
|
||||
'base_id' => $this->base_id,
|
||||
'collection_id' => $this->collection_id,
|
||||
'status' => $this->status,
|
||||
];
|
||||
|
||||
$this->set_data_to_cache($data);
|
||||
@@ -1848,64 +1812,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$this->original_name = $row['originalName'];
|
||||
$this->sha256 = $row['sha256'];
|
||||
$this->mime = $row['mime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function mapTechnicalDataFromCache()
|
||||
{
|
||||
try {
|
||||
$technical_data = $this->get_data_from_cache(self::CACHE_TECHNICAL_DATA);
|
||||
} catch (Exception $e) {
|
||||
$technical_data = false;
|
||||
}
|
||||
|
||||
if (false === $technical_data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->technical_data = $technical_data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|array
|
||||
*/
|
||||
private function fetchTechnicalDataFromDb()
|
||||
{
|
||||
$sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id';
|
||||
|
||||
return $this->getDataboxConnection()
|
||||
->fetchAll($sql, ['record_id' => $this->getRecordId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rows
|
||||
*/
|
||||
private function mapTechnicalDataFromDb(array $rows)
|
||||
{
|
||||
$this->technical_data = new ArrayTechnicalDataSet();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
switch (true) {
|
||||
case ctype_digit($row['value']):
|
||||
$this->technical_data[] = new IntegerTechnicalData($row['name'], $row['value']);
|
||||
break;
|
||||
case preg_match('/[0-9]?\.[0-9]+/', $row['value']):
|
||||
$this->technical_data[] = new FloatTechnicalData($row['name'], $row['value']);
|
||||
break;
|
||||
default:
|
||||
$this->technical_data[] = new StringTechnicalData($row['name'], $row['value']);
|
||||
}
|
||||
}
|
||||
$this->status = str_pad($row['status'], 32, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Connection
|
||||
*/
|
||||
private function getDataboxConnection()
|
||||
protected function getDataboxConnection()
|
||||
{
|
||||
if (null === $this->connection) {
|
||||
$this->connection = $this->getDatabox()->get_connection();
|
||||
@@ -1913,4 +1826,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MediaSubdefRepository
|
||||
*/
|
||||
private function getMediaSubdefRepository()
|
||||
{
|
||||
return $this->app['provider.repo.media_subdef']->getRepositoryForDatabox($this->getDataboxId());
|
||||
}
|
||||
}
|
||||
|
@@ -83,14 +83,13 @@ class record_exportElement extends record_adapter
|
||||
|
||||
$sd = $this->get_subdefs();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->app, $this->get_base_id());
|
||||
|
||||
$subdefgroups = $this->app->findDataboxById($sbas_id)->get_subdef_structure();
|
||||
$sbas_id = phrasea::sbasFromBas($this->app, $this->getBaseId());
|
||||
|
||||
/** @var databox_subdef[] $subdefs */
|
||||
$subdefs = [];
|
||||
|
||||
foreach ($subdefgroups as $subdef_type => $subdefs_obj) {
|
||||
if ($subdef_type == $this->get_type()) {
|
||||
foreach ($this->app->findDataboxById($sbas_id)->get_subdef_structure() as $subdef_type => $subdefs_obj) {
|
||||
if ($subdef_type == $this->getType()) {
|
||||
$subdefs = $subdefs_obj;
|
||||
break;
|
||||
}
|
||||
@@ -102,10 +101,10 @@ class record_exportElement extends record_adapter
|
||||
'thumbnail' => true
|
||||
];
|
||||
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->get_base_id(), 'candwnldhd')) {
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'candwnldhd')) {
|
||||
$go_dl['document'] = true;
|
||||
}
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->get_base_id(), 'candwnldpreview')) {
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'candwnldpreview')) {
|
||||
$go_dl['preview'] = true;
|
||||
}
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->has_hd_grant($this)) {
|
||||
@@ -118,18 +117,18 @@ class record_exportElement extends record_adapter
|
||||
|
||||
$query = $this->app['phraseanet.user-query'];
|
||||
|
||||
$masters = $query->on_base_ids([$this->get_base_id()])
|
||||
$masters = $query->on_base_ids([$this->getBaseId()])
|
||||
->who_have_right(['order_master'])
|
||||
->execute()->get_results();
|
||||
|
||||
$go_cmd = (count($masters) > 0 && $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->get_base_id(), 'cancmd'));
|
||||
$go_cmd = (count($masters) > 0 && $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'cancmd'));
|
||||
|
||||
$orderable['document'] = false;
|
||||
$downloadable['document'] = false;
|
||||
|
||||
if (isset($sd['document']) && is_file($sd['document']->getRealPath())) {
|
||||
if ($go_dl['document'] === true) {
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->is_restricted_download($this->get_base_id())) {
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->is_restricted_download($this->getBaseId())) {
|
||||
$this->remain_hd --;
|
||||
if ($this->remain_hd >= 0) {
|
||||
$localizedLabel = $this->app->trans('document original');
|
||||
@@ -183,7 +182,7 @@ class record_exportElement extends record_adapter
|
||||
if (isset($sd[$name]) && $sd[$name]->is_physically_present()) {
|
||||
if ($class == 'document') {
|
||||
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->is_restricted_download($this->get_base_id())) {
|
||||
if ($this->app->getAclForUser($this->app->getAuthenticatedUser())->is_restricted_download($this->getBaseId())) {
|
||||
$this->remain_hd --;
|
||||
if ($this->remain_hd >= 0)
|
||||
$downloadable[$name] = [
|
||||
|
@@ -10,8 +10,7 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Basket;
|
||||
use Alchemy\Phrasea\Model\Entities\BasketElement;
|
||||
use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Guzzle\Http\Url;
|
||||
@@ -19,69 +18,59 @@ use Guzzle\Http\Url;
|
||||
class record_preview extends record_adapter
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $env;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $total;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mixed content
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mixed content
|
||||
*/
|
||||
protected $train;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
protected $short_history;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
* @var media_adapter
|
||||
*/
|
||||
protected $view_popularity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
* @var media_adapter
|
||||
*/
|
||||
protected $refferer_popularity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
* @var media_adapter
|
||||
*/
|
||||
protected $download_popularity;
|
||||
|
||||
protected $original_item;
|
||||
|
||||
protected $pos;
|
||||
protected$search_engine;
|
||||
protected $searchEngine;
|
||||
protected $query;
|
||||
protected $options;
|
||||
|
||||
@@ -100,8 +89,13 @@ class record_preview extends record_adapter
|
||||
if (null === $search_engine) {
|
||||
throw new \LogicException('Search Engine should be provided');
|
||||
}
|
||||
if (!$options) {
|
||||
$options = new SearchEngineOptions();
|
||||
}
|
||||
$options->setFirstResult($pos);
|
||||
$options->setMaxResults(1);
|
||||
|
||||
$results = $search_engine->query($query, (int) ($pos), 1, $options);
|
||||
$results = $search_engine->query($query, $options);
|
||||
|
||||
if ($results->getResults()->isEmpty()) {
|
||||
throw new Exception('Record introuvable');
|
||||
@@ -124,11 +118,11 @@ class record_preview extends record_adapter
|
||||
if ($pos == 0) {
|
||||
$number = 0;
|
||||
} else {
|
||||
$children = $this->container->get_children();
|
||||
$children = $this->container->getChildren();
|
||||
foreach ($children as $child) {
|
||||
$sbas_id = $child->get_sbas_id();
|
||||
$sbas_id = $child->getDataboxId();
|
||||
$this->original_item = $child;
|
||||
$record_id = $child->get_record_id();
|
||||
$record_id = $child->getRecordId();
|
||||
if ($child->getNumber() == $pos)
|
||||
break;
|
||||
}
|
||||
@@ -141,34 +135,25 @@ class record_preview extends record_adapter
|
||||
$Basket = $app['converter.basket']->convert($contId);
|
||||
$app['acl.basket']->hasAccess($Basket, $app->getAuthenticatedUser());
|
||||
|
||||
/* @var $Basket Basket */
|
||||
$this->container = $Basket;
|
||||
$this->total = $Basket->getElements()->count();
|
||||
$i = 0;
|
||||
$first = true;
|
||||
|
||||
foreach ($Basket->getElements() as $element) {
|
||||
/* @var $element BasketElement */
|
||||
$i ++;
|
||||
if ($first) {
|
||||
if ($element->getOrd() == $pos || $first) {
|
||||
$this->original_item = $element;
|
||||
$sbas_id = $element->getRecord($this->app)->get_sbas_id();
|
||||
$record_id = $element->getRecord($this->app)->get_record_id();
|
||||
$this->name = $Basket->getName();
|
||||
$number = $element->getOrd();
|
||||
}
|
||||
$first = false;
|
||||
|
||||
if ($element->getOrd() == $pos) {
|
||||
$this->original_item = $element;
|
||||
$sbas_id = $element->getRecord($this->app)->get_sbas_id();
|
||||
$record_id = $element->getRecord($this->app)->get_record_id();
|
||||
$sbas_id = $element->getSbasId();
|
||||
$record_id = $element->getRecordId();
|
||||
$this->name = $Basket->getName();
|
||||
$number = $element->getOrd();
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "FEED":
|
||||
/** @var FeedEntry $entry */
|
||||
$entry = $app['repo.feed-entries']->find($contId);
|
||||
|
||||
$this->container = $entry;
|
||||
@@ -178,25 +163,24 @@ class record_preview extends record_adapter
|
||||
|
||||
foreach ($entry->getItems() as $element) {
|
||||
$i ++;
|
||||
if ($first) {
|
||||
$sbas_id = $element->getRecord($this->app)->get_sbas_id();
|
||||
$record_id = $element->getRecord($this->app)->get_record_id();
|
||||
$this->name = $entry->getTitle();
|
||||
$this->original_item = $element;
|
||||
$number = $element->getOrd();
|
||||
}
|
||||
$first = false;
|
||||
|
||||
if ($element->getOrd() == $pos) {
|
||||
$sbas_id = $element->getRecord($this->app)->get_sbas_id();
|
||||
$record_id = $element->getRecord($this->app)->get_record_id();
|
||||
if ($element->getOrd() == $pos || $first) {
|
||||
$sbas_id = $element->getSbasId();
|
||||
$record_id = $element->getRecordId();
|
||||
$this->name = $entry->getTitle();
|
||||
$this->original_item = $element;
|
||||
$number = $element->getOrd();
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf('Expects env argument to one of (RESULT, REG, BASK, FEED) got %s', $env));
|
||||
}
|
||||
|
||||
if (!(isset($sbas_id) && isset($record_id))) {
|
||||
throw new Exception('No record could be found');
|
||||
}
|
||||
|
||||
parent::__construct($app, $sbas_id, $record_id, $number);
|
||||
}
|
||||
|
||||
@@ -208,9 +192,11 @@ class record_preview extends record_adapter
|
||||
|
||||
switch ($this->env) {
|
||||
case 'RESULT':
|
||||
$perPage = 56;
|
||||
$index = ($this->pos - 3) < 0 ? 0 : ($this->pos - 3);
|
||||
$results = $this->searchEngine->query($this->query, $index, $perPage, $this->options);
|
||||
$options = $this->options ?: new SearchEngineOptions();
|
||||
$options->setFirstResult(($this->pos - 3) < 0 ? 0 : ($this->pos - 3));
|
||||
$options->setMaxResults(56);
|
||||
|
||||
$results = $this->searchEngine->query($this->query, $options);
|
||||
|
||||
$this->train = $results->getResults()->toArray();
|
||||
break;
|
||||
@@ -226,22 +212,23 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function is_from_result()
|
||||
{
|
||||
return $this->env == 'RESULT';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_from_feed()
|
||||
{
|
||||
return $this->env == 'FEED';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function is_from_basket()
|
||||
{
|
||||
@@ -249,8 +236,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function is_from_reg()
|
||||
{
|
||||
@@ -272,7 +258,7 @@ class record_preview extends record_adapter
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
$this->title = collection::getLogo($this->get_base_id(), $this->app) . ' ';
|
||||
$this->title = collection::getLogo($this->getBaseId(), $this->app) . ' ';
|
||||
|
||||
switch ($this->env) {
|
||||
|
||||
@@ -303,7 +289,6 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return mixed content
|
||||
*/
|
||||
public function get_container()
|
||||
@@ -312,8 +297,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function get_short_history()
|
||||
{
|
||||
@@ -323,16 +307,13 @@ class record_preview extends record_adapter
|
||||
|
||||
$tab = [];
|
||||
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->get_base_id(), 'canreport');
|
||||
|
||||
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
||||
$connsbas = $databox->get_connection();
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'canreport');
|
||||
|
||||
$sql = 'SELECT d . * , l.user, l.usrid as usr_id, l.site
|
||||
FROM log_docs d, log l
|
||||
WHERE d.log_id = l.id
|
||||
AND d.record_id = :record_id ';
|
||||
$params = [':record_id' => $this->get_record_id()];
|
||||
$params = [':record_id' => $this->getRecordId()];
|
||||
|
||||
if (! $report) {
|
||||
$sql .= ' AND ((l.usrid = :usr_id AND l.site= :site) OR action="add")';
|
||||
@@ -342,12 +323,7 @@ class record_preview extends record_adapter
|
||||
|
||||
$sql .= 'ORDER BY d.date, usrid DESC';
|
||||
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
foreach ($this->getDataboxConnection()->executeQuery($sql, $params)->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$hour = $this->app['date-formatter']->getPrettyString(new DateTime($row['date']));
|
||||
|
||||
if ( ! isset($tab[$hour]))
|
||||
@@ -374,7 +350,7 @@ class record_preview extends record_adapter
|
||||
|
||||
if ( ! in_array($row['final'], $tab[$hour][$site][$action][$row['usr_id']]['final'])) {
|
||||
if ($action == 'collection') {
|
||||
$tab[$hour][$site][$action][$row['usr_id']]['final'][] = phrasea::baseFromColl($this->get_sbas_id(), $row['final'], $this->app);
|
||||
$tab[$hour][$site][$action][$row['usr_id']]['final'][] = phrasea::baseFromColl($this->getDataboxId(), $row['final'], $this->app);
|
||||
} else {
|
||||
$tab[$hour][$site][$action][$row['usr_id']]['final'][] = $row['final'];
|
||||
}
|
||||
@@ -390,8 +366,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media_image
|
||||
* @return media_adapter
|
||||
*/
|
||||
public function get_view_popularity()
|
||||
{
|
||||
@@ -400,7 +375,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base(
|
||||
$this->get_base_id(), 'canreport');
|
||||
$this->getBaseId(), 'canreport');
|
||||
|
||||
if ( ! $report && ! $this->app['conf']->get(['registry', 'webservices', 'google-charts-enabled'])) {
|
||||
$this->view_popularity = false;
|
||||
@@ -429,19 +404,14 @@ class record_preview extends record_adapter
|
||||
AND site_id = :site
|
||||
GROUP BY datee ORDER BY datee ASC';
|
||||
|
||||
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
||||
$connsbas = $databox->get_connection();
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute(
|
||||
[
|
||||
':record_id' => $this->get_record_id(),
|
||||
':site' => $this->app['conf']->get(['main', 'key'])
|
||||
]
|
||||
);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$result = $this->getDataboxConnection()
|
||||
->executeQuery($sql, [
|
||||
':record_id' => $this->getRecordId(),
|
||||
':site' => $this->app['conf']->get(['main', 'key'])
|
||||
])
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
foreach ($result as $row) {
|
||||
if (isset($views[$row['datee']])) {
|
||||
$views[$row['datee']] = (int) $row['views'];
|
||||
$top = max((int) $row['views'], $top);
|
||||
@@ -480,8 +450,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media
|
||||
* @return media_adapter
|
||||
*/
|
||||
public function get_refferer_popularity()
|
||||
{
|
||||
@@ -490,7 +459,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base(
|
||||
$this->get_base_id(), 'canreport');
|
||||
$this->getBaseId(), 'canreport');
|
||||
|
||||
if ( ! $report && ! $this->app['conf']->get(['registry', 'webservices', 'google-charts-enabled'])) {
|
||||
$this->refferer_popularity = false;
|
||||
@@ -498,23 +467,19 @@ class record_preview extends record_adapter
|
||||
return $this->refferer_popularity;
|
||||
}
|
||||
|
||||
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
||||
$connsbas = $databox->get_connection();
|
||||
|
||||
$sql = 'SELECT count( id ) AS views, referrer
|
||||
FROM `log_view`
|
||||
WHERE record_id = :record_id
|
||||
AND date > ( NOW( ) - INTERVAL 1 MONTH )
|
||||
GROUP BY referrer ORDER BY referrer ASC';
|
||||
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute([':record_id' => $this->get_record_id()]);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$result = $this->getDataboxConnection()
|
||||
->executeQuery($sql, [':record_id' => $this->getRecordId()])
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$referrers = [];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
foreach ($result as $row) {
|
||||
if ($row['referrer'] == 'NO REFERRER')
|
||||
$row['referrer'] = $this->app->trans('report::acces direct');
|
||||
if ($row['referrer'] == $this->app['conf']->get('servername') . 'prod/')
|
||||
@@ -553,8 +518,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media
|
||||
* @return media_adapter
|
||||
*/
|
||||
public function get_download_popularity()
|
||||
{
|
||||
@@ -562,7 +526,7 @@ class record_preview extends record_adapter
|
||||
return $this->download_popularity;
|
||||
}
|
||||
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->get_base_id(), 'canreport');
|
||||
$report = $this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($this->getBaseId(), 'canreport');
|
||||
|
||||
$ret = false;
|
||||
if ( ! $report && ! $this->app['conf']->get(['registry', 'webservices', 'google-charts-enabled'])) {
|
||||
@@ -592,21 +556,16 @@ class record_preview extends record_adapter
|
||||
AND site= :site
|
||||
GROUP BY datee ORDER BY datee ASC';
|
||||
|
||||
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
||||
$connsbas = $databox->get_connection();
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute(
|
||||
[
|
||||
':record_id' => $this->get_record_id(),
|
||||
$result = $this->getDataboxConnection()
|
||||
->executeQuery($sql, [
|
||||
':record_id' => $this->getRecordId(),
|
||||
':site' => $this->app['conf']->get(['main', 'key'])
|
||||
]
|
||||
);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
])
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$top = 10;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
foreach ($result as $row) {
|
||||
if (isset($dwnls[$row['datee']])) {
|
||||
$dwnls[$row['datee']] = (int) $row['dwnl'];
|
||||
$top = max(((int) $row['dwnl'] + 10), $top);
|
||||
|
Reference in New Issue
Block a user