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 "primary_resources" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class PrimaryResourcesDAO extends DAO {
29 * @param content_id, file_name, language_code
33 public function Create($content_id, $file_name, $lang)
37 $content_id = intval($content_id);
38 $file_name = $addslashes(convertAmp($file_name));
39 $lang = $addslashes($lang);
41 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources
42 SET content_id=$content_id,
43 resource='$file_name',
44 language_code='$lang'";
46 return $this->execute($sql);
50 * Delete rows by content_id
53 * @return true or false
56 public function Delete($cid)
58 $pri_resource_ids = array();
60 // Get all primary resources ID out that're associated with this content
61 $rows = $this->getByContent($cid);
64 foreach ($rows as $row) $pri_resource_ids[] = $row['primary_resource_id'];
67 if (!empty($pri_resource_ids)){
68 $glued_pri_ids = implode(",", $pri_resource_ids);
70 // Delete all secondary a4a
71 $sql = 'DELETE c, d FROM '.TABLE_PREFIX.'secondary_resources c
72 LEFT JOIN '.TABLE_PREFIX.'secondary_resources_types d
73 ON c.secondary_resource_id=d.secondary_resource_id
74 WHERE primary_resource_id IN ('.$glued_pri_ids.')';
76 // If successful, remove all primary resources
77 if ($this->execute($sql)){
78 $sql = 'DELETE a, b FROM '.TABLE_PREFIX.'primary_resources a
79 LEFT JOIN '.TABLE_PREFIX.'primary_resources_types b
80 ON a.primary_resource_id=b.primary_resource_id
81 WHERE content_id='.$cid;
82 return $this->execute($sql);
89 * Delete rows that primary resource name is the given $resourceName
91 * @param $resourceName: primary resource name
92 * @return true or false
95 function DeleteByResourceName($resourceName)
97 $sql = "DELETE FROM ".TABLE_PREFIX."primary_resources
98 WHERE resource = '".$resourceName."'";
99 return $this->execute($sql);
103 * Delete rows by using resource id
105 * @param $resourceID: primary resource ID
106 * @return true or false
107 * @author Harris Wong
110 function DeleteByResourceID($resourceID){
111 // Delete all secondary a4a
112 $sql = 'DELETE c, d FROM '.TABLE_PREFIX.'secondary_resources c LEFT JOIN '.TABLE_PREFIX."secondary_resources_types d ON c.secondary_resource_id=d.secondary_resource_id WHERE primary_resource_id=$resourceID";
113 $result = $this->execute($sql);
115 // If successful, remove all primary resources
117 $sql = 'DELETE a, b FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX."primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE a.primary_resource_id=$resourceID";
118 return $this->execute($sql);
123 * Return rows by content_id
125 * @param cid: content_id
127 * @author Cindy Qi Li
129 public function getByContent($cid)
131 $sql = 'SELECT * FROM '.TABLE_PREFIX.'primary_resources WHERE content_id='.$cid.' ORDER BY primary_resource_id';;
132 return $this->execute($sql);
136 * Return rows by primary resource name
138 * @param $cid: the content id
139 * @param $lang: the language code.
140 * @param $resourceName: primary resource name
142 * @author Harris Wong
145 public function getByResourceName($cid, $lang, $resource_name){
146 $sql = "SELECT * FROM ".TABLE_PREFIX."primary_resources
147 WHERE content_id=".$cid."
148 AND language_code = '".$lang."'
149 AND resource='".$resource_name."'";
150 return $this->execute($sql);