/** * Insert or update product videos * 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_videos($videos = array()) { if (empty($videos) || !is_array($videos)) { return false; } foreach ($videos as $key => $video) { $data = $video['data']; if (is_numeric($video['id']) && $video['id'] > 0) { // Update existing video $item = Model_Product_Video::find_one_by_id($video['id']); $item->set($data); } else { $item = Model_Product_Video::forge($data); } $item->save(); } }
/** * Insert or update product videos * 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_videos($videos = array()) { if (empty($videos) || !is_array($videos)) { return false; } foreach ($videos as $key => $video) { $item = Model_Product_Video::forge($video['data']); if (is_numeric($video['id']) && $video['id'] > 0) { // Update existing videos $item->set(array('id' => $video['id'])); $item->is_new(false); } $item->save(); } }