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 "secondary_resources" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class SecondaryResourcesDAO extends DAO {
29 * @param primary_resource_id, file_name, language_code
33 public function Create($primary_resource_id, $file_name, $lang)
37 $primary_resource_id = intval($primary_resource_id);
38 $file_name = $addslashes(convertAmp($file_name));
39 $lang = $addslashes($lang);
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);
49 * Delete rows that primary or secondary resource name is the given $resourceName
51 * @param $resourceName: primary or secondary resource name
52 * @return true or false
55 function DeleteByResourceName($resourceName)
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);
66 * Return distinct rows by content_id
72 public function getByContent($content_id)
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);
81 * Return rows by primary resource id
87 public function getByPrimaryResourceID($primary_resource_id)
89 $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources WHERE primary_resource_id='.$primary_resource_id;
90 return $this->execute($sql);