ImgObjectPropertiesReader.php 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php
/**
 * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
 *
 * BOKEH is free software; you can redistribute it and/or modify
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
 * BOKEH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
 * along with BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */


class ZendAfi_View_Helper_Admin_ImgObjectPropertiesReader
  extends ZendAfi_View_Helper_BaseHelper{
  const
    DEFAULTS_FILE = 'valeurs_par_defaut.txt',
    PROPERTIES_FILE = 'valeurs_properties.html';

  protected $_properties_path, $_defaults_path;

31
  public function imgObjectPropertiesReader($plugin, $preferences, $without_div=false) {
32 33 34 35 36 37 38 39
    if (!$this->_hasProperties($plugin))
      return '';

    $this->view->preferences = array_merge($this->_loadDefaults(),
                                           $preferences);
    $this->view->addScriptPath(PATH_JAVA);
    $html = $this->_tag('div', $this->_('Propriétés de l\'objet'))
      . $this->view->render($this->_properties_path);
Laurent's avatar
Laurent committed
40 41

    if ($without_div)
42
       return $html;
Laurent's avatar
Laurent committed
43 44

    $html = $this->_tag('div',
45 46 47
                         $html,
                         ['id' => 'objet_props',
                          'style' => 'display: none;']);
48 49 50 51 52 53
    return Class_Admin_Skin::current()
      ->renderActionIconOn('box_configuration',
                           $this->view,
                           ['title' => $this->_("propriétés de l'objet"),
                            'style' => 'cursor:pointer',
                            'onclick' => "$(this).next().slideToggle();"]) .
54 55
      $html
      ;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  }


  protected function _loadDefaults() {
    if (!$content = file(PATH_JAVA . $this->_defaults_path, FILE_IGNORE_NEW_LINES))
      return [];

    $defaults = [];
    foreach ($content as $line) {
      $parts = explode('=', trim($line));
      $defaults['op_' . $parts[0]] = $parts[1];
    }

    return $defaults;
  }


  protected function _hasProperties($plugin) {
    $properties_path = $plugin . '/' . static::PROPERTIES_FILE;
    $defaults_path = $plugin . '/' . static::DEFAULTS_FILE;

    if (file_exists(PATH_JAVA . $properties_path)) {
      $this->_properties_path = $properties_path;
      $this->_defaults_path = $defaults_path;
      return true;
    }

    return false;
  }
}