Exemplo n.º 1
0
 /**
  * Insert or update product files
  * Certain array structure need to be passed
  * 
  * array(
  * 	0 => array(
  * 		'id' 	=> If numeric and larger than 0, file will be updated. Otherwise file is considered new
  * 		'data'	=> Array of file data to insert
  * 	),
  * 	1 => array(
  * 		'id' 	=> If numeric and larger than 0, file will be updated. Otherwise file is considered new
  * 		'data'	=> Array of file data to insert
  * 	),
  * 	etc.
  * )
  * 
  * @param $files
  */
 public static function bind_files($files = array())
 {
     if (empty($files) || !is_array($files)) {
         return false;
     }
     foreach ($files as $key => $file) {
         $item = Model_Product_File::forge($file['data']);
         if (is_numeric($file['id']) && $file['id'] > 0) {
             // Update existing file
             $item->set(array('id' => $file['id']));
             $item->is_new(false);
         }
         $item->save();
     }
 }