Пример #1
0
 /**
  * конвертирует строковые значения полей в заданный тип
  *
  * @param string $value значение переменной
  * @param string $type тип переменной ('bool','date') 
  * @return mixed значение нужного типа
  */
 function type_cast($value, $type)
 {
     switch ($type) {
         case "bool":
             return $value == "true";
         case 'float':
             return get_float(trim($value));
         case 'int':
         case 'integer':
             return get_integer(trim($value));
         case "date":
             $date_parts = strptime($value, get_date_input());
             return mktime(0, 0, 0, $date_parts["tm_mon"] + 1, $date_parts["tm_mday"], 1900 + $date_parts["tm_year"]);
         case 'textcode':
             $num = 0;
             for ($i = strlen($value) - 1; $i >= 0; $i--) {
                 $num = $num * 26 + (ord($value[$i]) - ord('a'));
             }
             return (int) $num ^ 67894523;
         default:
             return $value;
     }
 }
Пример #2
0
 protected function getCidList($table, $id, $different, $isChild = false)
 {
     $obj = M($table);
     $id = get_integer($id);
     $data = $obj->field('`id`')->where(array('pid' => $id, 'different' => $different))->select();
     $data = deep_htmlspecialchars_decode($data);
     foreach ($data as $value) {
         $string = $string . ',' . $value['id'];
         $string = $string . $this->getIdList($table, $value['id'], $different, true);
     }
     if ($isChild) {
         return $string;
     } else {
         return $id . $string;
     }
 }