示例#1
0
 /**
  * Attempts to get a translated label which can be used when composing an "add" link.
  *
  * @return string Localised "add" label
  */
 public function getAddLabel()
 {
     $key = 'link_' . $this->fieldName() . '_add';
     $label = Tools::atktext($key, $this->m_ownerInstance->m_module, $this->m_ownerInstance->m_type, '', '', true);
     if ($label == '') {
         $label = Tools::atktext($key, $this->m_destInstance->m_module, '', '', '', true);
         if ($label == '') {
             $key = 'link_' . Tools::getNodeType($this->m_destination) . '_add';
             $label = Tools::atktext($key, $this->m_destInstance->m_module, '', '', '', true);
             if ($label == '') {
                 $label = Tools::atktext('link_add', 'atk');
             }
         }
     }
     return $label;
 }
示例#2
0
文件: Atk.php 项目: sintattica/atk
 /**
  * Tells ATK that a node exists, and what actions are available to
  * perform on that node.  Note that registerNode() is not involved in
  * deciding which users can do what, only in establishing the full set
  * of actions that can potentially be performed on the node.
  *
  * @param string $nodeUri uri of the node
  * @param string $class class of the node
  * @param array $actions actions that can be performed on the node
  * @param array $tabs tabnames for which security should be handled.
  *              Note that tabs that every user may see need not be
  *              registered.
  * @param string $section
  */
 public function registerNode($nodeUri, $class, $actions = null, $tabs = [], $section = null)
 {
     if (!is_array($tabs)) {
         $section = $tabs;
         $tabs = [];
     }
     $module = Tools::getNodeModule($nodeUri);
     $type = Tools::getNodeType($nodeUri);
     $this->g_nodesClasses[$nodeUri] = $class;
     if ($actions) {
         // prefix tabs with tab_
         for ($i = 0, $_i = count($tabs); $i < $_i; ++$i) {
             $tabs[$i] = 'tab_' . $tabs[$i];
         }
         if ($module == '') {
             $module = 'main';
         }
         if ($section == null) {
             $section = $module;
         }
         $this->g_nodes[$section][$module][$type] = array_merge($actions, $tabs);
     }
 }
示例#3
0
 /**
  * Gets the node and the descriptor for the current item
  * and returns a trace of that.
  *
  * So for instance, if we were adding a grade to a student,
  * it would show:
  * Student [ Teknoman ] - Grade [ A+ ]
  *
  * @return string The descriptortrace
  */
 public function descriptorTrace()
 {
     $sessionData =& self::getSession();
     $stack = $sessionData[$this->m_namespace]['stack'][$this->atkStackID()];
     $res = [];
     $node = null;
     $module = null;
     $nodename = null;
     $stackcount = count($stack);
     $atk = Atk::getInstance();
     for ($i = 0; $i < $stackcount; ++$i) {
         if (isset($stack[$i]['descriptor']) || $i == $stackcount - 1) {
             if ($stack[$i]['atknodeuri'] != '') {
                 $node = $atk->atkGetNode($stack[$i]['atknodeuri']);
                 $module = Tools::getNodeModule($stack[$i]['atknodeuri']);
                 $nodename = Tools::getNodeType($stack[$i]['atknodeuri']);
             }
             if (is_object($node)) {
                 $ui = Ui::getInstance();
                 $txt = $ui->title($module, $nodename);
             } else {
                 $txt = Tools::atktext($nodename, $module);
             }
             $res[] = $txt . (isset($stack[$i]['descriptor']) ? " [ {$stack[$i]['descriptor']} ] " : '');
         }
     }
     return $res;
 }
