Exemplo n.º 1
0
 function tagDict($Item = array())
 {
     $name = $this->attr("from");
     $sort = $this->attr("sort");
     $dsort = $this->attr("data-sort");
     $desc = $this->attr("desc");
     $rand = $this->attr("rand");
     if ($this->attr("item") > "") {
         $value = $this->attr("item");
     } else {
         $value = $this->attr("data-id");
     }
     $result = aikiReadDict($name);
     if ($value > "") {
         $result = aikiWhere($result, 'id = "' . $value . '"');
     }
     $html = $this->html();
     $this->html("");
     $inner = "";
     if (is_array($result)) {
         if ($sort > "") {
             // старый формат
             if ($desc == "true") {
                 $stype = SORT_DESC;
             } else {
                 $stype = SORT_ASC;
             }
             $result = array_sort($result, $sort, $stype);
         }
         if ($dsort > "") {
             $result = array_sort_multi($result, $dsort);
         }
         if ($rand == "true") {
             shuffle($result);
         }
         $srcVal = array();
         foreach ($Item as $k => $v) {
             $srcVal["%{$k}"] = $v;
         }
         unset($v);
         $ndx = 0;
         foreach ($result as $key => $val) {
             $val["_idx"] = $_SESSION["dict_idx"] = $key;
             $val["_ndx"] = $_SESSION["dict_ndx"] = $ndx;
             $ndx++;
             $val = (array) $srcVal + (array) $val;
             // сливаем массивы
             $tpl = aikiFromString($html);
             $tpl->contentSetData($val);
             if ($value > "") {
                 if ($value == $val["id"]) {
                     $inner = $tpl->outerHtml();
                 }
             } else {
                 $inner .= $tpl->outerHtml();
             }
         }
         $this->html($inner);
         unset($val, $inner);
     }
     if ($this->tag() == "select") {
         if (!is_array($result)) {
             $this->outerHtml("");
         }
         $plhr = $this->attr("placeholder");
         if ($plhr > "") {
             $this->prepend("<option value=''>{$plhr}</option>");
         }
     }
 }
Exemplo n.º 2
0
function aikiDictOconv($dict, $value, $search_fld = "id", $return_fld = null)
{
    if (is_string($dict)) {
        $dict = aikiReadDict($dict);
    }
    return $dict[array_search_assoc($dict, $value)][$return_fld];
}