316a5bc06148a2c682be0544f6c400850599f024
[acontent.git] / docs / include / classes / DAO / PatchesFilesDAO.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 /**
14  * DAO for "patches_files" table
15  * @access      public
16  * @author      Cindy Qi Li
17  * @package     DAO
18  */
19
20 if (!defined('TR_INCLUDE_PATH')) exit;
21
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23
24 class PatchesFilesDAO extends DAO {
25
26         /**
27          * Create new row
28          * @access  public
29          * @param   patch_id, action, $name, $location
30          * @return  patches_files_id, if successful
31          *          false and add error into global var $msg, if unsuccessful
32          * @author  Cindy Qi Li
33          */
34         public function Create($patch_id, $action, $name, $location)
35         {
36                 global $addslashes;
37
38                 $sql = "INSERT INTO " . TABLE_PREFIX. "patches_files " .
39                                          "(patches_id, 
40                                            action,
41                                            name,
42                                            location)
43                                           VALUES
44                                           (".$patch_id.",
45                                            '".$action."',
46                                            '".$addslashes($name)."',
47                                            '".$addslashes($location)."')";
48                 
49                 if (!$this->execute($sql))
50                 {
51                         $msg->addError('DB_NOT_UPDATED');
52                         return false;
53                 }
54                 else
55                 {
56                         return mysql_insert_id();
57                 }
58         }
59
60         /**
61          * Return number of times that the given file have been updated by Updater
62          * @access  public
63          * @param   $file: file name
64          * @return  number of times
65          * @author  Cindy Qi Li
66          */
67         public function getNumOfUpdatesOnFile($file)
68         {
69                 $sql = "SELECT count(*) num_of_updates FROM " . TABLE_PREFIX. "patches patches, " . TABLE_PREFIX."patches_files patches_files " .
70                                "WHERE patches.applied_version = '" . VERSION . "' ".
71                                "  AND patches.status = 'Installed' " .
72                                "  AND patches.patches_id = patches_files.patches_id " .
73                                "  AND patches_files.name = '" . $file . "'";
74                 
75                 return $this->execute($sql);
76         }               
77 }
78 ?>