moved code up one level to eliminate the docs subdirectory
[acontent.git] / include / classes / DAO / SecondaryResourcesDAO.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 "secondary_resources" 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 SecondaryResourcesDAO extends DAO {
25
26         /**
27         * Insert a new row
28         * @access  public
29         * @param   primary_resource_id, file_name, language_code
30         * @return  table rows
31         * @author  Cindy Qi Li
32         */
33         public function Create($primary_resource_id, $file_name, $lang)
34         {
35                 global $addslashes;
36                 
37                 $primary_resource_id = intval($primary_resource_id);
38                 $file_name = $addslashes(convertAmp($file_name));
39                 $lang = $addslashes($lang);
40
41                 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources 
42                                 SET primary_resource_id=$primary_resource_id, 
43                                     secondary_resource='$file_name', 
44                                     language_code='$lang'";
45                 return $this->execute($sql);
46         }
47         
48         /**
49         * Delete rows that primary or secondary resource name is the given $resourceName
50         * @access  public
51         * @param   $resourceName: primary or secondary resource name
52         * @return  true or false
53         * @author  Cindy Qi Li
54         */
55         function DeleteByResourceName($resourceName)
56         {
57                 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources
58                          WHERE secondary_resource = '".$resourceName."'
59                             OR primary_resource_id in (SELECT primary_resource_id
60                                      FROM ".TABLE_PREFIX."primary_resources
61                                     WHERE resource='".$resourceName."')";
62                 return $this->execute($sql);
63         }
64         
65         /**
66         * Return distinct rows by content_id
67         * @access  public
68         * @param   content_id
69         * @return  table rows
70         * @author  Cindy Qi Li
71         */
72         public function getByContent($content_id)
73         {
74                 $sql = "SELECT DISTINCT secondary_resource_id, secondary_resource FROM ".TABLE_PREFIX."primary_resources a 
75                           LEFT JOIN ".TABLE_PREFIX."secondary_resources s
76                                         ON a.primary_resource_id = s.primary_resource_id 
77                                  WHERE content_id=".$content_id;
78                 return $this->execute($sql);
79         }
80         /**
81         * Return rows by primary resource id
82         * @access  public
83         * @param   name
84         * @return  table rows
85         * @author  Cindy Qi Li
86         */
87         public function getByPrimaryResourceID($primary_resource_id)
88         {
89             $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources WHERE primary_resource_id='.$primary_resource_id;
90             return $this->execute($sql);
91         }
92 }
93 ?>