예제 #1
0
 /**
  * 
  * @param be_widget $widget
  * @return \be_widget
  */
 public static function AddWidget($widget)
 {
     $sqlCommand = "INSERT INTO widgets (page_id, widget_type_id, title, description, refresh_frequency_sec, `order`, created_datetime )" . "VALUES (?,?,?,?,?,?, NOW())";
     $paramTypeSpec = "iissii";
     $mysqli = DA_Helper::mysqli_connect();
     if ($mysqli->connect_errno) {
         $msg = "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
         throw new Exception($msg, $mysqli->connect_errno);
     }
     if (!($stmt = $mysqli->prepare($sqlCommand))) {
         $msg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
         throw new Exception($msg, $stmt->errno);
     }
     if (!$stmt->bind_param($paramTypeSpec, $widget->page_id, $widget->widget_type_id, $widget->title, $widget->description, $widget->refresh_frequency_sec, $widget->order)) {
         $msg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
         throw new Exception($msg, $stmt->errno);
     }
     if (!$stmt->execute()) {
         $msg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
         throw new Exception($msg, $stmt->errno);
     }
     $stmt->close();
     da_widgets::reorderWidgets($widget->page_id);
     $insertedWidgetID = $mysqli->insert_id;
     $retrievedPage = da_widgets::GetWidget($insertedWidgetID);
     return $retrievedPage;
 }