コード例 #1
0
 function score()
 {
     if (isset($_GET['type'])) {
         $type = $_GET['type'];
         $types = D('ScoreField')->getScoreFields();
         if (in_array($type, get_new_array($types, 'name'))) {
             $s = session('avatar');
             if (isset($s[$_GET['number']])) {
                 $p = array();
                 foreach ($s as $k => $v) {
                     $t['number'] = $k;
                     $score = $this->getScore($k, $type);
                     $t['score'] = $score['score'];
                     $t['sid'] = $score['sid'];
                     if ($k == $_GET['number']) {
                         $t['this'] = 1;
                     } else {
                         $t['this'] = 0;
                     }
                     $p[] = $t;
                     unset($t);
                 }
                 if (count($p) != 2) {
                     session('avatar', null);
                     return false;
                 }
                 $re = pk($p[0]['score'], $p[1]['score'], $p[0]['this'], $p[1]['this']);
                 $p[0]['score'] = $re[0];
                 $p[1]['score'] = $re[1];
                 $p[0]['type'] = $type;
                 $p[1]['type'] = $type;
                 unset($p[0]['this']);
                 unset($p[1]['this']);
                 $this->save($p[0]);
                 $this->save($p[1]);
                 $this->setScoreLog($_GET['number']);
                 session('avatar', null);
                 return true;
             }
             session('avatar', null);
         }
     }
 }
コード例 #2
0
ファイル: base.php プロジェクト: volodymyr-volynets/frontend
 /**
  * Convert multiple columns
  */
 private function convert_multiple_columns(&$values)
 {
     // regular fields
     foreach ($this->fields as $k => $v) {
         if (!empty($v['options']['multiple_column'])) {
             if (!empty($values[$k])) {
                 pk($v['options']['multiple_column'], $values[$k]);
                 $values[$k] = array_keys($values[$k]);
             }
         }
     }
     // details
     foreach ($this->detail_fields as $k => $v) {
         if (empty($values[$k]) || !is_array($values[$k])) {
             continue;
         }
         if (!empty($v['options']['details_convert_multiple_columns'])) {
             $widget_model = factory::model($k, true);
             $widget_model->convert_multiple_columns($this, $values[$k]);
         } else {
             if (!empty($values[$k])) {
                 // convert fields
                 // 1 to 1
                 if (!empty($v['options']['details_11'])) {
                     $details = [$values[$k]];
                 } else {
                     // 1 to M
                     $details = $values[$k];
                 }
                 foreach ($details as $k5 => $v5) {
                     if (!empty($v['options']['details_11'])) {
                         $values_key = [$k];
                     } else {
                         $values_key = [$k, $k5];
                     }
                     foreach ($v['elements'] as $k2 => $v2) {
                         if (!empty($v2['options']['multiple_column'])) {
                             if (!empty($v5[$k2])) {
                                 $temp = $v5[$k2];
                                 pk($v2['options']['multiple_column'], $temp);
                                 array_key_set($values, array_merge($values_key, [$k2]), array_keys($temp));
                             }
                         }
                     }
                 }
             }
         }
         // subdetails
         if (!empty($v['subdetails'])) {
             foreach ($values[$k] as $k11 => $v11) {
                 foreach ($v['subdetails'] as $k0 => $v0) {
                     if (!empty($v0['options']['details_convert_multiple_columns'])) {
                         $widget_model = factory::model($k0, true);
                         $widget_model->convert_multiple_columns($this, $values[$k][$k11][$k0]);
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: data.php プロジェクト: volodymyr-volynets/framework
 /**
  * Get data
  *
  * @param array $options
  *		where - array of conditions
  *		pk - primary key to be used by query
  *		orderby - array of columns to sort by
  * @return array
  */
 public function get($options = [])
 {
     // get available data types
     if (get_called_class() == 'object_data_types') {
         $types = $this->data;
     } else {
         $types = object_data_types::get_static();
     }
     // transform data
     $result = [];
     foreach ($this->data as $k => $v) {
         foreach ($this->columns as $k2 => $v2) {
             if ($this->column_key == $k2) {
                 $result[$k][$k2] = $k;
             } else {
                 if (!array_key_exists($k2, $v)) {
                     $result[$k][$k2] = $v2['default'] ?? $types[$v2['type']]['no_data_type_default'] ?? null;
                 } else {
                     $result[$k][$k2] = $v[$k2];
                 }
             }
         }
     }
     // filtering
     if (!empty($options['where'])) {
         foreach ($result as $k => $v) {
             $found = true;
             foreach ($options['where'] as $k2 => $v2) {
                 // todo: add options ad in query
                 if (array_key_exists($k2, $v) && $v[$k2] != $v2) {
                     $found = false;
                     break;
                 }
             }
             if (!$found) {
                 unset($result[$k]);
             }
         }
     }
     // sorting, if none specified we sort by name if its in columns
     $orderby = null;
     if (isset($options['orderby'])) {
         $orderby = $options['orderby'];
     } else {
         if (isset($this->orderby)) {
             $orderby = $this->orderby;
         } else {
             if (isset($this->columns[$this->column_prefix . 'name'])) {
                 $orderby = [$this->column_prefix . 'name' => SORT_ASC];
             }
         }
     }
     if (!empty($orderby)) {
         $method = [];
         foreach ($orderby as $k => $v) {
             $type = $types[$this->columns[$k]['type']]['php_type'];
             if ($type == 'integer' || $type == 'float') {
                 $method[$k] = SORT_NUMERIC;
             }
         }
         array_key_sort($result, $orderby, $method);
     }
     // if we have primary key
     $pk = $options['pk'] ?? $this->pk;
     if (!empty($pk)) {
         pk($pk, $result);
     }
     return $result;
 }