http://atutor.ca/atutor/mantis/view.php?id=4553
authorharris wong <hwong@ocad.ca>
Thu, 30 Sep 2010 22:28:07 +0000 (22:28 -0000)
committerharris wong <hwong@ocad.ca>
Thu, 30 Sep 2010 22:28:07 +0000 (22:28 -0000)
docs/mods/_core/editor/editor_tabs/alternatives.inc.php
docs/mods/_core/imsafa/classes/A4a.class.php

index 8311ea2..684f92e 100644 (file)
@@ -139,6 +139,21 @@ else
        echo '  </thead>'."\n";
        
        echo '  <tbody>';
+
+    /* http://atutor.ca/atutor/mantis/view.php?id=4553
+     * remove old primary resources that's no longer used. 
+     * @harris 9/30/2010
+     */
+    include_once(AT_INCLUDE_PATH.'../mods/_core/imsafa/classes/A4a.class.php');
+    $a4a = new A4a($cid);
+    $db_primary_resources = $a4a->getPrimaryResources();
+    foreach ($db_primary_resources  as $primary_rid=>$db_resource){
+        //if this file from our table is not found in the $resource, then it's not used.
+        if(in_array($db_resource['resource'], $resources)===false){
+            $a4a->deletePrimaryResource($primary_rid);
+        }
+    }
+
        foreach($resources as $primary_resource)
        {
                // check whether the primary resource is in the table
@@ -147,7 +162,7 @@ else
                           AND language_code = '".$_SESSION['lang']."'
                           AND resource='".$primary_resource."'";
                $primary_result = mysql_query($sql, $db);
-               
+
                // insert primary resource if it's not in db
                if (mysql_num_rows($primary_result) == 0)
                {
index 73b995c..7b4e55f 100644 (file)
@@ -209,6 +209,23 @@ class A4a {
        }
 
 
+    /**
+     * Delete this primary resource and all its associated secondary resources
+     * @param   int     primary resournce id
+     */
+    function deletePrimaryResource($primary_rid){
+        global $db;
+        // Delete all secondary a4a
+        $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=$primary_rid";
+        $result = mysql_query($sql, $db);
+        
+        // If successful, remove all primary resources
+        if ($result){
+            $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=$primary_rid";
+            mysql_query($sql, $db);
+        }
+    }
+
        // Delete all materials associated with this content
        function deleteA4a(){
                global $db;