directory = $directory; if ($this->directory) { $unicode = new \unicode(); $this->directory = $unicode->remove_nonazAZ09($this->directory) . '/'; } $this->remain_hd = $remain_hd; $this->size = array(); parent::__construct($app, $sbas_id, $record_id); $this->get_actions($remain_hd); return $this; } /** * * @return record_exportElement */ protected function get_actions() { $this->downloadable = $downloadable = array(); $this->orderable = $orderable = array(); $sd = $this->get_subdefs(); $sbas_id = phrasea::sbasFromBas($this->app, $this->base_id); $subdefgroups = $this->app['phraseanet.appbox']->get_databox($sbas_id)->get_subdef_structure(); $subdefs = array(); foreach ($subdefgroups as $subdef_type => $subdefs_obj) { if ($subdef_type == $this->get_type()) { $subdefs = $subdefs_obj; break; } } $go_dl = array( 'document' => false, 'preview' => false, 'thumbnail' => true ); if ($this->app['authentication']->getUser()->ACL()->has_right_on_base($this->get_base_id(), 'candwnldhd')) { $go_dl['document'] = true; } if ($this->app['authentication']->getUser()->ACL()->has_right_on_base($this->get_base_id(), 'candwnldpreview')) { $go_dl['preview'] = true; } if ($this->app['authentication']->getUser()->ACL()->has_hd_grant($this)) { $go_dl['document'] = true; $go_dl['preview'] = true; } if ($this->app['authentication']->getUser()->ACL()->has_preview_grant($this)) { $go_dl['preview'] = true; } $query = new User_Query($this->app); $masters = $query->on_base_ids(array($this->base_id)) ->who_have_right(array('order_master')) ->execute()->get_results(); $go_cmd = (count($masters) > 0 && $this->app['authentication']->getUser()->ACL()->has_right_on_base($this->base_id, 'cancmd')); $orderable['document'] = false; $downloadable['document'] = false; if (isset($sd['document']) && is_file($sd['document']->get_pathfile())) { if ($go_dl['document'] === true) { if ($this->app['authentication']->getUser()->ACL()->is_restricted_download($this->base_id)) { $this->remain_hd --; if ($this->remain_hd >= 0) $downloadable['document'] = array( 'class' => 'document', 'label' => _('document original') ); } else $downloadable['document'] = array( 'class' => 'document', 'label' => _('document original') ); } if ($go_cmd === true) { $orderable['document'] = true; } $this->add_count('document', $sd['document']->get_size()); } foreach ($subdefs as $subdef) { $name = $subdef->get_name(); $class = $subdef->get_class(); $subdef_label = $name; foreach ($subdef->get_labels() as $lang => $label) { if (trim($label) == '') continue; if ($lang == $this->app['locale.I18n']) { $subdef_label = $label; break; } $subdef_label = $label; } $downloadable[$name] = false; $downloadable_settings = $subdef->is_downloadable(); if (! $downloadable_settings || $go_dl[$class] === false) { continue; } if ($go_dl[$class]) { if (isset($sd[$name]) && $sd[$name]->is_physically_present()) { if ($class == 'document') { if ($this->app['authentication']->getUser()->ACL()->is_restricted_download($this->base_id)) { $this->remain_hd --; if ($this->remain_hd >= 0) $downloadable[$name] = array( 'class' => $class, 'label' => $subdef_label ); } else $downloadable[$name] = array( 'class' => $class, 'label' => $subdef_label ); } else { $downloadable[$name] = array( 'class' => $class, 'label' => $subdef_label ); } $this->add_count($name, $sd[$name]->get_size()); } } } $xml = $this->get_caption()->serialize(caption_record::SERIALIZE_XML); if ($xml) { $downloadable['caption'] = array( 'class' => 'caption', 'label' => _('caption XML') ); $this->add_count('caption', strlen($xml)); $downloadable['caption-yaml'] = array( 'class' => 'caption', 'label' => _('caption YAML') ); $this->add_count('caption-yaml', strlen(strip_tags($xml))); } $this->downloadable = $downloadable; $this->orderable = $orderable; return $this; } /** * * @param string $name * @param int $size * @return record_exportElement */ private function add_count($name, $size) { if (! $this->size) { $objectsize = array(); } else $objectsize = $this->size; $objectsize[$name] = $size; $this->size = $objectsize; return $this; } /** * * @param string $name * @return mixed content */ public function get_size($name = false) { if ($name) { return $this->size[$name]; } else { return $this->size; } } /** * * @return Array */ public function get_orderable() { return $this->orderable; } /** * * @return Array */ public function get_downloadable() { return $this->downloadable; } /** * * @return int */ public function get_remain_hd() { return $this->remain_hd; } /** * * @return string */ public function get_directory() { return $this->directory; } }