示例#4
0
 /**
  * Get the select link to select the value using a select action on the destination node.
  *
  * @param string $selname
  * @param string $filter
  *
  * @return string HTML-code with the select link
  */
 public function _getSelectLink($selname, $filter)
 {
     $result = '';
     // we use the current level to automatically return to this page
     // when we come from the select..
     $sm = SessionManager::getInstance();
     $atktarget = Tools::atkurlencode(Config::getGlobal('dispatcher') . '?atklevel=' . $sm->atkLevel() . '&' . $selname . '=[atkprimkey]');
     $linkname = Tools::atktext('link_select_' . Tools::getNodeType($this->m_destination), $this->getOwnerInstance()->getModule(), $this->getOwnerInstance()->getType(), '', '', true);
     if (!$linkname) {
         $linkname = Tools::atktext('link_select_' . Tools::getNodeType($this->m_destination), Tools::getNodeModule($this->m_destination), Tools::getNodeType($this->m_destination), '', '', true);
     }
     if (!$linkname) {
         $linkname = Tools::atktext('select_a');
     }
     $result .= Tools::href(Tools::dispatch_url($this->m_destination, 'select', ['atkfilter' => $filter, 'atktarget' => $atktarget]), $linkname, SessionManager::SESSION_NESTED, $this->m_autocomplete_saveform, 'class="atkmanytoonerelation atkmanytoonerelation-link"');
     return $result;
 }
示例#5
0
 /**
  * Admin page displays records and the actions that can be performed on
  * them (edit, delete) in a Treeview.
  *
  * @param ActionHandler $handler The action handler object
  */
 public function adminPage($handler)
 {
     global $g_maxlevel;
     $ui = $this->getUi();
     $content = '';
     $adminHeader = $handler->invoke('adminHeader');
     if ($adminHeader != '') {
         $content .= $adminHeader . '<br><br>';
     }
     Tools::atkdebug('Entering treeview page.');
     $t = $this->buildTree();
     $this->m_tree[0]['level'] = 0;
     $this->m_tree[0]['id'] = '';
     $this->m_tree[0]['expand'] = $this->hasFlag(self::NF_TREE_AUTO_EXPAND) ? 1 : 0;
     $this->m_tree[0]['colapse'] = 0;
     $this->m_tree[0]['isleaf'] = 1;
     $this->m_tree[0]['label'] = '';
     $this->treeToArray($t->m_tree);
     $g_maxlevel = $g_maxlevel + 2;
     $width = $g_maxlevel * 16 + 600;
     $content .= '<table border="0" cellspacing=0 cellpadding=0 cols=' . ($g_maxlevel + 2) . ' width=' . $width . ">\n";
     if (!$this->hasFlag(self::NF_NO_ADD) && $this->hasFlag(self::NF_ADD_LINK) && $this->allowed('add')) {
         $addurl = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=add&atkfilter=' . rawurlencode($this->m_parent . '.' . $this->m_primaryKey[0] . "='0'");
         if (Tools::atktext('txt_link_' . Tools::getNodeType($this->m_type) . '_add', $this->m_module, '', '', '', true) != '') {
             // specific text
             $label = Tools::atktext('link_' . Tools::getNodeType($this->m_type) . '_add', $this->m_module);
         } else {
             // generic text
             $label = Tools::atktext(Tools::getNodeType($this->m_type), $this->m_module) . ' ' . Tools::atktext('add', 'atk');
         }
         $content .= Tools::href($addurl, $label, SessionManager::SESSION_NESTED) . '<br><br>';
     }
     $content .= $this->GraphTreeRender();
     $content .= '</table><br>';
     $adminFooter = $handler->invoke('adminFooter');
     if ($adminFooter != '') {
         $content .= '<br>' . $adminFooter;
     }
     Tools::atkdebug('Generated treeview');
     return $ui->renderBox(array('title' => Tools::atktext('title_' . $this->m_type . '_tree', $this->m_module), 'content' => $content));
 }
示例#6
0
 /**
  * Returns the currently selected actions.
  *
  * @param array $record The record
  *
  * @return array array with selected actions
  */
 public function getSelectedActions($record)
 {
     $selected = $record[$this->fieldName()];
     $result = [];
     foreach ($selected as $node => $actions) {
         $module = Tools::getNodeModule($node);
         $node = Tools::getNodeType($node);
         $result[$module][$node] = $actions;
     }
     return $result;
 }