2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "myown_patches" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class MyownPatchesDAO extends DAO {
29 * @param system_patch_id, applied_versin, description, sql_statement
30 * @return myown_patch_id, if successful
31 * false and add error into global var $msg, if unsuccessful
34 public function Create($system_patch_id, $applied_version,
35 $description, $sql_statement)
39 $sql = "INSERT INTO ".TABLE_PREFIX."myown_patches
46 VALUES ('".$system_patch_id."',
47 '".$applied_version."',
53 if (!$this->execute($sql))
55 $msg->addError('DB_NOT_UPDATED');
60 return mysql_insert_id();
67 * @param myown_patch_id, system_patch_id, applied_versin, description, sql_statement
68 * @return true, if successful. Otherwise, false
71 public function Update($myown_patch_id, $system_patch_id, $applied_version,
72 $description, $sql_statement)
76 $sql = "UPDATE ".TABLE_PREFIX."myown_patches
77 SET system_patch_id = '". $system_patch_id ."',
78 applied_version = '". $applied_version ."',
79 description = '". $description ."',
80 sql_statement = '". $sql_statement ."',
83 WHERE myown_patch_id = ". $myown_patch_id;
85 return $this->execute($sql);
89 * Update an existing myown_patches record
91 * @param myownPatchID: myown_patches.myown_patch_id
92 * fieldName: the name of the table field to update
93 * fieldValue: the value to update
94 * @return true if successful
95 * error message array if failed; false if update db failed
98 public function UpdateField($myownPatchID, $fieldName, $fieldValue)
102 // check if the required fields are filled
103 if (($fieldName == 'system_patch_id' || $fieldName == 'applied_version') && $fieldValue == '')
104 return array(_AT('TR_ERROR_EMPTY_FIELD'));
106 $sql = "UPDATE ".TABLE_PREFIX."myown_patches
107 SET ".$addslashes($fieldName)."='".$addslashes($fieldValue)."'
108 WHERE myown_patch_id = ".$myownPatchID;
110 return $this->execute($sql);
117 * @return true, if successful
118 * false and add error into global var $msg, if unsuccessful
119 * @author Cindy Qi Li
121 public function Delete($patchID)
123 $sql = "DELETE FROM ".TABLE_PREFIX."myown_patches
124 WHERE myown_patch_id = ".$patchID;
126 return $this->execute($sql);
130 * Return all my own patches
133 * @return all table rows
134 * @author Cindy Qi Li
136 public function getAll()
138 $sql = "SELECT * from ".TABLE_PREFIX."myown_patches m order by last_modified desc";
140 return $this->execute($sql);
144 * Return the patch info with the given patch id
148 * @author Cindy Qi Li
150 public function getByID($patchID)
152 $sql = "SELECT * from ".TABLE_PREFIX."myown_patches where myown_patch_id=". $patchID;
154 $rows = $this->execute($sql);
156 if (is_array($rows)) return $rows[0];