Пример #1
0
 /**
  * Constructor.
  *
  * @param string $name Name of the attribute
  * @param int $flags Flags for this attribute
  * @param array $optionArray Array with options
  * @param array $valueArray Array with values. If you don't use this parameter,
  *                            values are assumed to be the same as the options.
  */
 public function __construct($name, $flags = 0, $optionArray, $valueArray = null)
 {
     parent::__construct($name, $flags, $optionArray, $valueArray);
     $this->m_dbfieldtype = 'number';
 }
Пример #2
0
 public function edit($record, $fieldprefix, $mode)
 {
     // There are 2 possibilities. Either we are going to search,
     // in which case we show a searchbox.
     // Or, a search has already been performed but multiple
     // matches have been found and an atkerror was set.
     // In this case, we show the selects.
     $select = false;
     if (isset($record['atkerror'])) {
         foreach ($record['atkerror'] as $error) {
             if ($error['attrib_name'] === $this->fieldName()) {
                 $select = true;
             }
         }
     }
     if ($select && $this->createSearchNodeInstance()) {
         $res = '';
         $notempty = false;
         // First lets get the results, which were lost during the redirect
         $this->m_matches = $this->getMatches($record[$this->fieldName()]);
         // Second check if we actually found anything
         if ($this->m_matches) {
             foreach ($this->m_matches as $match) {
                 if (!empty($match)) {
                     $notempty = true;
                     continue;
                 }
             }
             if (!$notempty) {
                 return Tools::atktext('no_results_found');
             }
         }
         if ($this->m_mode == 'multiselect' && count($this->m_matches) > 1) {
             $optionArray = $valueArray = [];
             foreach ($this->m_matches as $keyword => $matches) {
                 for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                     $optionArray[] = $this->m_searchnodeInstance->descriptor($matches[$i]);
                     $valueArray[] = $this->m_searchnodeInstance->primaryKey($matches[$i]);
                 }
             }
             $attrib = new MultiSelectAttribute($this->m_name, $optionArray, $valueArray, 1, self::AF_NO_LABEL | MultiSelectAttribute::AF_CHECK_ALL | MultiSelectAttribute::AF_LINKS_BOTTOM);
             $res .= $attrib->edit($record, $fieldprefix, $mode);
         } else {
             if ($this->m_mode == 'select' || $this->m_mode == 'multiselect' && count($this->m_matches) == 1) {
                 // Select one record from all matches.
                 $res .= '<SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">';
                 $res .= '<OPTION VALUE="">' . Tools::atktext('select_none');
                 $selects = [];
                 foreach ($this->m_matches as $keyword => $matches) {
                     for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                         $item = '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]);
                         if (!in_array($item, $selects)) {
                             $selects[] = $item;
                         }
                     }
                     $res .= implode("\n", $selects);
                 }
                 $res .= '</SELECT>';
             } else {
                 if ($this->m_mode == 'selectperkeyword') {
                     // Select one record per keyword.
                     $res = '<table border="0">';
                     foreach ($this->m_matches as $keyword => $matches) {
                         if (count($matches) > 0) {
                             $res .= '<tr><td>\'' . $keyword . '\': </td><td><SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">';
                             $res .= '<OPTION VALUE="">' . Tools::atktext('select_none');
                             for ($i = 0, $_i = count($matches); $i < $_i; ++$i) {
                                 $res .= '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]);
                             }
                             $res .= '</SELECT></td></tr>';
                         }
                     }
                     $res .= '</table>';
                 }
             }
         }
         return $res;
     } else {
         $record = '';
         // clear the record so we always start with an empty
         // searchbox.
         return parent::edit($record, $fieldprefix, $mode);
     }
 }