Пример #1
0
 public function mysql_save_from_post($post)
 {
     foreach ($post as $pk => $pv) {
         foreach (get_object_vars($this) as $ok => $ov) {
             if ($pk == $ok) {
                 $this->{$ok} = $pv;
             }
         }
     }
     $lid = $this->mysql_save();
     $this->id = $lid;
     if (isset($post['buttons'])) {
         foreach ($this->get_ItemButtons() as $button) {
             if (!in_array($button->name, $post['buttons'])) {
                 $button->mysql_delete();
             }
         }
         for ($i = 0; $i < count($post['buttons']); $i++) {
             $name = $post['buttons'][$i];
             $function = $post['functions'][$i];
             if ($name == "") {
                 continue;
             }
             $button = $this->get_Button($name);
             if ($button == null) {
                 $button = new ItemButton();
                 $button->id = 0;
             }
             $button->function = $function;
             $button->Item_id = $lid;
             $button->name = $name;
             $button->mysql_save();
         }
     }
     $default_btn = ItemButton::from_property(array("name" => $post["default_btn_name"], "Item_id" => $post["oid"]), false);
     if ($default_btn != null) {
         $this->default_Button_id = $default_btn->id;
     } else {
         $this->default_Button_id = 0;
     }
     $this->hash = $this->calculate_hash();
     $this->mysql_save();
     return $lid;
 }