Example #1
0
 /**
  * Called when new item creates
  * Calc position for item and set it
  */
 private function assign_position()
 {
     $sql_tail = '';
     if (!$this->container->with_positions()) {
         return;
     }
     $pos = $this->field('position');
     if (isset($pos['space'])) {
         $sql_tail = ' WHERE ' . $this->make_space_sql($pos['space']);
     }
     $sql = "SELECT max(position) as mp FROM " . $this->get_table() . $sql_tail;
     $row = $this->db->fetch_row($res = $this->db->query($sql));
     $this->db->free_result($res);
     $this->position = (int) $row['mp'] + 1;
 }
Example #2
0
 /**
  * Update item fields
  * Service method, call with caution
  * Data must be validated!
  * @param array|integer item id
  * @param array|string sql array('key=>'value',...)
  * @return bool result
  */
 public function update_item_fields($id, $data)
 {
     $sql_in = array();
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $value = $this->format_field_sql($key, $value);
             $sql_in[] = "{$key} = {$value}";
         }
         $data = implode(',', $sql_in);
     }
     $key = $this->get_key();
     if (is_array($id)) {
         foreach ($id as &$_id) {
             $_id = $this->format_field_sql($key, $_id);
         }
     } else {
         $id = $this->format_field_sql($key, $id);
     }
     $where_id = is_array($id) ? "IN (" . implode(',', $id) . ")" : "= {$id}";
     $this->_last_query = $sql = "UPDATE LOW_PRIORITY {$this->config->table} SET {$data} WHERE {$key} " . $where_id . ';';
     $res = $this->db->query($sql);
     return $res;
 }
Example #3
0
 /**
  * @param dbal $db
  * @param string $sql
  */
 function run_queries($db, $sql)
 {
     if (strpos($sql, ';') !== false) {
         $sql = explode(';', $sql);
         foreach ($sql as $query) {
             $query = trim($query);
             if (!empty($query)) {
                 $db->query($query);
             }
         }
     } else {
         $db->query($sql);
     }
 }