Are you a regular stikked user? Signup so you can keep track of your pastes!
  1. <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Cross_ref_write {
  4.  
  5.         // var $tag_scope = FALSE; // tag or parent or category or shortcut
  6.        
  7.        
  8.        
  9.         // we have two tables to deal with, so this will probably be a problem...
  10.        
  11.         var $id                         = '';
  12.         var $biblio_id          = '';
  13.         var $profile_id         = '';
  14.         var $tag_id                     = '';
  15.         var $page_id            = '';
  16.         var $course_id          = '';
  17.         var $coll_id            = '';
  18.        
  19.        
  20.        
  21.         function delete($primary = NULL, $primary_id = NULL, $related_scope = NULL)
  22.         {
  23.                 $this->db->where("{$primary_scope}_id", $primary_id);
  24.                 $this->db->where("{$related_scope}_id NOT ", 0);
  25.                 $this->db->delete('cross_ref');
  26.         }
  27.        
  28.         function delete_all()
  29.         {
  30.                
  31.         }
  32.  
  33.         function add_one($primary_scope = NULL, $primary_id = NULL, $related_scope = NULL, $related_id = NULL)
  34.         {
  35.                
  36.         }
  37.  
  38.         function save($primary_scope = NULL, $primary_id = NULL, $related_scope = NULL, $related_ids = NULL)
  39.         {
  40.                 if(is_null($primary_scope) OR is_null($primary_id) OR is_null($related_scope) OR is_null($related_ids))
  41.                 {
  42.                         return FALSE;
  43.                 }
  44.                 else
  45.                 {
  46.                         // proceed
  47.                         $CI =& get_instance();
  48.                         try
  49.                         {
  50.                                 // DELETE from CROSS_REF where {primary_scope}_id =
  51.                                 // housekeeping is easier if we wipe the slate clean, rather than update existing.
  52.                                 // then we add/re-add them in fresh below
  53.                                 $CI->db->where("{$primary_scope}_id", $primary_id);
  54.                                 $CI->db->where("{$related_scope}_id NOT ", 0);
  55.                                 $CI->db->delete('cross_ref');
  56.  
  57.                                 // ADD to CROSS_REF
  58.                                 // loop through related id's INSERT one at a time
  59.                                 foreach($related_ids as $related_id)
  60.                                 {
  61.                                         if($related_id != '')
  62.                                         {
  63.                                                 $cross = array(
  64.                                                                 "{$primary_scope}_id" => $primary_id,
  65.                                                                 "{$related_scope}_id" => $related_id
  66.                                                         );
  67.                                         }
  68.                                         $CI->db->insert('cross_ref', $cross);
  69.                                 }
  70.                                 return TRUE;
  71.                         }
  72.                         catch ()
  73.                         {
  74.                                 return FALSE;
  75.                         }
  76.                 }
  77.         }
  78. } // EOF

Reply to "Cross_ref_write.php"

Here you can reply to the paste above

Create a snipurl

Make Private

Feeling clever? Set some advanced options.